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

DisableServiceLinks admission controller #122631

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

jmcgrath207
Copy link
Contributor

@jmcgrath207 jmcgrath207 commented Jan 7, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds an optional admission controller to disable EnableServiceLinks for new Pods without the need for a third-party mutating webhook.

Which issue(s) this PR fixes:

Fixes # #121787

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Thios PR was reverted in #125002.

The original relnote, for posterity: Added DisableServiceLinks admission controller: An optional mutating controller that will set Spec.EnableServiceLinks: False for all pods manifests in the cluster before scheduling.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

Agreement to solve this issue with an optional admission controller.
REF: #121787 (comment)


@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 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 Jan 7, 2024
Copy link

linux-foundation-easycla bot commented Jan 7, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jmcgrath207 / name: John McGrath (edb0287)

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 7, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @jmcgrath207!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 7, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @jmcgrath207. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 7, 2024
@carlory
Copy link
Member

carlory commented Jan 7, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 7, 2024
// newDisableServiceLinks creates a new instance of the DisableServiceLinks admission controller.
func newDisableServiceLinks() *plugin {
return &plugin{
Handler: admission.NewHandler(admission.Create, admission.Update),
Copy link
Member

Choose a reason for hiding this comment

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

I think this should operate only on Create, IIUIC Updates to a Pod will not recreate the environment variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Catch!

I did some testing in kind and found those fields are immutable when updating a pod. I removed admission.Update in my commit.

$ kubectl apply -f simple-pod.yaml 
The Pod "nginx" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)
  core.PodSpec{
  	... // 26 identical fields
  	RuntimeClassName:          nil,
  	Overhead:                  nil,
- 	EnableServiceLinks:        &true,
+ 	EnableServiceLinks:        &false,
  	TopologySpreadConstraints: nil,
  	OS:                        nil,
  	... // 2 identical fields
  }


Copy link
Member

Choose a reason for hiding this comment

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

Supporting update might be a no-op today, but could be future-safe

@jmcgrath207
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind-ipv6
/test pull-kubernetes-dependencies

return errors.NewBadRequest(fmt.Sprintf("expected *core.Pod but got %T", attributes.GetObject()))
}

pod.Spec.EnableServiceLinks = ptr.To(false)
Copy link
Member

@aojea aojea Jan 8, 2024

Choose a reason for hiding this comment

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

if we don't find a way to differentiate between defaulted by the apiserver or set by the user adding Always to the plugin name may be more accurate, AlwaysDisableServiceLinks

is just a thought wait for discussion of other reviewers

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 want to make this "smarter" (dubious judgement) and respect cases where the user actually set it, or do we want it to be unilateral and ALWAYS disable it?

This is a semantic decision. If it was easy, I'd say let's respect the user's input but it's not. It's not very complicated, but it's not trivial. Is it worthwhile?

Notes:

2 ways to do it:

  1. Look at managed fields info to see what was defaulted. ISTR there is not actually enough info to determine this?

  2. Let plugins see it as nil.

PrepareForCreate() is called from BeforeCreate() is called from staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go Store.create().

createValidation (which includes admission plugins) is called AFTER callingBeforeCreate().

This means that we can't set the default in PrepareForCreate. We'd need a hook AFTER BeforeCreate() but before e.Storage.Create() to set defaults

@aojea
Copy link
Member

aojea commented Jan 8, 2024

one last comment #122631 (comment) and one doubt #122631 (comment) but LGTM
/assign @thockin

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jan 12, 2024
@jmcgrath207
Copy link
Contributor Author

@carlory Ah, I misunderstood. I've updated the release note description. Does this work for you?

@jmcgrath207 jmcgrath207 changed the title Disable EnableServiceLinks admission controller DisableServiceLinks admission controller Jan 12, 2024
@thockin
Copy link
Member

thockin commented Mar 4, 2024

I'll approve and hold, if you want to re-add Update or rename it, ping me. Else just clear the hold.

/approve
/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 4, 2024
@thockin thockin added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2024
@k8s-ci-robot k8s-ci-robot requested a review from thockin March 6, 2024 06:24
@jmcgrath207 jmcgrath207 force-pushed the disable-service-links branch from da39708 to edb0287 Compare March 6, 2024 06:40
@jmcgrath207
Copy link
Contributor Author

Thanks @thockin

I've added the noop for admission.Update and updated the tests to reflect the admission operation. I also rebased and squashed.

If there is nothing else, I am ready to merge.

@thockin
Copy link
Member

thockin commented Mar 7, 2024

Ugh, I missed this ping in the code freeze chaos. It will have to wait for 1.31.

Copy link
Member

@thockin thockin 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

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

LGTM label has been added.

Git tree hash: 669ad6c4d821f5d6ccdc9dfe59cc94652caf86da

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jmcgrath207, thockin

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

@thockin thockin removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit 6faeecc into kubernetes:master Apr 18, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Apr 18, 2024
@enj
Copy link
Member

enj commented May 14, 2024

IMO this PR is the wrong approach, and we should consider reverting it before we release v1.31. kubernetes/enhancements#3962 should give users the ability to tweak the default as they desire though the Kube API, and we don't need to create one off admission plugins for every wrong default we have (especially since admission config isn't available to users on some environments).

@thockin
Copy link
Member

thockin commented May 14, 2024

I don't have any philosophical preference for this sort of laser-focused admission plugins over MAP, except that MAP is alpha. At the time this proposal was in flgiht I wasn't so aware of MAP. That said, the interplay between default values and admission control sequencing leaves me scratching my head still. In a MAP or mutating webhook, I can't tell if a value was specified by a user or by the defaulting logic. This PR would probably consider that if it could, but it can't, so it doesn't.

This issue is not so urgent that it can't wait for MAP, though I hope it's not TOOO long. So I guess I agree with @enj - are there any major reasons why we couldn't back this out and pivot the solution to MAP?

@jmcgrath207 ?

@thockin
Copy link
Member

thockin commented May 20, 2024

ping to @jmcgrath207 one more time

@jmcgrath207
Copy link
Contributor Author

Hey All,

Sorry for the late response.

I went ahead and reviewed KEP-3962, and I agree this meets my needs.

I feel it's best to revert my commit and move forward with the KEP-3962 solution to prevent a deprecation scenario. The Alpha part doesn't bother me since both solutions would require a control-plane config change.

As for urgency, users can use a policy controller like kyverno that I mentioned here here or it can just edit the manifest. I assume I am in the minority here with heavy restrictions on image approval running in their environment.

@thockin
Copy link
Member

thockin commented May 20, 2024

Do you want to send a revert or shall I?

@jmcgrath207
Copy link
Contributor Author

jmcgrath207 commented May 20, 2024

@thockin Here is the revert PR. If this isn't the proper way, I have no issues with you reverting it.

#125002

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels May 20, 2024
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/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants