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

add preset controller #9545

Merged
merged 2 commits into from Apr 7, 2022
Merged

Conversation

zreigz
Copy link
Contributor

@zreigz zreigz commented Apr 6, 2022

What does this PR do / Why do we need it: add a preset controller. Checks if preset was deleted and changes all affected clusters (set credential preset annotation)

Does this PR close any issues?:
Fixes #9464

Add a controller to monitor preset deletion. All affected clusters will be annotated. The end-user can make the decision to migrate the cluster credentials.

@kubermatic-bot kubermatic-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. sig/cluster-management Denotes a PR or issue as being assigned to SIG Cluster Management. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 6, 2022
@zreigz zreigz force-pushed the preset-controller branch 2 times, most recently from 9576951 to 255bcf2 Compare April 6, 2022 12:37
)

const (
ControllerName = "kkp_preset_controller"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use regular "-" and not underscores.

func (r *reconciler) reconcile(ctx context.Context, preset *kubermaticv1.Preset, log *zap.SugaredLogger) error {
// handle deletion to change all cluster annotation
if !preset.DeletionTimestamp.IsZero() {
log.Debugf("The preset %s was deleted", preset.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

The log you're using already has the request as a context, there is no need to include the preset name in the log message again.


clusters := &kubermaticv1.ClusterList{}
if err := r.seedClient.List(ctx, clusters, listOpts); err != nil {
log.Errorw("Failed to get clusters", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this error logged effectively twice? (once here, once in Reconcile())

log.Errorw("Failed to get clusters", zap.Error(err))
return fmt.Errorf("failed to get clusters %w", err)
}
log.Debugf("Update clusters after preset deletion")
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug instead of Debugf

log.Debugf("Update clusters after preset deletion")
for _, cluster := range clusters.Items {
if cluster.Annotations != nil && cluster.Annotations[kubermaticv1.PresetNameAnnotation] == preset.Name {
log.Debugf("Update cluster %s", cluster.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use structured logging, i.e. log.Debugw("Update cluster", "cluster", cluster.Name)

copyCluster := cluster.DeepCopy()
copyCluster.Annotations[kubermaticv1.PresetInvalidatedAnnotation] = string(kubermaticv1.PresetDeleted)
if err := r.seedClient.Update(ctx, copyCluster); err != nil {
log.Errorw("Failed to update cluster", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this error logged twice?

*/

/*
Package presetcontroller contains a controller that is responsible for managing presets.
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, I read the ticket and the PR and I still don't know what this controller does or why. When a preset is deleted, it sets some annotation? Why? What is this used for? Can you please describe the purpose of this controller more than "The x-controller is a controller that controls X." :)

t.Fatalf("can't get expected cluster %s", clusterName)
}
if cluster.Annotations == nil {
t.Fatalf("expected annotations for the cluster")
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Fatal is enough here

Copy link
Contributor

@xrstf xrstf left a comment

Choose a reason for hiding this comment

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

A few comments

@xrstf
Copy link
Contributor

xrstf commented Apr 6, 2022

"Add preset controller"

I don't think this is helpful as a release note. What does this mean for the KKP admin or user?

@zreigz
Copy link
Contributor Author

zreigz commented Apr 7, 2022

@xrstf thanks a lot for your review. PTAL

Copy link
Contributor

@xrstf xrstf left a comment

Choose a reason for hiding this comment

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

/approve

@kubermatic-bot kubermatic-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 7, 2022
@kubermatic-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 85debfc5d58c6dea055efe179ba0fa80e2154372

@kubermatic-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xrstf, zreigz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubermatic-bot kubermatic-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 7, 2022
@kubermatic-bot kubermatic-bot merged commit 5621161 into kubermatic:master Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-management Denotes a PR or issue as being assigned to SIG Cluster Management. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create preset controller
3 participants