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

feat(k8s): always inject Kuma as the first container #5436

Merged
merged 2 commits into from
Dec 14, 2022

Conversation

curtiscook
Copy link
Contributor

@curtiscook curtiscook commented Dec 5, 2022

Checklist prior to review

  • Link to docs PR or issue -- Make Kuma's init container first by default #3121
  • Link to UI issue or PR -- n/a
  • Is the issue worked on linked? --
  • The PR does not hardcode values that might break projects that depend on kuma (e.g. "kumahq" as a image registry) --
  • The PR will work for both Linux and Windows, system specific functions like syscall.Mkfifo have equivalent implementation on the other OS --
  • Unit Tests --
  • E2E Tests --
  • Manual Universal Tests --
  • Manual Kubernetes Tests --
  • Do you need to update UPGRADE.md? -- no
  • Does it need to be backported according to the backporting policy? -- no
  • Do you need to explicitly set a > Changelog: entry here or add a ci/ label to run fewer/more tests?

@johnharris85
Copy link
Contributor

Thanks for the PR! This definitely needs to be flagged / configurable and documented as it's a breaking change. We should also document that this only represents a 'best-effort' to put our sidecar first, as another mutating controller could come along and be mischievous :)

@curtiscook
Copy link
Contributor Author

Thanks for the PR! This definitely needs to be flagged / configurable and documented as it's a breaking change. We should also document that this only represents a 'best-effort' to put our sidecar first, as another mutating controller could come along and be mischievous :)

Agree. This pr still needs

  1. configurability
  2. testing
  3. documentation

Also, the pr itself isn't very useful without a postStart hook on the sidecar, so would probably want to tie that in if possible. Will try to follow up with the cleanup when I get a chance. (Unless someone with more free time wants to take it across the finish line)

@lahabana
Copy link
Contributor

lahabana commented Dec 7, 2022

@slonka @johnharris85 Is it really a breaking change? I don't think it is without a postStart as the order of containers doesn't really influence anything (they are all started at once except if there's a postStart).

@slonka
Copy link
Contributor

slonka commented Dec 7, 2022

I thought that we're only considering this feature it with postStart otherwise it's not very useful (I thought that's what we agreed in some slack thread)

@curtiscook
Copy link
Contributor Author

It only really makes sense with postStart but we could always inject first and then set the config to add a postStart executable

@lahabana
Copy link
Contributor

lahabana commented Dec 7, 2022

Right so without postStart it's not especially useful to have it first. So isn't it likely to just have it always first and then make postStart optional/opt-in . So for this PR maybe we should not make this configurable (it should just be first)

@curtiscook
Copy link
Contributor Author

Right so without postStart it's not especially useful to have it first. So isn't it likely to just have it always first and then make postStart optional/opt-in . So for this PR maybe we should not make this configurable (it should just be first)

This seems sensible and atomic. I might keep the function for testability but drop the boolean in that case.

Originally I was going to incorporate both changes into this pr, but still not familiar with how configurations work in kuma so it's probably better to separate them.

As a side note, I think that allowing the main pod to start without effectively having a network is a critical issue, despite workarounds. This is mostly Kubernetes's fault, but I feel that it's worth handling. Currently the best workaround that I have found is to crash-loop the main pod until you can connect to an outside server i.e. some persistence layer. If you don't do this, Kubernetes seems to assume your node is in a ready state which results in rollouts causing unwanted downtime. Unfortunately the next best workaround is to disable the sidecar proxy, which is even less ideal if you're trying to implement traffic rules with mTLS

@lahabana
Copy link
Contributor

lahabana commented Dec 8, 2022

Ok so sounds like you should be able to update your PR to always inject it first (and sign your commit). Then we can help you work on adding the postStart option.

@curtiscook curtiscook force-pushed the c/inject-first branch 5 times, most recently from 30c5aeb to 131b874 Compare December 8, 2022 17:08
@curtiscook curtiscook changed the title [WIP, Draft] Allow Kuma Sidecar to be injected First Always Inject Kuma Sidecar as the first container definition in the pod Dec 8, 2022
@curtiscook curtiscook marked this pull request as ready for review December 8, 2022 17:11
@curtiscook curtiscook requested review from a team, michaelbeaumont and slonka and removed request for a team December 8, 2022 17:11
@lahabana
Copy link
Contributor

lahabana commented Dec 9, 2022

/format /golden_files

@lahabana
Copy link
Contributor

lahabana commented Dec 9, 2022

/format

@lahabana
Copy link
Contributor

lahabana commented Dec 9, 2022

  [FAILED] in [It] - /home/runner/work/kuma/kuma/pkg/plugins/runtime/k8s/webhooks/injector/injector_test.go:121 @ 12/09/22 12:29:03.163
  << Timeline

  [FAILED] Expected
      <string>: busybox
  to be equivalent to
      <string>: kuma-sidecar
  In [It] at: /home/runner/work/kuma/kuma/pkg/plugins/runtime/k8s/webhooks/injector/injector_test.go:121 @ 12/09/22 12:29:03.16

Looks like this actually fails

@curtiscook curtiscook changed the title Always Inject Kuma Sidecar as the first container definition in the pod chore(k8s): always inject Kuma as the first container Dec 9, 2022
@curtiscook curtiscook force-pushed the c/inject-first branch 3 times, most recently from d811a1e to b5c37fe Compare December 9, 2022 17:05
@lahabana
Copy link
Contributor

Your using go 19 that's why all these go embed got updated

@curtiscook curtiscook force-pushed the c/inject-first branch 2 times, most recently from 1bd3c95 to 014cd11 Compare December 12, 2022 16:57
@lahabana
Copy link
Contributor

/golden_files

@curtiscook
Copy link
Contributor Author

It looks like there are test cases under "should inject" that shouldn't inject

  [FAIL] Injector should inject Kuma into a Pod [It] 10. Pod with `kuma.io/sidecar-injection: disabled` annotation

@curtiscook curtiscook force-pushed the c/inject-first branch 4 times, most recently from 07af79d to e957bea Compare December 12, 2022 23:19
@curtiscook curtiscook requested review from lahabana and removed request for michaelbeaumont and slonka December 12, 2022 23:19
@curtiscook curtiscook force-pushed the c/inject-first branch 2 times, most recently from 2a72598 to e5d4147 Compare December 13, 2022 13:43
Signed-off-by: c <curtis@commonstock.com>
@curtiscook
Copy link
Contributor Author

I think this last test failure might be a flake, but not familiar enough with your test suite

Copy link
Contributor

@lahabana lahabana left a comment

Choose a reason for hiding this comment

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

Thx for the contrib!

Signed-off-by: Charly Molter <charly.molter@konghq.com>
@lahabana
Copy link
Contributor

@curtiscook I added a message in UPGRADE.md because there's a small upgrade path required. Merging as soon as CI passes

@lahabana lahabana enabled auto-merge (squash) December 14, 2022 09:17
@lahabana lahabana merged commit b126bc8 into kumahq:master Dec 14, 2022
@lahabana lahabana changed the title chore(k8s): always inject Kuma as the first container feat(k8s): always inject Kuma as the first container Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants