Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/controller/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,18 @@ func updateHelmParameter(goal api.PatternParameter, actual []argoapi.HelmParamet
}
return false
}

func syncApplicationWithPrune(client argoclient.Interface, app *argoapi.Application, namespace string) error {
app.Operation = &argoapi.Operation{
Sync: &argoapi.SyncOperation{
Prune: true,
},
}

_, err := client.ArgoprojV1alpha1().Applications(namespace).Update(context.Background(), app, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("failed to sync application %q with prune: %w", app.Name, err)
}

return nil
}
11 changes: 7 additions & 4 deletions internal/controller/pattern_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,11 @@ func (r *PatternReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

// -- GitOps Subscription
targetSub, _ := newSubscriptionFromConfigMap(r.fullClient)
_ = controllerutil.SetOwnerReference(qualifiedInstance, targetSub, r.Scheme)

sub, _ := getSubscription(r.olmClient, targetSub.Name)
if sub == nil {
err = createSubscription(r.olmClient, targetSub)
return r.actionPerformed(qualifiedInstance, "create gitops subscription", err)
} else if ownedBySame(targetSub, sub) {
} else if owner, ok := sub.Labels["app.kubernetes.io/managed-by"]; ok && owner == "patterns-operator" {
// Check version/channel etc
// Dangerous if multiple patterns do not agree, or automatic upgrades are in place...
changed, errSub := updateSubscription(r.olmClient, targetSub, sub)
Expand Down Expand Up @@ -528,6 +526,10 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
return fmt.Errorf("updated application %q for removal", app.Name)
}

if err := syncApplicationWithPrune(r.argoClient, app, ns); err != nil {
return err
}

if haveACMHub(r) {
return fmt.Errorf("waiting for removal of that acm hub")
}
Expand Down Expand Up @@ -604,7 +606,8 @@ func (r *PatternReconciler) onReconcileErrorWithRequeue(p *api.Pattern, reason s
}
if duration != nil {
log.Printf("Requeueing\n")
return reconcile.Result{RequeueAfter: *duration}, err
// Return nil error when we have a duration to avoid exponential backoff
return reconcile.Result{RequeueAfter: *duration}, nil
}
return reconcile.Result{}, err
}
Expand Down
1 change: 1 addition & 0 deletions internal/controller/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func newSubscriptionFromConfigMap(r kubernetes.Interface) (*operatorv1alpha1.Sub
ObjectMeta: metav1.ObjectMeta{
Name: GitOpsDefaultPackageName,
Namespace: SubscriptionNamespace,
Labels: map[string]string{"app.kubernetes.io/managed-by": "patterns-operator"},
},
Spec: spec,
}
Expand Down