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

Allow draining when DaemonSet kind has custom API Group #6412

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Allow draining when DaemonSet kind has custom API Group #6412

merged 2 commits into from
Jan 23, 2024

Conversation

shamil
Copy link
Contributor

@shamil shamil commented Dec 29, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

The issue is described in #5977

Which issue(s) this PR fixes:

Fixes #5977
Suppresses #6328

Special notes for your reviewer:

This PR is a continuation from #6328. Made the changes as requested by @x13n

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 29, 2023
@k8s-ci-robot k8s-ci-robot requested a review from x13n December 29, 2023 22:12
@shamil
Copy link
Contributor Author

shamil commented Dec 29, 2023

/assign @x13n @vadasambar

@@ -57,7 +58,10 @@ func (r *Rule) Drainable(drainCtx *drainability.DrainContext, pod *apiv1.Pod) dr
if controllerRef == nil {
return drainability.NewUndefinedStatus()
}
refKind := controllerRef.Kind

groupVersionKind := schema.FromAPIVersionAndKind(controllerRef.APIVersion, controllerRef.Kind)
Copy link
Member

Choose a reason for hiding this comment

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

Docs for FromAPIVersionAndKind says:

// FromAPIVersionAndKind returns a GVK representing the provided fields for types that
// do not use TypeMeta. This method exists to support test types and legacy serializations
// that have a distinct group and kind.
// TODO: further reduce usage of this method.

https://github.com/kubernetes/apimachinery/blob/e2f405af78de67e27b5dd5ceb1a3eca76331e4d5/pkg/runtime/schema/group_version.go#L296-L305

DaemonSet uses TypeMeta: https://pkg.go.dev/k8s.io/api/apps/v1#DaemonSet

Should we be using TypeMeta's GroupVersionKind() function here instead? GroupVersionKind() uses FromAPIVersionAndKInd() internally but there is less chance of GroupVersionKind() getting removed in the future (while FromAPIVersionKind() might)

Something like (at the cost of more verbosity):

v1.TypeMeta{Kind: controllerRef.Kind, APIVersion: controllerRef.APIVersion}.GroupVersionKind()

Copy link
Member

Choose a reason for hiding this comment

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

cc: @x13n

Copy link
Member

Choose a reason for hiding this comment

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

How about:

refGroup := schema.ParseGroupVersion(controllerRef.APIVersion)
refKind := controllerRef.Kind

ParseGroupVersion isn't annotated as something that is planned for removal.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me 👍

Copy link
Contributor Author

@shamil shamil Jan 21, 2024

Choose a reason for hiding this comment

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

Hi @vadasambar, @x13n

schema.ParseGroupVersion returns error in addition to schema.GroupVersion, will the following code be sufficient (which is similar to what we do for controllerRef)?

refGroup, err := schema.ParseGroupVersion(controllerRef.APIVersion)
if err != nil {
	return drainability.NewUndefinedStatus()
}

refKind := controllerRef.Kind

Or should I return drainability.NewBlockedStatus instead?

Copy link
Member

Choose a reason for hiding this comment

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

Undefined is ok in this case. If it didn't parse, it means it wasn't a correctly formatted APIVersion string.

Copy link
Member

Choose a reason for hiding this comment

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

(In particular, if it doesn't parse, it means it is not apps/v1.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, changed

@x13n
Copy link
Member

x13n commented Jan 23, 2024

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 23, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shamil, x13n

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2024
@k8s-ci-robot k8s-ci-robot merged commit 779c1ba into kubernetes:master Jan 23, 2024
6 checks passed
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/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoscaler not scaling down pods whenkind is of the resource is same between controllers
4 participants