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: allow proxies to be injected using a native sidecar #1442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devjoes
Copy link

@devjoes devjoes commented Aug 21, 2024

Reason for Change:

Fixes Issue 773 by using native sidecars so that pods exit cleanly when running as cronjobs, currently azwi sidecar prevents the pod from terminating.

It also addresses an annoyance where the first container in the pod is the proxy, so any kubectl commands target that container, previously I was working around this by adding the default-container annotation.

I've kept the current behaviour as the default because this change requires at least k8s 1.28, adding the annotation azure.workload.identity/use-native-sidecar enables native sidecars. But it seems to work well so at some point in the future you could just make this the default behaviour.

No update to deployment.yaml

No change to Helm chart

Requirements

  • squashed commits
  • included documentation
  • added unit tests and e2e tests (if applicable).

Issue Fixed:

Fixes #733

Please answer the following questions with yes/no:

Does this change contain code from or inspired by another project? If so, did you notify the maintainers and provide attribution?

  • yes
  • no

Notes for Reviewers:
Tested on v1.30.0-eks-fff26e3

@devjoes devjoes requested review from aramase and enj as code owners August 21, 2024 10:04
@devjoes
Copy link
Author

devjoes commented Aug 21, 2024

@microsoft-github-policy-service agree

@devjoes
Copy link
Author

devjoes commented Sep 9, 2024

@aramase @enj any update on this PR? I've just rebased it and messaged our MS TAMs to see if they can do anything to get it merged.

@bench
Copy link

bench commented Dec 9, 2024

Hi,
Can we have any news for this PR please :)
@aramase @enj

@devjoes
Copy link
Author

devjoes commented Feb 13, 2025

@bench I think that this repo is dead tbh. I'm going to get on to our account managers and see if they can talk to whoever is in charge of it

Copy link
Member

@aramase aramase left a comment

Choose a reason for hiding this comment

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

Please also add a e2e test here to validate the new annotation.

@@ -21,9 +21,9 @@ All annotations are optional. If the annotation is not specified, the default va
| `azure.workload.identity/service-account-token-expiration` | **(Takes precedence if the service account is also annotated)** Represents the `expirationSeconds` field for the projected service account token. It is an optional field that the user might want to configure this to prevent any downtime caused by errors during service account token refresh. Kubernetes service account token expiry will not be correlated with AAD tokens. AAD tokens will expire in 24 hours after they are issued. | `3600` (acceptable range: `3600 - 86400`) |
| `azure.workload.identity/skip-containers` | Represents a semi-colon-separated list of containers (e.g. `container1;container2`) to skip adding projected service account token volume. By default, the projected service account token volume will be added to all containers. | |
| `azure.workload.identity/inject-proxy-sidecar` | Injects a proxy init container and proxy sidecar into the pod. The proxy sidecar is used to intercept token requests to IMDS and acquire an AAD token on behalf of the user with federated identity credential. | `true` |
| `azure.workload.identity/use-native-sidecar` | If injected then the proxy sidecar should be injected as a native sidecar init container instead of a container. Native sidecars are terminated when if pod exits, for instance when running as a cron-job. | `false` |
Copy link
Member

Choose a reason for hiding this comment

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

Add a note about the minimum required kubernetes version this annotation can be used.

Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong approach IMO. I think we should instead detect at runtime (once at webhook start up time) if the cluster supports native sidecars, and if it does, we should simply always use them for the proxy sidecar. If for some reason we cannot detect this at runtime, we can make it a CLI flag based config to the webhook (possibly enabled by default since in a few days Kube v1.30 will be the oldest supported upstream version).

Comment on lines +160 to +164
if useNativeSidecar {
pod.Spec.InitContainers = m.injectProxySidecarContainer(pod.Spec.InitContainers, proxyPort, ptr.To(corev1.ContainerRestartPolicyAlways))
} else {
pod.Spec.Containers = m.injectProxySidecarContainer(pod.Spec.Containers, proxyPort, nil)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if useNativeSidecar {
pod.Spec.InitContainers = m.injectProxySidecarContainer(pod.Spec.InitContainers, proxyPort, ptr.To(corev1.ContainerRestartPolicyAlways))
} else {
pod.Spec.Containers = m.injectProxySidecarContainer(pod.Spec.Containers, proxyPort, nil)
}
var restartPolicy *corev1.ContainerRestartPolicy
if useNativeSidecar {
restartPolicy = ptr.To(corev1.ContainerRestartPolicyAlways)
}
pod.Spec.Containers = m.injectProxySidecarContainer(pod.Spec.Containers, proxyPort, restartPolicy)

for _, container := range containers {
if container.Name == ProxySidecarContainerName {
return containers
// proxy-init starts with proxy, so we append ":" to imageRepository when checking
if strings.HasPrefix(container.Image, fmt.Sprintf("%s:", imageRepository)) || container.Name == ProxySidecarContainerName {
Copy link
Member

Choose a reason for hiding this comment

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

this check was removed as part of #1443

}
}
logLevel := currentLogLevel() // run the proxy at the same log level as the webhook

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -1151,7 +1151,7 @@ func TestInjectProxySidecarContainer(t *testing.T) {
m := &podMutator{proxyImage: imageURL}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
containers := m.injectProxySidecarContainer(test.containers, proxyPort)
containers := m.injectProxySidecarContainer(test.containers, proxyPort, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Update this table test to include restart policy and ensure the return result contains the desired restart policy

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.

azure.workload.identity/inject-proxy-sidecar blocks jobs in Kubernetes
4 participants