-
Notifications
You must be signed in to change notification settings - Fork 69
remove the bundled NSTemplateTiers that are no longer used #1180
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
base: master
Are you sure you want to change the base?
Changes from all commits
a2f74ef
cebe77c
a9d224d
05bb8c9
cd13c5d
4303502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,10 @@ | |
|
||
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" | ||
"github.com/codeready-toolchain/host-operator/controllers/toolchainconfig" | ||
"github.com/codeready-toolchain/host-operator/pkg/constants" | ||
"github.com/codeready-toolchain/host-operator/pkg/templates/nstemplatetiers" | ||
"github.com/codeready-toolchain/toolchain-common/pkg/condition" | ||
"github.com/codeready-toolchain/toolchain-common/pkg/hash" | ||
"github.com/redhat-cop/operator-utils/pkg/util" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
|
@@ -20,6 +22,7 @@ | |
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
|
@@ -64,7 +67,7 @@ | |
} | ||
// if the NSTemplateTier is being deleted, then do nothing | ||
if util.IsBeingDeleted(tier) { | ||
return reconcile.Result{}, nil | ||
return reconcile.Result{}, r.handleDeletion(ctx, tier) | ||
} | ||
|
||
_, err := toolchainconfig.GetToolchainConfig(r.Client) | ||
|
@@ -91,6 +94,47 @@ | |
return reconcile.Result{}, err | ||
} | ||
|
||
func (r *Reconciler) handleDeletion(ctx context.Context, tier *toolchainv1alpha1.NSTemplateTier) error { | ||
if !util.HasFinalizer(tier, constants.BundledNSTemplateTierFinalizerName) { | ||
// no special handling required for "ordinary" nstemplatetiers | ||
return nil | ||
} | ||
|
||
bundled, err := nstemplatetiers.IsBundled(runtimeclient.ObjectKeyFromObject(tier)) | ||
if err != nil { | ||
return fmt.Errorf("failed to find if a tier is bundled or not (this shouldn't happen): %w", err) | ||
} | ||
|
||
if bundled { | ||
// let's just keep the bundled tier around even if someone wants to delete it. It'd be recreated at | ||
// the next start of the operator anyway. | ||
return nil | ||
} | ||
Comment on lines
+103
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that we should really check if it's bundled or not as part of the finalizer. If you would block the deletion, then the CR would end up in the terminating state forever. |
||
|
||
// We have a tier with a "bundled" finalizer that is not bundled - i.e. a tier that used to be bundled | ||
// but is not anymore and that is being deleted. We allow such deletion only when the tier is not used | ||
// by any space. | ||
used, err := isTierUsed(ctx, r.Client, tier) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !used { | ||
controllerutil.RemoveFinalizer(tier, constants.BundledNSTemplateTierFinalizerName) | ||
return r.Client.Update(ctx, tier) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func isTierUsed(ctx context.Context, client runtimeclient.Client, tier *toolchainv1alpha1.NSTemplateTier) (bool, error) { | ||
list := &toolchainv1alpha1.SpaceList{} | ||
if err := client.List(ctx, list, runtimeclient.InNamespace(tier.Namespace), runtimeclient.HasLabels{hash.TemplateTierHashLabelKey(tier.Name)}); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only an optimization tip (in this particular case it doesn't matter much) - you can use |
||
return false, err | ||
} | ||
return len(list.Items) > 0, nil | ||
} | ||
|
||
// ensureRevision ensures that there is a TierTemplateRevision CR for each of the TierTemplate. | ||
// returns `true` if a new TierTemplateRevision CR was created, `err` if something wrong happened | ||
func (r *Reconciler) ensureRevision(ctx context.Context, nsTmplTier *toolchainv1alpha1.NSTemplateTier) (bool, error) { | ||
|
@@ -183,7 +227,6 @@ | |
return false, "", err | ||
} | ||
return true, ttrName, nil | ||
|
||
} | ||
|
||
func (r *Reconciler) createNewTierTemplateRevision(ctx context.Context, nsTmplTier *toolchainv1alpha1.NSTemplateTier, tierTemplate *toolchainv1alpha1.TierTemplate) (string, error) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package constants | ||
|
||
import toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" | ||
|
||
// HostOperatorFieldManager is the field manager we want to use in the managed fields | ||
// of objects deployed by the host operator. | ||
const HostOperatorFieldManager = "kubesaw-host-operator" | ||
|
||
// BundledWithHostOperatorAnnotationValue is meant to be the value of the toolchainv1alpha1.BundledLabelKey that marks | ||
// the objects as bundled with the host operator and therefore managed by it. | ||
const BundledWithHostOperatorAnnotationValue = "host-operator" | ||
|
||
const BundledNSTemplateTierFinalizerName = toolchainv1alpha1.LabelKeyPrefix + "bundled-tier" |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code is still missing a logic that would add a finalizer