Skip to content

Add checks of dedicatedCPUPlacement to validation webhook #8886

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

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

opokornyy
Copy link
Contributor

@opokornyy opokornyy commented Dec 1, 2022

What this PR does / why we need it:

Setting dedicatedCPUPLacement is not supported at the moment and causes VMI to fail during start. This PR makes sure that instance type with dedicatedCPUPLacement is rejected by validation webhook.

Which issue(s) this PR fixes :
Fixes #8867

Release note:

Bug #8867 has been fixed, for now the dedicatedCPUPlacementattribute is no longer supported within the VirtualMachineInstancetype and VirtualMachineClusterInstancetype CRDs until support for resource requests is introduced.

Signed-off-by: Ondrej Pokorny opokorny@redhat.com

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L labels Dec 1, 2022
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Dec 1, 2022
@lyarwood
Copy link
Member

lyarwood commented Dec 1, 2022

/area instancetype
/cc @lyarwood

if instancetypeSpec.CPU.DedicatedCPUPlacement {
return []metav1.StatusCause{{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "setting spec.resources.DedicatedCPUPlacement is now allowed",
Copy link
Member

Choose a reason for hiding this comment

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

dedicatedCPUPlacement is not currently supported

return []metav1.StatusCause{{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "setting spec.resources.DedicatedCPUPlacement is now allowed",
Field: k8sfield.NewPath("spec", "instancetype").String(),
Copy link
Member

Choose a reason for hiding this comment

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

k8sfield.NewPath("spec", "cpu", "dedicatedCPUPlacement").String()

Comment on lines +113 to +115
if ar.Request.Resource != instanceTypeResource {
return fmt.Errorf("expected '%s' got '%s'", &instanceTypeResource, ar.Request.Resource)
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we have test coverage of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is just one test, that is testing unsupported version of ar.Request.Resource. I will add more tests to check also unsupported group and resource.

return &admissionv1.AdmissionResponse{
Allowed: true,
}
}

type ClusterInstancetypeAdmitter struct{}
func GetInstanceTypeFromAdmissionReview(ar *admissionv1.AdmissionReview) (*instancetypev1alpha2.VirtualMachineInstancetype, error) {
Copy link
Member

Choose a reason for hiding this comment

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

getInstanceTypeFromAdmissionReview

return &admissionv1.AdmissionResponse{
Allowed: true,
}
}

func GetClusterInstanceTypeFromAdmissionReview(ar *admissionv1.AdmissionReview) (*instancetypev1alpha2.VirtualMachineClusterInstancetype, error) {
Copy link
Member

Choose a reason for hiding this comment

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

getClusterInstanceTypeFromAdmissionReview

return &newInstanceType, nil
}

func ValidateRequestResource(ar *admissionv1.AdmissionReview, resourceType string) error {
Copy link
Member

Choose a reason for hiding this comment

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

validateRequestResource

return nil
}

func ValidateDedicatedCPUPlacement(instancetypeSpec *instancetypev1alpha2.VirtualMachineInstancetypeSpec) []metav1.StatusCause {
Copy link
Member

Choose a reason for hiding this comment

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

validateDedicatedCPUPlacement

ar := createInstancetypeAdmissionReview(instancetypeObj)
response := admitter.Admit(ar)

Expect(response.Allowed).To(BeFalse(), "Expected instancetype to not be allowed")
Copy link
Member

Choose a reason for hiding this comment

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

nit - Expect

Comment on lines 53 to 56
ObjectMeta: metav1.ObjectMeta{
Name: "test-name",
Namespace: "test-namespace",
},
Copy link
Member

Choose a reason for hiding this comment

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

BeforeEach already provides a basic InstancetypeObj with this set, all you need to do here is update the spec.

instancetypeObj.Spec = instancetypev1alpha2.VirtualMachineInstancetypeSpec{
	CPU: instancetypev1alpha2.CPUInstancetype{
		DedicatedCPUPlacement: true,
	},
}

@@ -47,6 +47,27 @@ var _ = Describe("Validating Instancetype Admitter", func() {
Expect(response.Allowed).To(BeFalse(), "Expected instancetype to not be allowed")
Expect(response.Result.Code).To(Equal(int32(http.StatusBadRequest)), "Expected error 400: BadRequest")
})

It("should reject instanceType with dedicatedCPUPlacement", func() {
Copy link
Member

Choose a reason for hiding this comment

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

supernit - instancetype

Setting dedicatedCPUPLacement is not supported at the
moment and causes VMI to fail during start. This PR
makes sure that instance type with dedicatedCPUPLacement
is rejected by validation webhook

Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
@opokornyy opokornyy force-pushed the dedicatedCPUPlacement branch from 4907260 to 48a2ade Compare December 1, 2022 13:16
Copy link
Member

@lyarwood lyarwood left a comment

Choose a reason for hiding this comment

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

/lgtm

What do you think about using the following as the release note?

Bug #8867 has been fixed, for now the `dedicatedCPUPlacement` attribute is no longer supported within the `VirtualMachineInstancetype` and `VirtualMachineClusterInstancetype` CRDs until support for resource requests is introduced.`

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2022
@lyarwood
Copy link
Member

lyarwood commented Dec 1, 2022

/retest

2 similar comments
@opokornyy
Copy link
Contributor Author

/retest

@opokornyy
Copy link
Contributor Author

/retest

@ksimon1
Copy link
Member

ksimon1 commented Dec 6, 2022

/lgtm
@xpivarc @enp0s3 can you please check this PR?

@ksimon1
Copy link
Member

ksimon1 commented Dec 12, 2022

@davidvossel, @acardace, @vladikr can you please check this PR?

Copy link
Member

@xpivarc xpivarc left a comment

Choose a reason for hiding this comment

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

/approve
I would personally split the changes into two commits, functional change and refactoring. It is then easier to review. This is just a suggestion for the future.

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xpivarc

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 12, 2022
@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

1 similar comment
@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-bot kubevirt-bot merged commit a7a69d5 into kubevirt:main Dec 13, 2022
@opokornyy
Copy link
Contributor Author

/cherrypick release-0.58

@kubevirt-bot
Copy link
Contributor

@opokornyy: new pull request created: #8938

In response to this:

/cherrypick release-0.58

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.

lyarwood added a commit to lyarwood/common-instancetypes that referenced this pull request Dec 13, 2022
A recent change to KubeVirt [1][2] has essentially disabled the use of
dedicatedCPUPlacement as we have no way of expressing the required
resource requirements through instance types at present.

Until this is corrected all requests to create instance types with this
attribute will be rejected. This change drops the use of this attribute
until this is resolved.

[1] kubevirt/kubevirt#8886
[2] kubevirt/kubevirt#8867

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
lyarwood added a commit to kubevirt/common-instancetypes that referenced this pull request Dec 13, 2022
A recent change to KubeVirt [1][2] has essentially disabled the use of
dedicatedCPUPlacement as we have no way of expressing the required
resource requirements through instance types at present.

Until this is corrected all requests to create instance types with this
attribute will be rejected. This change drops the use of this attribute
until this is resolved.

[1] kubevirt/kubevirt#8886
[2] kubevirt/kubevirt#8867

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
lyarwood added a commit to lyarwood/common-instancetypes that referenced this pull request Jan 25, 2023
Instance types using dedicatedCPUPlacement have recently started to be
rejected by virt-api [1] as we currently have no way of expressing the
required resource requests within an instance type.

dedicatedCPUPlacement is also a requirement when using
guestMappingPassthrough and as such this also needs to be removed from
our shipped instance types ahead of a similar check being introduced
[2] in virt-api.

[1] kubevirt/kubevirt#8886
[2] kubevirt/kubevirt#9105

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
kubevirt-bot pushed a commit to kubevirt/common-instancetypes that referenced this pull request Jan 26, 2023
Instance types using dedicatedCPUPlacement have recently started to be
rejected by virt-api [1] as we currently have no way of expressing the
required resource requests within an instance type.

dedicatedCPUPlacement is also a requirement when using
guestMappingPassthrough and as such this also needs to be removed from
our shipped instance types ahead of a similar check being introduced
[2] in virt-api.

[1] kubevirt/kubevirt#8886
[2] kubevirt/kubevirt#9105

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
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/instancetype dco-signoff: yes Indicates the PR's author has DCO signed all their commits. 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. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dedicatedCPUPlacement is not usable when set within an instance type
6 participants