Skip to content

Commit 8435a5b

Browse files
committed
If applied, this commit will solve race condition when using two Kustomizations with the same SourceRef
Signed-off-by: Florian Fl Bauer <[email protected]>
1 parent ed4d153 commit 8435a5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

controllers/kustomization_controller.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
205205

206206
// check dependencies
207207
if len(kustomization.Spec.DependsOn) > 0 {
208-
if err := r.checkDependencies(kustomization); err != nil {
208+
if err := r.checkDependencies(source, kustomization); err != nil {
209209
kustomization = kustomizev1.KustomizationNotReady(
210210
kustomization, source.GetArtifact().Revision, meta.DependencyNotReadyReason, err.Error())
211211
if err := r.patchStatus(ctx, req, kustomization.Status); err != nil {
@@ -470,7 +470,7 @@ func (r *KustomizationReconciler) reconcile(
470470
), nil
471471
}
472472

473-
func (r *KustomizationReconciler) checkDependencies(kustomization kustomizev1.Kustomization) error {
473+
func (r *KustomizationReconciler) checkDependencies(source sourcev1.Source, kustomization kustomizev1.Kustomization) error {
474474
for _, d := range kustomization.Spec.DependsOn {
475475
if d.Namespace == "" {
476476
d.Namespace = kustomization.GetNamespace()
@@ -489,6 +489,10 @@ func (r *KustomizationReconciler) checkDependencies(kustomization kustomizev1.Ku
489489
if !apimeta.IsStatusConditionTrue(k.Status.Conditions, meta.ReadyCondition) {
490490
return fmt.Errorf("dependency '%s' is not ready", dName)
491491
}
492+
493+
if k.Spec.SourceRef.Name == kustomization.Spec.SourceRef.Name && k.Spec.SourceRef.Namespace == kustomization.Spec.SourceRef.Namespace && k.Spec.SourceRef.Kind == kustomization.Spec.SourceRef.Kind && source.GetArtifact().Revision != k.Status.LastAppliedRevision {
494+
return fmt.Errorf("dependency '%s' is not updated yet", dName)
495+
}
492496
}
493497

494498
return nil

0 commit comments

Comments
 (0)