Skip to content

Commit a7b26e1

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 8d61ff7 commit a7b26e1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

api/v1beta1/zz_generated.deepcopy.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/zz_generated.deepcopy.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/kustomization_controller.go

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

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

474-
func (r *KustomizationReconciler) checkDependencies(kustomization kustomizev1.Kustomization) error {
474+
func (r *KustomizationReconciler) checkDependencies(source sourcev1.Source, kustomization kustomizev1.Kustomization) error {
475475
for _, d := range kustomization.Spec.DependsOn {
476476
if d.Namespace == "" {
477477
d.Namespace = kustomization.GetNamespace()
@@ -490,6 +490,10 @@ func (r *KustomizationReconciler) checkDependencies(kustomization kustomizev1.Ku
490490
if !apimeta.IsStatusConditionTrue(k.Status.Conditions, meta.ReadyCondition) {
491491
return fmt.Errorf("dependency '%s' is not ready", dName)
492492
}
493+
494+
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 {
495+
return fmt.Errorf("dependency '%s' is not updated yet", dName)
496+
}
493497
}
494498

495499
return nil

0 commit comments

Comments
 (0)