Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip region check for CCS ProjectClaims #121

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified coverage_badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ require (
github.com/coreos/prometheus-operator v0.26.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/emicklei/go-restful v2.11.2+incompatible // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.0 // indirect
github.com/go-openapi/spec v0.19.2
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
github.com/golang/mock v1.4.4
github.com/google/uuid v1.0.0
Expand All @@ -20,6 +23,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.8.5 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/jpoles1/gopherbadger v2.4.0+incompatible // indirect
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/openshift/cluster-api v0.0.0-20191129101638-b09907ac6668
Expand Down
17 changes: 15 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ github.com/emicklei/go-restful v2.11.2+incompatible/go.mod h1:otzb+WCGbkyDHkqmQm
github.com/evanphx/json-patch v4.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
Expand Down Expand Up @@ -91,6 +95,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -154,6 +160,9 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jpoles1/gopherbadger v1.0.0 h1:1hWuWkWUhFPGxVRHiFEi/+WLteggAHG2dF1lgd2t6bc=
github.com/jpoles1/gopherbadger v2.4.0+incompatible h1:UHNcdQnmeUo8kAIAZfz55Dkev3zM/Jj2SMgeEwkMO8A=
github.com/jpoles1/gopherbadger v2.4.0+incompatible/go.mod h1:DVwxsf5adYLiDOj955t/ejfCRWjKA5tme6Vejb72Ro0=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -175,6 +184,10 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63 h1:nTT4s92Dgz2HlrB
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/markbates/inflect v1.0.4 h1:5fh1gzTFhfae06u3hzHYO9xe3l3v3nW5Pwt3naLTP5g=
github.com/markbates/inflect v1.0.4/go.mod h1:1fR9+pO2KHEO9ZRtto13gDwwZaAKstQzferVeWqbgNs=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -354,8 +367,10 @@ golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -389,8 +404,6 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191010171213-8abd42400456/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201002055958-0d28ed0cbe40 h1:ErPN1Z9An7dXc56pRUCKgWJkjYzc3hE+y15ky9E8qxU=
golang.org/x/tools v0.0.0-20201002055958-0d28ed0cbe40/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.0.0-20201008025239-9df69603baec h1:RY2OghEV/7X1MLaecgm1mwFd3sGvUddm5pGVSxQvX0c=
golang.org/x/tools v0.0.0-20201008025239-9df69603baec/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/gcp/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
ConditionVerification ConditionType = "Verification"
// ConditionError is set when a project custom resource state changes to Error
ConditionError ConditionType = "Error"
// ConditionInvalid is set when a project custom resource has an invalid or unsupported configuration
ConditionInvalid ConditionType = "Invalid"
// ConditionComputeApiReady is set when the compute API is not yet ready
ConditionComputeApiReady ConditionType = "ComputeApiReady"
)
11 changes: 11 additions & 0 deletions pkg/condition/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Conditions interface {
SetCondition(conditions *[]gcpv1alpha1.Condition, conditionType gcpv1alpha1.ConditionType, status corev1.ConditionStatus, reason string, message string)
FindCondition(conditions *[]gcpv1alpha1.Condition, conditionType gcpv1alpha1.ConditionType) (*gcpv1alpha1.Condition, bool)
HasCondition(conditions *[]gcpv1alpha1.Condition, conditionType gcpv1alpha1.ConditionType) bool
}

