Skip to content

Commit

Permalink
[SAPBTPCFS-15469] Update Service Instance on change of 'parametersFro…
Browse files Browse the repository at this point in the history
…m' secret
  • Loading branch information
I065450 committed Dec 8, 2024
1 parent 62240de commit b1e853c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/v1/serviceinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ func (si *ServiceInstance) ShouldBeShared() bool {
return si.Spec.Shared != nil && *si.Spec.Shared
}

func (si *ServiceInstance) IsSubscribedToSecretKeyRefChange() bool {
func (si *ServiceInstance) IsSubscribedToSecretChange() bool {
return si.Spec.SubscribeToSecretChanges != nil && *si.Spec.SubscribeToSecretChanges
}
5 changes: 5 additions & 0 deletions api/v1/serviceinstance_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ var _ = Describe("Service Instance Type Test", func() {
instance.SetAnnotations(annotation)
Expect(instance.GetAnnotations()).To(Equal(annotation))
})

It("should update SubscribeToSecretChanges", func() {
instance.Spec.SubscribeToSecretChanges = &[]bool{true}[0]
Expect(instance.IsSubscribedToSecretChange()).To(BeTrue())
})
})
2 changes: 1 addition & 1 deletion controllers/serviceinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func (r *ServiceInstanceReconciler) buildSMRequestParameters(ctx context.Context
return nil, err
}
shouldUpdate := false
if serviceInstance.IsSubscribedToSecretKeyRefChange() {
if serviceInstance.IsSubscribedToSecretChange() {
existingSecrets := make(map[string]string)
if serviceInstance.Labels == nil {
serviceInstance.Labels = make(map[string]string)
Expand Down
24 changes: 23 additions & 1 deletion controllers/serviceinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,10 @@ var _ = Describe("ServiceInstance controller", func() {
})
})
When("secret updated and instance don't watch secret", func() {
It("should update instance with the secret change", func() {
AfterEach(func() {
instanceSpec.SubscribeToSecretChanges = pointer.Bool(false)
})
It("should not update instance with the secret change", func() {
serviceInstance = createInstance(ctx, fakeInstanceName, instanceSpec, nil, true)
smInstance, _, _, _, _, _ := fakeClient.ProvisionArgsForCall(0)
checkParams(string(smInstance.Parameters), []string{"\"key\":\"value\"", "\"secret-key\":\"secret-value\""})
Expand All @@ -1411,6 +1414,25 @@ 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 SubscribeToSecretChanges", func() {
instanceSpec.SubscribeToSecretChanges = 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.SubscribeToSecretChanges = pointer.Bool(false)
updateInstance(ctx, serviceInstance)
waitForResourceCondition(ctx, serviceInstance, common.ConditionSucceeded, metav1.ConditionTrue, common.Updated, "")
checkSecretAnnotationsAndLabels(ctx, k8sClient, paramsSecret, []*v1.ServiceInstance{})

credentialsMap := make(map[string][]byte)
credentialsMap["secret-parameter"] = []byte("{\"secret-key\":\"new-secret-value\"}")
paramsSecret.Data = credentialsMap
Expect(k8sClient.Update(ctx, paramsSecret)).To(Succeed())
Expect(fakeClient.UpdateInstanceCallCount()).To(Equal(1))
})
})

})
Expand Down

0 comments on commit b1e853c

Please sign in to comment.