-
Notifications
You must be signed in to change notification settings - Fork 85
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
enhance handling prune for CR #214
Changes from all commits
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 |
---|---|---|
|
@@ -74,6 +74,21 @@ type DeclarativeObject interface { | |
metav1.Object | ||
} | ||
|
||
// Pruner is a trait for addon CRDs that determines whether pruning behavior should be enabled for the current CR. | ||
// To enable this feature, it's necessary to enable WithApplyPrune. If WithApplyPrune is enabled but Pruner is not | ||
// implemented, Prune behavior is assumed by default. | ||
type Pruner interface { | ||
Prune() bool | ||
} | ||
|
||
// PruneWhiteLister is a trait for addon CRDs that determines which kind of resources should be pruned. It's useful | ||
// when CR in installed by Addon and want to prune them automatically. The format of array item should be exactly like | ||
// <group>/<version>/<kind> (core group using 'core' indeed). For example: ["core/v1/ConfigMap", "batch/v1/Job"]. | ||
// Notice: kubeadm has a built-in prune white list, and it will be ignored if this method is implemented. | ||
type PruneWhiteLister interface { | ||
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. ditto. 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. And, 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. perfect! 😄 |
||
PruneWhiteList() []string | ||
} | ||
|
||
type ErrorResult struct { | ||
Result reconcile.Result | ||
Err error | ||
|
@@ -248,13 +263,20 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN | |
|
||
extraArgs := []string{"--force"} | ||
|
||
if r.options.prune { | ||
// allow user disable prune in CR | ||
if p, ok := instance.(Pruner); (!ok && r.options.prune) || (ok && r.options.prune && p.Prune()) { | ||
var labels []string | ||
for k, v := range r.options.labelMaker(ctx, instance) { | ||
labels = append(labels, fmt.Sprintf("%s=%s", k, v)) | ||
} | ||
|
||
extraArgs = append(extraArgs, "--prune", "--selector", strings.Join(labels, ",")) | ||
|
||
if lister, ok := instance.(PruneWhiteLister); ok { | ||
for _, gvk := range lister.PruneWhiteList() { | ||
extraArgs = append(extraArgs, "--prune-whitelist", gvk) | ||
} | ||
} | ||
} | ||
|
||
ns := "" | ||
|
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.
Could you add some explaination for this interface?
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.
An explanation of the interface has been appended.