Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skips Namespace deletion on installlerSet deletion #565

Merged
merged 1 commit into from
Dec 20, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, installerSet *v1alpha1.Te
return err
}

// Delete all resources except CRDs as they are own by owner of
// Delete all resources except CRDs and Namespace as they are own by owner of
// TektonInstallerSet
err = deleteManifests.Filter(mf.Not(mf.CRDs)).Delete()
// They will be deleted when the component CR is deleted
err = deleteManifests.Filter(mf.Not(mf.Any(namespacePred, mf.CRDs))).Delete()
if err != nil {
logger.Error("failed to delete resources")
return err
Expand Down Expand Up @@ -84,14 +85,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T
}

// Set owner of InstallerSet as owner of CRDs so that
// deleting the installer will not delete the CRDs
// If installerSet has not set any owner then crds will
// deleting the installer will not delete the CRDs and Namespace
// If installerSet has not set any owner then CRDs will
// not have any owner
installerSetOwner := installerSet.GetOwnerReferences()

installManifests, err = installManifests.Transform(
injectOwner(getReference(installerSet)),
injectOwnerForCRDs(installerSetOwner),
injectOwnerForCRDsAndNamespace(installerSetOwner),
)
if err != nil {
logger.Error("failed to transform manifest")
Expand Down
9 changes: 6 additions & 3 deletions pkg/reconciler/kubernetes/tektoninstallerset/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ func injectOwner(owner []v1.OwnerReference) mf.Transformer {
kind := u.GetKind()
if kind == "CustomResourceDefinition" ||
kind == "ValidatingWebhookConfiguration" ||
kind == "MutatingWebhookConfiguration" {
kind == "MutatingWebhookConfiguration" ||
kind == "Namespace" {
return nil
}
u.SetOwnerReferences(owner)
return nil
}
}

func injectOwnerForCRDs(owner []v1.OwnerReference) mf.Transformer {
func injectOwnerForCRDsAndNamespace(owner []v1.OwnerReference) mf.Transformer {
if len(owner) == 0 {
return func(u *unstructured.Unstructured) error { return nil }
}
return func(u *unstructured.Unstructured) error {
if u.GetKind() != "CustomResourceDefinition" {
kind := u.GetKind()
if kind != "CustomResourceDefinition" &&
kind != "Namespace" {
return nil
}
u.SetOwnerReferences(owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestInjectOwner_CRDs(t *testing.T) {
BlockOwnerDeletion: ptr.Bool(true),
}}

manifest, err := sourceManifest.Transform(injectOwnerForCRDs(owners))
manifest, err := sourceManifest.Transform(injectOwnerForCRDsAndNamespace(owners))
if err != nil {
t.Fatal("unexpected error: ", err)
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestInjectOwner_NonCRDs(t *testing.T) {
}}

// Must not add owner as resource is non-crd
manifest, err := sourceManifest.Transform(injectOwnerForCRDs(owners))
manifest, err := sourceManifest.Transform(injectOwnerForCRDsAndNamespace(owners))
if err != nil {
t.Fatal("unexpected error: ", err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/reconciler/shared/tektonconfig/tektonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ var _ tektonConfigreconciler.Finalizer = (*Reconciler)(nil)
func (r *Reconciler) FinalizeKind(ctx context.Context, original *v1alpha1.TektonConfig) pkgreconciler.Event {
logger := logging.FromContext(ctx)

if err := r.extension.Finalize(ctx, original); err != nil {
logger.Error("Failed to finalize platform resources", err)
}

if original.Spec.Profile == v1alpha1.ProfileLite {
return pipeline.TektonPipelineCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), v1alpha1.PipelineResourceName)
} else {
// TektonPipeline and TektonTrigger is common for profile type basic and all
if err := pipeline.TektonPipelineCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), v1alpha1.PipelineResourceName); err != nil {
if err := trigger.TektonTriggerCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), v1alpha1.TriggerResourceName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to delete in the reverse order of resource creation
as deleting TektonPipeline will delete namespace
we delete dashboard, triggers and then pipelines
just to make all resource get deleted in a cleaner way

return err
}
if err := trigger.TektonTriggerCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), v1alpha1.TriggerResourceName); err != nil {
if err := pipeline.TektonPipelineCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), v1alpha1.PipelineResourceName); err != nil {
return err
}
}

if err := r.extension.Finalize(ctx, original); err != nil {
logger.Error("Failed to finalize platform resources", err)
}

return nil
}

Expand Down