-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fix the custom injection on OpenShift #47898
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ import ( | |
"istio.io/istio/pkg/slices" | ||
"istio.io/istio/pkg/util/protomarshal" | ||
"istio.io/istio/pkg/util/sets" | ||
"istio.io/istio/tools/istio-iptables/pkg/constants" | ||
) | ||
|
||
var ( | ||
|
@@ -527,9 +528,8 @@ func reapplyOverwrittenContainers(finalPod *corev1.Pod, originalPod *corev1.Pod, | |
continue | ||
} | ||
overlay := *match.DeepCopy() | ||
if overlay.Image == AutoImage { | ||
overlay.Image = "" | ||
} | ||
resetFieldsInAutoImageContainer(&overlay, &c) | ||
|
||
overrides.Containers = append(overrides.Containers, overlay) | ||
newMergedPod, err := applyContainer(finalPod, overlay) | ||
if err != nil { | ||
|
@@ -549,9 +549,8 @@ func reapplyOverwrittenContainers(finalPod *corev1.Pod, originalPod *corev1.Pod, | |
continue | ||
} | ||
overlay := *match.DeepCopy() | ||
if overlay.Image == AutoImage { | ||
overlay.Image = "" | ||
} | ||
resetFieldsInAutoImageContainer(&overlay, &c) | ||
|
||
overrides.InitContainers = append(overrides.InitContainers, overlay) | ||
newMergedPod, err := applyInitContainer(finalPod, overlay) | ||
if err != nil { | ||
|
@@ -575,6 +574,23 @@ func reapplyOverwrittenContainers(finalPod *corev1.Pod, originalPod *corev1.Pod, | |
return finalPod, nil | ||
} | ||
|
||
func resetFieldsInAutoImageContainer(original *corev1.Container, template *corev1.Container) { | ||
if original.Image == AutoImage { | ||
original.Image = "" | ||
} | ||
|
||
// If the original pod comes with SecurityContext.RunAsUser and the template defines a value different than the default (1337), | ||
// then ignore the original value and stick with the final (merged one) | ||
// This is likely a scenario in OpenShift when the istio-proxy container with image: auto is parsed, if SecurityContext.RunAsUser | ||
// does not exist, OpenShift automatically assigns a value which is based on an annotation in the namespace. Regardless if the user | ||
// provided that value or if it was assigned by OpenShift, the correct value is the one in the template, as set by the `.ProxyUID` field. | ||
if original.SecurityContext != nil && template.SecurityContext != nil && template.SecurityContext.RunAsUser != nil && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @howardjohn fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM now although the function name is maybeconfusing |
||
*template.SecurityContext.RunAsUser != constants.DefaultProxyUIDInt { | ||
linsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
original.SecurityContext.RunAsUser = nil | ||
original.SecurityContext.RunAsGroup = nil | ||
} | ||
} | ||
|
||
// parseStatus extracts containers from injected SidecarStatus annotation | ||
func parseStatus(status string) ParsedContainers { | ||
parsedContainers := ParsedContainers{} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: release-notes/v2 | ||
kind: bug-fix | ||
area: installation | ||
docs: | ||
- 'https://istio.io/latest/docs/setup/additional-setup/sidecar-injection/#customizing-injection' | ||
releaseNotes: | ||
- | | ||
**Fixed** Custom injection of the `istio-proxy` container was not working on OpenShift because of the way OpenShift sets pod's `SecurityContext.RunAs` field. |
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.
Not sure why should we remove user's setting
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.
Indeed, this particular change in the test file was to guarantee we are not changing user values. This PR only changes it in a specific case: OpenShift.