Skip to content

Commit

Permalink
delete unmanaged manifest in manifest controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanxin committed Sep 6, 2024
1 parent 9e511ba commit 9101b26
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
4 changes: 0 additions & 4 deletions api/v1beta2/manifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,3 @@ func (manifest *Manifest) IsSameChannel(otherManifest *Manifest) bool {
}
return channel == otherChannel
}

func (manifest *Manifest) HasDeletionTimestamp() bool {
return !manifest.GetDeletionTimestamp().IsZero()
}
8 changes: 7 additions & 1 deletion internal/declarative/v2/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu

if manifest.IsUnmanaged() {
manifest.SetFinalizers([]string{})
return r.updateManifest(ctx, manifest, metrics.ManifestUnmanagedUpdate)
if !manifest.GetDeletionTimestamp().IsZero() {
return r.cleanupManifest(ctx, req, manifest, manifestStatus, metrics.ManifestUnmanagedUpdate, nil)
}
if err := r.Delete(ctx, manifest); err != nil {
return ctrl.Result{}, fmt.Errorf("manifestController: %w", err)
}
return ctrl.Result{RequeueAfter: r.Success}, nil
}

if manifest.GetDeletionTimestamp().IsZero() {
Expand Down
5 changes: 1 addition & 4 deletions pkg/module/sync/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ func (r *Runner) updateManifest(ctx context.Context, kyma *v1beta2.Kyma,
if err != nil {
return err
}
if manifestInCluster != nil && module.IsUnmanaged && manifestInCluster.IsUnmanaged() {
return r.deleteManifest(ctx, module)
}

if err := r.doUpdateWithStrategy(ctx, kyma.Labels[shared.ManagedBy], module,
manifestInCluster, newManifest, moduleStatus); err != nil {
Expand Down Expand Up @@ -206,7 +203,7 @@ func NeedToUpdate(manifestInCluster, newManifest *v1beta2.Manifest, moduleInStat
return !(module.IsUnmanaged)
}

if module.IsUnmanaged && manifestInCluster.IsUnmanaged() {
if manifestInCluster.IsUnmanaged() {
return false
}

Expand Down
31 changes: 31 additions & 0 deletions pkg/module/sync/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,37 @@ func TestNeedToUpdate(t *testing.T) {
},
false,
},
{
"When cluster Manifest is unmanaged and module is managed, expect no update",
args{
&v1beta2.Manifest{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{shared.UnmanagedAnnotation: "true"},
},
Status: shared.Status{
State: "Ready",
},
},
&v1beta2.Manifest{},
&v1beta2.ModuleStatus{
State: "Ready", Template: &v1beta2.TrackingObject{
PartialMeta: v1beta2.PartialMeta{
Generation: trackedModuleTemplateGeneration,
},
},
}, &common.Module{
Template: &templatelookup.ModuleTemplateInfo{
ModuleTemplate: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Generation: trackedModuleTemplateGeneration,
},
},
},
IsUnmanaged: false,
},
},
false,
},
{
"When cluster Manifest is managed and module is unmanaged, expect update",
args{
Expand Down

0 comments on commit 9101b26

Please sign in to comment.