type ConditionManager struct {
Expand Down Expand Up @@ -60,3 +61,13 @@ func (c *ConditionManager) FindCondition(conditions *[]gcpv1alpha1.Condition, co

return &(*conditions)[len(*conditions)-1], false
}

// HasCondition checks for the existance of a given Condition type
func (c *ConditionManager) HasCondition(conditions *[]gcpv1alpha1.Condition, conditionType gcpv1alpha1.ConditionType) bool {
for _, condition := range *conditions {
if condition.Type == conditionType {
return true
}
}
return false
}
4 changes: 2 additions & 2 deletions pkg/controller/projectclaim/projectclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type CustomResourceAdapter interface {
EnsureFinalizer() (gcputil.OperationResult, error)
EnsureCCSSecretFinalizer() (gcputil.OperationResult, error)
FinalizeProjectClaim() (ObjectState, error)
SetProjectClaimCondition(reason string, err error) error
SetProjectClaimCondition(gcpv1alpha1.ConditionType, string, error) (gcputil.OperationResult, error)
}

// Add creates a new ProjectClaim Controller and adds it to the Manager. The Manager will set fields on the Controller
Expand Down Expand Up @@ -100,7 +100,7 @@ func (r *ReconcileProjectClaim) Reconcile(request reconcile.Request) (reconcile.
adapter := NewProjectClaimAdapter(instance, reqLogger, r.client, conditionManager)
result, err := r.ReconcileHandler(adapter)
reason := "ReconcileError"
_ = adapter.SetProjectClaimCondition(reason, err)
_, _ = adapter.SetProjectClaimCondition(gcpv1alpha1.ConditionError, reason, err)

return result, err
}
Expand Down
46 changes: 25 additions & 21 deletions pkg/controller/projectclaim/projectclaimadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (

const ProjectClaimFinalizer string = "finalizer.gcp.managed.openshift.io"
const CCSSecretFinalizer string = "finalizer.gcp.managed.openshift.io/ccs"
const RegionCheckFailed string = "RegionCheckFailed"

// Regions supported in the gcp-project-operator
var supportedRegions = map[string]bool{
Expand Down Expand Up @@ -203,7 +204,7 @@ func (c *ProjectClaimAdapter) EnsureProjectClaimInitialized() (gcputil.Operation
c.projectClaim.Status.Conditions = []gcpv1alpha1.Condition{}
err := c.client.Status().Update(context.TODO(), c.projectClaim)
if err != nil {
gcputil.RequeueWithError(operrors.Wrap(err, "failed to initalize projectclaim"))
return gcputil.RequeueWithError(operrors.Wrap(err, "failed to initalize projectclaim"))
}
return gcputil.StopProcessing()
}
Expand Down Expand Up @@ -312,35 +313,36 @@ func (c *ProjectClaimAdapter) EnsureProjectClaimState(state gcpv1alpha1.ClaimSta
}

c.projectClaim.Status.State = state
err := c.StatusUpdate()
if err != nil {
return gcputil.RequeueWithError(err)
}

return gcputil.StopProcessing()
return gcputil.RequeueOnErrorOrStop(c.StatusUpdate())
}

// SetProjectClaimCondition calls SetCondition() with project claim conditions
func (c *ProjectClaimAdapter) SetProjectClaimCondition(reason string, err error) error {
func (c *ProjectClaimAdapter) SetProjectClaimCondition(conditionType gcpv1alpha1.ConditionType, reason string, err error) (gcputil.OperationResult, error) {
conditions := &c.projectClaim.Status.Conditions
conditionType := gcpv1alpha1.ConditionError
if err != nil {
c.conditionManager.SetCondition(conditions, conditionType, corev1.ConditionTrue, reason, err.Error())
} else {
if len(*conditions) != 0 {
reason = reason + "Resolved"
c.conditionManager.SetCondition(conditions, conditionType, corev1.ConditionFalse, reason, "")
} else {
return nil
}
return gcputil.RequeueOnErrorOrStop(c.StatusUpdate())
}

return c.StatusUpdate()
if !c.conditionManager.HasCondition(conditions, conditionType) {
return gcputil.ContinueProcessing()
}
reason = reason + "Resolved"
if condition, _ := c.conditionManager.FindCondition(conditions, conditionType); condition.Reason == reason {
return gcputil.ContinueProcessing()
}

c.conditionManager.SetCondition(conditions, conditionType, corev1.ConditionFalse, reason, "")
return gcputil.RequeueOnErrorOrStop(c.StatusUpdate())

}

// IsRegionSupported checks if current region is supported.
// It returns an error message if a region is not supported.
func (c *ProjectClaimAdapter) IsRegionSupported() error {
if c.projectClaim.Spec.CCS {
return nil
}
if _, ok := supportedRegions[c.projectClaim.Spec.Region]; !ok {
return operrors.ErrRegionNotSupported
}
Expand All @@ -350,12 +352,14 @@ func (c *ProjectClaimAdapter) IsRegionSupported() error {
// EnsureRegionSupported modifies projectClaim.Status.State with result from IsRegionSupported.
// If a region is not supported it returns an error and sets projectClaim.Status.State to ClaimStatusError.
func (c *ProjectClaimAdapter) EnsureRegionSupported() (gcputil.OperationResult, error) {
if err := c.IsRegionSupported(); err != nil {
err := c.IsRegionSupported()
if err != nil {
c.projectClaim.Status.State = gcpv1alpha1.ClaimStatusError
c.StatusUpdate()
return gcputil.RequeueWithError(operrors.Wrap(err, ""))
}
return gcputil.ContinueProcessing()
if err == nil && c.projectClaim.Status.State == gcpv1alpha1.ClaimStatusError {
c.projectClaim.Status.State = gcpv1alpha1.ClaimStatusPending
}
return c.SetProjectClaimCondition(gcpv1alpha1.ConditionInvalid, RegionCheckFailed, err)
}

// StatusUpdate updates the project claim status
Expand Down
68 changes: 48 additions & 20 deletions pkg/controller/projectclaim/projectclaimadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
gcpv1alpha1 "github.com/openshift/gcp-project-operator/pkg/apis/gcp/v1alpha1"
"github.com/openshift/gcp-project-operator/pkg/controller/projectclaim"
. "github.com/openshift/gcp-project-operator/pkg/controller/projectclaim"
"github.com/openshift/gcp-project-operator/pkg/util"
"github.com/openshift/gcp-project-operator/pkg/util/mocks"
mockconditions "github.com/openshift/gcp-project-operator/pkg/util/mocks/condition"
testStructs "github.com/openshift/gcp-project-operator/pkg/util/mocks/structs"
Expand Down Expand Up @@ -92,26 +93,42 @@ var _ = Describe("Customresourceadapter", func() {
Context("When the EnsureRegionSupported() is called", func() {
Context("if the projectclaim has a supported region", func() {
BeforeEach(func() {
mockConditions.EXPECT().HasCondition(gomock.Any(), gcpv1alpha1.ConditionInvalid).Return(false)
projectClaim.Spec.Region = "us-east1"
})
It("should return nil", func() {
_, err := adapter.EnsureRegionSupported()
Expect(err).To(BeNil())
res, err := adapter.EnsureRegionSupported()
Expect(res).To(Equal(util.ContinueOperationResult()))
Expect(err).NotTo(HaveOccurred())
})
})
Context("if the projectclaim has an unsupported region", func() {
BeforeEach(func() {
matcher := testStructs.NewProjectClaimMatcher()
mockClient.EXPECT().Status().Return(mockStatusWriter)
mockStatusWriter.EXPECT().Update(gomock.Any(), matcher)
projectClaim.Spec.Region = "fake-region"
})
It("should return err", func() {
_, err := adapter.EnsureRegionSupported()
Expect(err.Error()).Should(ContainSubstring("gcp-project-operator/pkg/controller/projectclaim/projectclaimadapter.go"))
Expect(err.Error()).Should(ContainSubstring("Line:"))
Expect(err.Error()).Should(ContainSubstring("gcp-project-operator/pkg/controller/projectclaim.(*ProjectClaimAdapter).EnsureRegionSupported"))
Expect(err.Error()).Should(ContainSubstring("RegionNotSupported"))
Context("when it is not a CCS cluster", func() {
BeforeEach(func() {
mockConditions.EXPECT().SetCondition(gomock.Any(), gcpv1alpha1.ConditionInvalid, corev1.ConditionTrue, RegionCheckFailed, gomock.Any())
matcher := testStructs.NewProjectClaimMatcher()
mockClient.EXPECT().Status().Return(mockStatusWriter)
mockStatusWriter.EXPECT().Update(gomock.Any(), matcher)
})
It("should return err", func() {
res, err := adapter.EnsureRegionSupported()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(util.StopOperationResult()))
})
})
Context("when it is a CCS cluster", func() {
BeforeEach(func() {
mockConditions.EXPECT().HasCondition(gomock.Any(), gcpv1alpha1.ConditionInvalid).Return(false)
projectClaim.Spec.CCS = true
})
It("should return nil", func() {
res, err := adapter.EnsureRegionSupported()
Expect(res).To(Equal(util.ContinueOperationResult()))
Expect(err).NotTo(HaveOccurred())
})
})
})
})
Expand Down Expand Up @@ -368,7 +385,7 @@ var _ = Describe("Customresourceadapter", func() {
currentState = gcpv1alpha1.ClaimStatusReady
})
It("doesn't change the ProjectClaim state", func() {
adapter.EnsureProjectClaimState(requestedState)
_, _ = adapter.EnsureProjectClaimState(requestedState)
Expect(projectClaim.Status.State).To(Equal(currentState))
})
})
Expand All @@ -379,7 +396,7 @@ var _ = Describe("Customresourceadapter", func() {
})
It("updates the state to Pending", func() {
mockClient.EXPECT().Status().Times(1).Return(stubStatus{})
adapter.EnsureProjectClaimState(requestedState)
_, _ = adapter.EnsureProjectClaimState(requestedState)
Expect(projectClaim.Status.State).To(Equal(requestedState))
})
})
Expand All @@ -395,7 +412,7 @@ var _ = Describe("Customresourceadapter", func() {
currentState = gcpv1alpha1.ClaimStatusReady
})
It("doesn't change the ProjectClaim state", func() {
adapter.EnsureProjectClaimState(requestedState)
_, _ = adapter.EnsureProjectClaimState(requestedState)
Expect(projectClaim.Status.State).To(Equal(currentState))
})
})
Expand All @@ -406,7 +423,7 @@ var _ = Describe("Customresourceadapter", func() {
})
It("updates the state to PendingProject", func() {
mockClient.EXPECT().Status().Times(1).Return(stubStatus{})
adapter.EnsureProjectClaimState(requestedState)
_, _ = adapter.EnsureProjectClaimState(requestedState)
Expect(projectClaim.Status.State).To(Equal(requestedState))
})
})
Expand All @@ -419,29 +436,40 @@ var _ = Describe("Customresourceadapter", func() {
conditionType = gcpv1alpha1.ConditionError
)
Context("when no conditions defined before and the err is nil", func() {
BeforeEach(func() {
mockConditions.EXPECT().HasCondition(gomock.Any(), conditionType).Return(false)
})
It("It returns nil ", func() {
errTemp := adapter.SetProjectClaimCondition(reason, nil)
_, errTemp := adapter.SetProjectClaimCondition(conditionType, reason, nil)
Expect(errTemp).To(BeNil())
})
})
Context("when the err comes from reconcileHandler", func() {
It("should update the CRD", func() {
It("should update the CR", func() {
matcher := testStructs.NewProjectClaimMatcher()
mockClient.EXPECT().Status().Return(mockStatusWriter)
mockStatusWriter.EXPECT().Update(gomock.Any(), matcher)
mockConditions.EXPECT().SetCondition(gomock.Any(), conditionType, corev1.ConditionTrue, reason, err.Error()).Times(1)
adapter.SetProjectClaimCondition(reason, err)
res, err := adapter.SetProjectClaimCondition(conditionType, reason, err)
Expect(res).To(Equal(util.StopOperationResult()))
Expect(err).NotTo(HaveOccurred())
})
})
Context("when the err has been resolved", func() {
It("It should update the CRD condition status as resolved", func() {
BeforeEach(func() {
mockConditions.EXPECT().HasCondition(gomock.Any(), conditionType).Return(true)
mockConditions.EXPECT().FindCondition(gomock.Any(), conditionType).Return(&gcpv1alpha1.Condition{}, true)
})
It("It should update the CR condition status as resolved", func() {
matcher := testStructs.NewProjectClaimMatcher()
conditions := &projectClaim.Status.Conditions
*conditions = append(*conditions, gcpv1alpha1.Condition{})
mockClient.EXPECT().Status().Return(mockStatusWriter)
mockStatusWriter.EXPECT().Update(gomock.Any(), matcher)
mockConditions.EXPECT().SetCondition(conditions, conditionType, corev1.ConditionFalse, "ReconcileErrorResolved", "").Times(1)
adapter.SetProjectClaimCondition(reason, nil)
res, err := adapter.SetProjectClaimCondition(conditionType, reason, nil)
Expect(res).To(Equal(util.StopOperationResult()))
Expect(err).NotTo(HaveOccurred())
})
})
})
Expand Down
Loading