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
add preset controller #9545
Conversation
9576951
to
255bcf2
Compare
255bcf2
to
a349da5
Compare
) | ||
|
||
const ( | ||
ControllerName = "kkp_preset_controller" |
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.
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) |
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 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)) |
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.
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") |
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.
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) |
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.
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)) |
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.
Why is this error logged twice?
*/ | ||
|
||
/* | ||
Package presetcontroller contains a controller that is responsible for managing presets. |
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.
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") |
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.
t.Fatal
is enough here
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.
A few comments
I don't think this is helpful as a release note. What does this mean for the KKP admin or user? |
@xrstf thanks a lot for your review. PTAL |
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.
/approve
LGTM label has been added. Git tree hash: 85debfc5d58c6dea055efe179ba0fa80e2154372
|
[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 |
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