Skip to content

Commit 1b6532a

Browse files
authored
fix: handle reserved annotations for PVCs (#1103)
Closes #1102. Details: 1. fix the `reconcileAfter` logic 2. handle reserved annotations for PVCs
1 parent 3eaea28 commit 1b6532a

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/amaltheasession_controller.go

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

168168
newStatus := updates.Status(ctx, r, amaltheasession)
169-
statusChanged := reflect.DeepEqual(amaltheasession.Status, newStatus)
169+
statusChanged := !reflect.DeepEqual(amaltheasession.Status, newStatus)
170+
170171
amaltheasession.Status = newStatus
171172
err = r.Status().Update(ctx, amaltheasession)
172173
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)