-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
/area instancetype |
if instancetypeSpec.CPU.DedicatedCPUPlacement { | ||
return []metav1.StatusCause{{ | ||
Type: metav1.CauseTypeFieldValueInvalid, | ||
Message: "setting spec.resources.DedicatedCPUPlacement is now allowed", |
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.
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(), |
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.
k8sfield.NewPath("spec", "cpu", "dedicatedCPUPlacement").String()
if ar.Request.Resource != instanceTypeResource { | ||
return fmt.Errorf("expected '%s' got '%s'", &instanceTypeResource, ar.Request.Resource) | ||
} |
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.
Do we have test coverage of this?
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.
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) { |
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.
getInstanceTypeFromAdmissionReview
return &admissionv1.AdmissionResponse{ | ||
Allowed: true, | ||
} | ||
} | ||
|
||
func GetClusterInstanceTypeFromAdmissionReview(ar *admissionv1.AdmissionReview) (*instancetypev1alpha2.VirtualMachineClusterInstancetype, error) { |
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.
getClusterInstanceTypeFromAdmissionReview
return &newInstanceType, nil | ||
} | ||
|
||
func ValidateRequestResource(ar *admissionv1.AdmissionReview, resourceType string) error { |
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.
validateRequestResource
return nil | ||
} | ||
|
||
func ValidateDedicatedCPUPlacement(instancetypeSpec *instancetypev1alpha2.VirtualMachineInstancetypeSpec) []metav1.StatusCause { |
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.
validateDedicatedCPUPlacement
ar := createInstancetypeAdmissionReview(instancetypeObj) | ||
response := admitter.Admit(ar) | ||
|
||
Expect(response.Allowed).To(BeFalse(), "Expected instancetype to not be allowed") |
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.
nit - Expect
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-namespace", | ||
}, |
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.
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() { |
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.
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>
4907260
to
48a2ade
Compare
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.
/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.`
/retest |
2 similar comments
/retest |
/retest |
@davidvossel, @acardace, @vladikr can you please check this PR? |
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
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.
[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 |
/retest-required |
1 similar comment
/retest-required |
/cherrypick release-0.58 |
@opokornyy: new pull request created: #8938 In response to this:
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. |
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>
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>
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>
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>
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:
Signed-off-by: Ondrej Pokorny opokorny@redhat.com