Skip to content

Commit 2b9aac1

Browse files
leaftyolevski
authored andcommitted
fix: handle reserved annotations for PVCs (#1103)
Closes #1102. Details: 1. fix the `reconcileAfter` logic 2. handle reserved annotations for PVCs
1 parent baace48 commit 2b9aac1

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal/controller/amaltheasession_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ func (r *AmaltheaSessionReconciler) Reconcile(ctx context.Context, req ctrl.Requ
164164
}
165165

166166
newStatus := updates.Status(ctx, r, amaltheasession)
167-
statusChanged := reflect.DeepEqual(amaltheasession.Status, newStatus)
167+
statusChanged := !reflect.DeepEqual(amaltheasession.Status, newStatus)
168+
168169
amaltheasession.Status = newStatus
169170
err = r.Status().Update(ctx, amaltheasession)
170171
if err != nil {

internal/controller/children.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,25 @@ func (c ChildResource[T]) Reconcile(ctx context.Context, clnt client.Client, cr
186186
// NOTE: If the desired storage class is nil then the current spec contains the name for the default storage class
187187
current.Spec.StorageClassName = desired.Spec.StorageClassName
188188
}
189+
// Do not touch reserved labels and annotations
190+
// Reference: https://kubernetes.io/docs/reference/labels-annotations-taints/
191+
// TODO: handle labels
189192
current.Labels = desired.Labels
193+
preservedAnnotations := map[string]string{}
194+
for key := range current.Annotations {
195+
domain, _, _ := strings.Cut(key, "/")
196+
if domain == "kubernetes.io" || domain == "k8s.io" || strings.HasSuffix(domain, ".kubernetes.io") ||
197+
strings.HasSuffix(domain, ".k8s.io") {
198+
preservedAnnotations[key] = current.Annotations[key]
199+
}
200+
}
190201
current.Annotations = desired.Annotations
202+
if current.Annotations == nil {
203+
current.Annotations = map[string]string{}
204+
}
205+
for key := range preservedAnnotations {
206+
current.Annotations[key] = preservedAnnotations[key]
207+
}
191208
default:
192209
return fmt.Errorf("attempting to reconcile PVC with unknown stategy %s", strategy)
193210
}

0 commit comments

Comments
 (0)