Skip to content

Commit abcd0b9

Browse files
authored
restore status.ObservedGeneration (#546)
1 parent 524aa69 commit abcd0b9

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

api/common/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type SAPBTPResource interface {
8282
GetReady() metav1.ConditionStatus
8383
GetAnnotations() map[string]string
8484
SetAnnotations(map[string]string)
85+
SetObservedGeneration(int64)
8586
}
8687

8788
func GetObservedGeneration(obj SAPBTPResource) int64 {

api/v1/servicebinding_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ type ServiceBindingStatus struct {
131131

132132
// The subaccount id of the service binding
133133
SubaccountID string `json:"subaccountID,omitempty"`
134+
135+
// Last generation that was acted on
136+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
134137
}
135138

136139
// +kubebuilder:object:root=true
@@ -196,6 +199,10 @@ func (sb *ServiceBinding) SetAnnotations(annotations map[string]string) {
196199
sb.ObjectMeta.Annotations = annotations
197200
}
198201

202+
func (sb *ServiceBinding) SetObservedGeneration(newObserved int64) {
203+
sb.Status.ObservedGeneration = newObserved
204+
}
205+
199206
// +kubebuilder:object:root=true
200207

201208
// ServiceBindingList contains a list of ServiceBinding

api/v1/serviceinstance_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ type ServiceInstanceStatus struct {
127127

128128
// if true need to update instance
129129
ForceReconcile bool `json:"forceReconcile,omitempty"`
130+
131+
// Last generation that was acted on
132+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
130133
}
131134

132135
// +kubebuilder:object:root=true
@@ -193,6 +196,10 @@ func (si *ServiceInstance) SetAnnotations(annotations map[string]string) {
193196
si.ObjectMeta.Annotations = annotations
194197
}
195198

199+
func (si *ServiceInstance) SetObservedGeneration(newObserved int64) {
200+
si.Status.ObservedGeneration = newObserved
201+
}
202+
196203
// +kubebuilder:object:root=true
197204

198205
// ServiceInstanceList contains a list of ServiceInstance

config/crd/bases/services.cloud.sap.com_servicebindings.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.1
6+
controller-gen.kubebuilder.io/version: v0.17.2
77
name: servicebindings.services.cloud.sap.com
88
spec:
99
group: services.cloud.sap.com
@@ -262,6 +262,10 @@ spec:
262262
description: Indicates when binding secret was rotated
263263
format: date-time
264264
type: string
265+
observedGeneration:
266+
description: Last generation that was acted on
267+
format: int64
268+
type: integer
265269
operationType:
266270
description: The operation type (CREATE/UPDATE/DELETE) for ongoing
267271
operation
@@ -347,6 +351,7 @@ spec:
347351
externalName:
348352
description: The name of the binding in Service Manager
349353
type: string
354+
maxLength: 100
350355
parameters:
351356
description: |-
352357
Parameters for the binding.

config/crd/bases/services.cloud.sap.com_serviceinstances.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.1
6+
controller-gen.kubebuilder.io/version: v0.17.2
77
name: serviceinstances.services.cloud.sap.com
88
spec:
99
group: services.cloud.sap.com
@@ -85,6 +85,7 @@ spec:
8585
externalName:
8686
description: The name of the instance in Service Manager
8787
type: string
88+
maxLength: 100
8889
parameters:
8990
description: |-
9091
Provisioning parameters for the instance.
@@ -250,6 +251,10 @@ spec:
250251
description: The generated ID of the instance, will be automatically
251252
filled once the instance is created
252253
type: string
254+
observedGeneration:
255+
description: Last generation that was acted on
256+
format: int64
257+
type: integer
253258
operationType:
254259
description: The operation type (CREATE/UPDATE/DELETE) for ongoing
255260
operation
@@ -336,6 +341,7 @@ spec:
336341
externalName:
337342
description: The name of the instance in Service Manager
338343
type: string
344+
maxLength: 100
339345
parameters:
340346
description: |-
341347
Provisioning parameters for the instance.

controllers/serviceinstance_controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
9898
if isFinalState(ctx, serviceInstance) {
9999
if len(serviceInstance.Status.HashedSpec) == 0 {
100100
updateHashedSpecValue(serviceInstance)
101-
err := r.Client.Status().Update(ctx, serviceInstance)
102-
if err != nil {
103-
return ctrl.Result{}, err
104-
}
101+
return ctrl.Result{}, utils.UpdateStatus(ctx, r.Client, serviceInstance)
105102
}
106103

107104
return ctrl.Result{}, nil

internal/utils/controller_util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func RemoveFinalizer(ctx context.Context, k8sClient client.Client, object client
5656
func UpdateStatus(ctx context.Context, k8sClient client.Client, object common.SAPBTPResource) error {
5757
log := GetLogger(ctx)
5858
log.Info(fmt.Sprintf("updating %s status", object.GetObjectKind().GroupVersionKind().Kind))
59+
object.SetObservedGeneration(getLastObservedGen(object))
5960
return k8sClient.Status().Update(ctx, object)
6061
}
6162

0 commit comments

Comments
 (0)