-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Update inject
to throw an error while injecting non-compliant pods
#4346
Update inject
to throw an error while injecting non-compliant pods
#4346
Conversation
Similarly, when the input has multiple non-compliant pods or a mix of compliant and non-compliant, the errors are accumulated and displayed as a single message and nothing is injected $ echo bad.yaml | bin/go-run cli inject -
Error transforming resources: failed to inject deployment/web - pods have a 3rd party proxy or initContainer already injected,
failed to inject deployment/web - pods use host networking Find |
Ping @kleimkuhler @alpeb |
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.
Looking good 👍
Can you also please fix the referred issue number in the description? |
fe71f52
to
5b20c62
Compare
@alpeb Thanks for the tip on wrapped errors - learnt something new! 😄 |
@mayankshah1607 Thanks for having humored me with the error wrapping suggestion. After having become more comfortable with that concept I realize now it's really meant for adding context to errors and not really for accumulating errors. So I take back that suggestion. |
I think you should also reintroduce the logic to properly concatenate the error messages. Currently doing
|
f11fcc2
to
99726e3
Compare
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.
Almost there!
cli/cmd/inject.go
Outdated
func throwInjectError(report *inject.Report) []error { | ||
|
||
errs := []error{} | ||
|
||
const ( | ||
disabledAutomountServiceAccountToken = "disabled_automount_service_account_token_account" | ||
hostNetworkEnabled = "host_network_enabled" | ||
sidecarExists = "sidecar_already_exists" | ||
udpPortsEnabled = "udp_ports_enabled" |
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.
Given this function is all about inject.Report
, I think it's better to move it into report.go
and make it a method of that struct. That will also avoid having to repeat these consts.
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 injection process to throw an error when the reason for failure is due to sidecar, udp, automountServiceAccountToken or hostNetwork Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
- rename `shouldInjectThrowError` to `throwInjectError` - `throwInjectError` accumulates all errors into a single error mesage instead of short circuiting at the first occurence of an error - update `processYAML` to accumulate error in a new error object rather that a slice of string - reuse errors messages from `inject.Reasons` map Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
99726e3
to
69ac7fc
Compare
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
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.
Thanks @mayankshah1607 !
Pinging @zaharidichev for one more approval! 😄 |
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.
LGTM. Just one minor feedback on the stdout output, and one question on the stderr output.
Also, it looks like we aren't handling the case when the automountServiceAccountToken
property is defined in the service account YAML. E.g.,
kind: ServiceAccount
apiVersion: v1
metadata:
name: emoji
namespace: emojivoto
automountServiceAccountToken: false
@alpeb @grampelberg do we want an issue to track that?
cli/cmd/inject.go
Outdated
@@ -304,6 +310,12 @@ func (resourceTransformerInject) generateReport(reports []inject.Report, output | |||
output.Write([]byte(fmt.Sprintf("%s %s\n", okStatus, udpDesc))) | |||
} | |||
|
|||
if len(automountServiceAccountTokenFalse) > 0 { | |||
output.Write([]byte(fmt.Sprintf("%s \"automountServiceAccountToken: false\" detected in %s\n", warnStatus, strings.Join(automountServiceAccountTokenFalse, ", ")))) |
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.
For my own understanding, output
writes to stderr
, right? But I can't seem to get the CLI to output this error. What am I missing?
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.
Ah, I think this might be redundant. The CLI will error out before this part of the code is executed.
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.
Let's remove it then. Thanks.
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.
Done 👍
Ah I didn't think of that... I guess the best we can do is to stop ignoring ServiceAccount manifests during injection and issue a warning whenever we encounter |
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
@mayankshah1607 That's correct. I created a separate issue (#4651) to deal with |
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
- Errors from each manifest to appear on new line Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Fixes #4214
This PR updates the way
inject
behaves while attempting to inject non-compliant pods, i.e, pods that have issues related to host network, UDP port, sidecars andautomountServiceAccountToken
Now instead of displaying warning messages and writing an uninjected YAML to
stdout
,inject
throws an error. For example :