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

CNV-34094: Add validating webhook #3132

Merged
merged 1 commit into from Nov 2, 2023

Conversation

nunnatsa
Copy link
Contributor

@nunnatsa nunnatsa commented Oct 25, 2023

What this PR does / why we need it:
Add validating webhook for HostedClusters and NodePools, to check if kubevirt external infra cluster is with sufficient CNV and K8s versions.

This is already checked on the operator, but adding this logic to the webhook will prevent the creating of resources in insufficient environment, in advance. Fixing this error is not an easy task and require upgrading the infra cluster, or the CNV installation, and we prefer to fail fast in this case.

Which issue(s) this PR fixes
Fixes #CNV-34094

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Oct 25, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 25, 2023

@nunnatsa: This pull request references CNV-34094 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.15.0" version, but no target version was set.

In response to this:

What this PR does / why we need it:
Add validating webhook for HostedClusters and NodePools, to check if kubevirt external infra cluster is with sufficient CNV and K8s versions.

This is already checked on the operator, but adding this logic to the webhook will prevent the creating of resources in insufficient environment, in advance. Fixing this error is not an easy task and require upgrading the infra cluster, or the CNV installation, and we prefer to fail fast in this case.

Which issue(s) this PR fixes
Fixes #CNV-34094

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

1 similar comment
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 25, 2023

@nunnatsa: This pull request references CNV-34094 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.15.0" version, but no target version was set.

In response to this:

What this PR does / why we need it:
Add validating webhook for HostedClusters and NodePools, to check if kubevirt external infra cluster is with sufficient CNV and K8s versions.

This is already checked on the operator, but adding this logic to the webhook will prevent the creating of resources in insufficient environment, in advance. Fixing this error is not an easy task and require upgrading the infra cluster, or the CNV installation, and we prefer to fail fast in this case.

Which issue(s) this PR fixes
Fixes #CNV-34094

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added area/ci-tooling Indicates the PR includes changes for CI or tooling area/cli Indicates the PR includes changes for CLI area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Oct 25, 2023
@nunnatsa
Copy link
Contributor Author

/test e2e-aws

@nunnatsa
Copy link
Contributor Author

/retest

@nunnatsa
Copy link
Contributor Author

/test e2e-aws

@nunnatsa
Copy link
Contributor Author

/retest

Copy link
Contributor

@davidvossel davidvossel left a comment

Choose a reason for hiding this comment

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

looks great! i made some minor comments. I also want to get Alberto's thoughts on removing the code that deletes the validation webhook. We obviously can't delete the validation webhook or else your logic here wouldn't work, but i want to make sure we account for whatever he was needing that deletion logic for. it's possible we might need to still delete the webhook but only if we are not explicitly having it enabled

Makefile Outdated
@@ -242,6 +242,7 @@ ci-install-hypershift-private:
--oidc-storage-provider-s3-credentials=/etc/hypershift-pool-aws-credentials/credentials \
--oidc-storage-provider-s3-bucket-name=hypershift-ci-oidc \
--oidc-storage-provider-s3-region=us-east-1 \
--enable-validating-webhook \
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't want to add the validating webhook here. This is used for CI jobs not related to kubevirt or self managed

hcPath := "/validate-hypershift-openshift-io-v1beta1-hostedcluster"
npPath := "/validate-hypershift-openshift-io-v1beta1-nodepool"
sideEffects := admissionregistrationv1.SideEffectClassNone
timeout := int32(10)
Copy link
Contributor

Choose a reason for hiding this comment

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

The mutating webhook uses a 15 second timeout. it would be good to be consistent

Comment on lines 329 to 347
// Since we dropped the validation webhook server we need to ensure this resource doesn't exist
// otherwise it will intercept kas requests and fail.
// TODO (alberto): dropped in 4.14.
validatingWebhookConfiguration := &admissionregistrationv1.ValidatingWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
Kind: "ValidatingWebhookConfiguration",
APIVersion: admissionregistrationv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: opts.Namespace,
Name: hyperv1.GroupVersion.Group,
},
}
if err := mgr.GetClient().Delete(ctx, validatingWebhookConfiguration); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@enxebre will we cause any issues by removing this code that deletes the validation webhook?

Copy link
Member

Choose a reason for hiding this comment

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

yes, we might have some envs running on versions where going through this is still necessary. So this would need to gate on if webhookNotEnabled kind of thing.
Also in addition please consider using ignore fail policy.

Copy link
Contributor Author

@nunnatsa nunnatsa Oct 30, 2023

Choose a reason for hiding this comment

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

Thanks @enxebre.

I'm not sure how to handle this. The flag is only known to the cli, and this is where the webhook is created. Main is running inside the cluster, knowing nothing about the installation and its configuration, AFAIK.

The only thing I can think of, is to use different webhook name for the new one. I don't like this idea and I find it confusing and error prompt. Also, not sure it's possible. The current name is hyperv1.GroupVersion.Group

Do you have any other idea?

Copy link
Member

Choose a reason for hiding this comment

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

we can explore either move the logic out to "install" or propagate the input into the HO options


if _, isTimeout := ctx.Deadline(); !isTimeout {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Second*3)
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd feel better if we extended this to a 5 second timeout... it likely doesn't matter, but i'm more on the conservative side when it comes to timing out operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make it 10, to be closer to the webhook T/O (15 sec)

Comment on lines +263 to +278
eg.Go(func() error {
var err error
cnvVersion, err = cl.GetInfraKubevirtVersion(egCtx)
return err
})

eg.Go(func() error {
var err error
k8sVersion, err = cl.GetInfraK8sVersion()
return err
})

err := eg.Wait()
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

that's kind of neat. I haven't seen this usage of errgroups before. looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add validating webhook for HostedClusters and NodePools, to check if
kubevirt external infra cluster is with sufficient CNV and K8s versions.

This is already checked on the operator, but adding this logic to the
webhook will prevent the creating of resources in insufficient
environment, in advance. Fixing this error is not an easy task and
require upgrading the infra cluster, or the CNV installation, and we
prefer to fail fast in this case.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
@nunnatsa
Copy link
Contributor Author

/rest e2e-aws

@nunnatsa
Copy link
Contributor Author

/test e2e-aws

Copy link
Contributor

@davidvossel davidvossel left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2023
Copy link
Contributor

openshift-ci bot commented Nov 1, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: davidvossel, nunnatsa

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 1, 2023
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 2462a4f and 2 for PR HEAD d95a109 in total

@nunnatsa
Copy link
Contributor Author

nunnatsa commented Nov 2, 2023

/retest

Copy link
Contributor

openshift-ci bot commented Nov 2, 2023

@nunnatsa: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-ci openshift-ci bot merged commit f6bcddb into openshift:main Nov 2, 2023
12 checks passed
@nunnatsa nunnatsa deleted the validate-kv-infra branch November 2, 2023 07:22
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. area/ci-tooling Indicates the PR includes changes for CI or tooling area/cli Indicates the PR includes changes for CLI area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants