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

Avoid updating webhooks service account unless required. #300

Merged
merged 3 commits into from
Mar 8, 2021

Conversation

amisevsk
Copy link
Collaborator

@amisevsk amisevsk commented Mar 4, 2021

What does this PR do?

  • Remove checks for whether webhooks are enabled, since they're now required (for conversion at least)
  • Only update the webhooks serviceAccount when necessary, as otherwise our update wipes out the .secrets field and causes k8s to create a new secret for the SA.

What issues does this PR fix or reference?

Fixes #199

Is it tested? How?

  1. Deploy operator
  2. Run make restart a few times; after first run, log should contain Webhook server service account up to date instead of Updated webhook server service account and only one secret named devworkspace-controller-serviceaccount-token-xxxxx should exist.

@amisevsk amisevsk requested review from sleshchenko and JPinkney March 4, 2021 19:49
@amisevsk amisevsk changed the title Webhooks sa Avoid updating webhooks service account unless required. Mar 4, 2021
@amisevsk amisevsk requested a review from tinakurian March 4, 2021 20:23
amisevsk added 2 commits March 5, 2021 10:44
Since webhooks are required for conversion, set them to always enabled
and remove any related checks from the codebase.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Each time the webhooks serviceAccount is updated with nil .secrets, a new secret is
generated to fill the `secrets` field. This results in every restart of
the DevWorkspace operator creating a new secret on the cluster.

Since the only fields we set on the spec ServiceAccount are labels, we
only need to update when the labels differ from the cluster.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

LGTM

Left some comments but they can be addressed separately

return err
if needsUpdate(serviceAccount, existingCfg) {
serviceAccount.ResourceVersion = existingCfg.ResourceVersion
err = client.Update(ctx, serviceAccount)
Copy link
Member

Choose a reason for hiding this comment

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

Does it mean that after we update labels on SA, new token will be created? Can we avoid it with patching or it's by design for k8s?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The .secrets field in a SA object gets populated with a reference to the secret that should be used. When we apply the spec SA as an update, it wipes out that field and k8s fills it again... with a new secret.

We could potentially work around this by copying the current secrets field over to the spec before updating, but I'm not sure if that causes any issues in other ways, so I opted to avoid updating unless necessary (which realistically, should not be needed 99% of the time)

if config.ControllerCfg.GetWebhooksEnabled() != "true" {
return "", nil
}
func (r *DevWorkspaceReconciler) validateCreatorLabel(workspace *devworkspace.DevWorkspace) (msg string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to disable that check for non-restricted-access workspaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably, but all workspaces get a creator label now; the check itself is doing something kind of different from before. The only way we would have a DW without the label would be if it was created before webhooks, in which case it may make sense to fail the workspace anyways since it might have missed conversion, etc.

@@ -156,17 +156,6 @@ func (r *DevWorkspaceReconciler) Reconcile(req ctrl.Request) (reconcileResult ct
return reconcile.Result{Requeue: true}, err
}

restrictedAccess := clusterWorkspace.Annotations[config.WorkspaceRestrictedAccessAnnotation]
Copy link
Member

Choose a reason for hiding this comment

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

would it be a good idea to check if webhooks really exists on the cluster here? Or when they absent workspace can't be reconciled due validateCreatorLabel check?
I think the second.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's probably safer to do some check that webhooks are enabled (i.e. actually checking that webhooks exist on the cluster), but I would separate that out into another issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created #305

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amisevsk, sleshchenko

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:
  • OWNERS [amisevsk,sleshchenko]

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

@sleshchenko
Copy link
Member

/test v5-devworkspaces-operator-e2e

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
@openshift-ci-robot
Copy link
Collaborator

New changes are detected. LGTM label has been removed.

@amisevsk
Copy link
Collaborator Author

amisevsk commented Mar 8, 2021

/test v5-devworkspaces-operator-e2e

@amisevsk amisevsk merged commit ef4b1ee into devfile:main Mar 8, 2021
@amisevsk amisevsk deleted the webhooks-sa branch March 8, 2021 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Every time devworkspace operator is restarted, a new serviceaccount token is created
3 participants