-
Notifications
You must be signed in to change notification settings - Fork 97
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
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
@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 |
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.
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` | |
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.
Add a note about the minimum required kubernetes version this annotation can be used.
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.
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).
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) | ||
} |
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.
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 { |
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.
this check was removed as part of #1443
} | ||
} | ||
logLevel := currentLogLevel() // run the proxy at the same log level as the webhook | ||
|
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.
@@ -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) |
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.
Update this table test to include restart policy and ensure the return result contains the desired restart policy
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
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?
Notes for Reviewers:
Tested on v1.30.0-eks-fff26e3