Skip to content

Commit

Permalink
Add option for adding annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
I065450 committed Dec 23, 2024
1 parent e21fda0 commit 87076a5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 77 deletions.
1 change: 0 additions & 1 deletion api/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type ControllerName string
const (
ServiceInstanceController ControllerName = "ServiceInstance"
ServiceBindingController ControllerName = "ServiceBinding"
SecretController ControllerName = "Secret"
FinalizerName string = "services.cloud.sap.com/sap-btp-finalizer"
StaleBindingIDLabel string = "services.cloud.sap.com/stale"
StaleBindingRotationOfLabel string = "services.cloud.sap.com/rotationOf"
Expand Down
4 changes: 2 additions & 2 deletions api/v1/serviceinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type ServiceInstanceSpec struct {

// indicate instance will update on secrets from parametersFrom change
// +optional
WatchParameterFromChanges *bool `json:"watchParameterFromChanges,omitempty"`
WatchParametersFromChanges *bool `json:"watchParametersFromChanges,omitempty"`

// List of custom tags describing the ServiceInstance, will be copied to `ServiceBinding` secret in the key called `tags`.
// +optional
Expand Down Expand Up @@ -213,7 +213,7 @@ func (si *ServiceInstance) GetShared() bool {
}

func (si *ServiceInstance) IsSubscribedToParamSecretsChanges() bool {
return si.Spec.WatchParameterFromChanges != nil && *si.Spec.WatchParameterFromChanges
return si.Spec.WatchParametersFromChanges != nil && *si.Spec.WatchParametersFromChanges
}

func (si *ServiceInstance) GetSpecHash() string {
Expand Down
4 changes: 2 additions & 2 deletions api/v1/serviceinstance_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ var _ = Describe("Service Instance Type Test", func() {
Expect(instance.GetAnnotations()).To(Equal(annotation))
})

It("should update WatchParameterFromChanges", func() {
instance.Spec.WatchParameterFromChanges = &[]bool{true}[0]
It("should update WatchParametersFromChanges", func() {
instance.Spec.WatchParametersFromChanges = &[]bool{true}[0]
Expect(instance.IsSubscribedToParamSecretsChanges()).To(BeTrue())
})

Expand Down
2 changes: 1 addition & 1 deletion api/v1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func getInstance() *ServiceInstance {
},
},
},
WatchParameterFromChanges: &[]bool{true}[0],
WatchParametersFromChanges: &[]bool{true}[0],
UserInfo: &v1.UserInfo{
Username: "test-user",
Groups: []string{"test-group"},
Expand Down
4 changes: 2 additions & 2 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ spec:
shared:
description: Indicates the desired shared state
type: boolean
watchParameterFromChanges:
watchParametersFromChanges:
description: indicate instance will update on secrets from parametersFrom
change
type: boolean
Expand Down
14 changes: 7 additions & 7 deletions controllers/serviceinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,10 @@ var _ = Describe("ServiceInstance controller", func() {
var anotherInstance *v1.ServiceInstance
var anotherSecret *corev1.Secret
BeforeEach(func() {
instanceSpec.WatchParameterFromChanges = pointer.Bool(true)
instanceSpec.WatchParametersFromChanges = pointer.Bool(true)
})
AfterEach(func() {
instanceSpec.WatchParameterFromChanges = pointer.Bool(false)
instanceSpec.WatchParametersFromChanges = pointer.Bool(false)
if anotherInstance != nil {
deleteAndWait(ctx, anotherInstance)
}
Expand Down Expand Up @@ -1353,7 +1353,7 @@ var _ = Describe("ServiceInstance controller", func() {
},
},
},
WatchParameterFromChanges: pointer.Bool(true),
WatchParametersFromChanges: pointer.Bool(true),
}
serviceInstance = createInstance(ctx, anotherInstanceName, newInstanceSpec, nil, false)
waitForResourceCondition(ctx, serviceInstance, common.ConditionSucceeded, metav1.ConditionFalse, common.CreateInProgress, "secrets \"instance-params-secret-new\" not found")
Expand Down Expand Up @@ -1477,7 +1477,7 @@ var _ = Describe("ServiceInstance controller", func() {
})
When("secret updated and instance don't watch secret", func() {
AfterEach(func() {
instanceSpec.WatchParameterFromChanges = pointer.Bool(false)
instanceSpec.WatchParametersFromChanges = pointer.Bool(false)
})
It("should not update instance with the secret change", func() {
serviceInstance = createInstance(ctx, fakeInstanceName, instanceSpec, nil, true)
Expand All @@ -1492,14 +1492,14 @@ var _ = Describe("ServiceInstance controller", func() {
Expect(k8sClient.Update(ctx, paramsSecret)).To(Succeed())
Expect(fakeClient.UpdateInstanceCallCount()).To(Equal(0))
})
It("should not update instance with the secret change after removing WatchParameterFromChanges", func() {
instanceSpec.WatchParameterFromChanges = pointer.Bool(true)
It("should not update instance with the secret change after removing WatchParametersFromChanges", func() {
instanceSpec.WatchParametersFromChanges = pointer.Bool(true)
serviceInstance = createInstance(ctx, fakeInstanceName, instanceSpec, nil, true)
smInstance, _, _, _, _, _ := fakeClient.ProvisionArgsForCall(0)
checkParams(string(smInstance.Parameters), []string{"\"key\":\"value\"", "\"secret-key\":\"secret-value\""})
checkSecretAnnotationsAndLabels(ctx, k8sClient, paramsSecret, []*v1.ServiceInstance{serviceInstance})

serviceInstance.Spec.WatchParameterFromChanges = pointer.Bool(false)
serviceInstance.Spec.WatchParametersFromChanges = pointer.Bool(false)
updateInstance(ctx, serviceInstance)
waitForResourceCondition(ctx, serviceInstance, common.ConditionSucceeded, metav1.ConditionTrue, common.Updated, "")
checkSecretAnnotationsAndLabels(ctx, k8sClient, paramsSecret, []*v1.ServiceInstance{})
Expand Down
40 changes: 21 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/SAP/sap-btp-service-operator

go 1.22.7
go 1.23.0

toolchain go1.23.4

require (
github.com/Masterminds/sprig/v3 v3.2.3
Expand All @@ -9,13 +11,13 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/lithammer/dedent v1.1.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.33.1
github.com/onsi/gomega v1.35.1
github.com/pkg/errors v0.9.1
golang.org/x/oauth2 v0.20.0
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/client-go v0.30.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
golang.org/x/oauth2 v0.23.0
k8s.io/api v0.32.0
k8s.io/apimachinery v0.32.0
k8s.io/client-go v0.32.0
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
sigs.k8s.io/controller-runtime v0.18.3
sigs.k8s.io/yaml v1.4.0
)
Expand All @@ -25,17 +27,17 @@ require (
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -56,10 +58,10 @@ require (
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
Expand All @@ -68,16 +70,16 @@ require (
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/time v0.7.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.30.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
)
Loading

0 comments on commit 87076a5

Please sign in to comment.