Add inject support for namespace configs (Fix #3255)#3607
Conversation
b57023a to
eecba56
Compare
eecba56 to
1aff672
Compare
|
@mayankshah1607 Good work! Thanks for incorporating the review comments. It's cool to see that But you shouldn't need to change any of the |
1aff672 to
f5872c6
Compare
|
@ihcsim I reverted the changes and let the |
|
@mayankshah1607 Can you try running |
f5872c6 to
06c035f
Compare
|
@ihcsim Done! I ran |
|
@mayankshah1607 I was actually surprised by the updates to the I think the simplest way to solve this is to add a new field to the diff --git a/cli/cmd/inject.go b/cli/cmd/inject.go
index 0a2af4a2..7b4100c8 100644
--- a/cli/cmd/inject.go
+++ b/cli/cmd/inject.go
@@ -31,10 +31,11 @@ const (
)
type resourceTransformerInject struct {
- injectProxy bool
- configs *cfg.All
- overrideAnnotations map[string]string
- enableDebugSidecar bool
+ allowNamespaceInject bool
+ injectProxy bool
+ configs *cfg.All
+ overrideAnnotations map[string]string
+ enableDebugSidecar bool
}
func runInjectCmd(inputs []io.Reader, errWriter, outWriter io.Writer, transformer *resourceTransformerInject) int {
@@ -82,10 +83,11 @@ sub-folders, or coming from stdin.`,
options.overrideConfigs(configs, overrideAnnotations)
transformer := &resourceTransformerInject{
- injectProxy: manualOption,
- configs: configs,
- overrideAnnotations: overrideAnnotations,
- enableDebugSidecar: enableDebugSidecar,
+ allowNamespaceInject: true,
+ injectProxy: manualOption,
+ configs: configs,
+ overrideAnnotations: overrideAnnotations,
+ enableDebugSidecar: enableDebugSidecar,
}
exitCode := uninjectAndInject(in, stderr, stdout, transformer)
os.Exit(exitCode)
@@ -148,7 +150,7 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
}
reports := []inject.Report{*report}
- if conf.IsNamespace() {
+ if rt.allowNamespaceInject && conf.IsNamespace() {
b, err := conf.InjectNamespace(rt.overrideAnnotations)
return b, reports, err
}With this change, I'd expect there are no changes to the |
8a1bd5c to
74f6cc2
Compare
|
@ihcsim Thank you for pointing that out. It did feel little weird as to why The |
alpeb
left a comment
There was a problem hiding this comment.
Thanks @mayankshah1607 , looking good 👍
I think you should also couple this change with an update to linkerd uninject, which should now be removing the annotation from the namespace as well.
Also, could you rename files like cli/cmd/testdata/inject_emojivoto_namespace.good.golden.stderr to cli/cmd/testdata/inject_emojivoto_namespace_good.golden.report to follow the same pattern other existing test fixtures have?
|
@mayankshah1607 Yes, a separate PR for uninject makes sense 👍 |
ihcsim
left a comment
There was a problem hiding this comment.
@mayankshah1607 Thanks again for working on this issue 👍. All the integration tests passed on my machine:
=== PASS: all tests passed
I'll create a separate issue for updating the uninject command.
Also, please fill up this form when you next get the chance, so that we can send you some awesome Linkerd swags!
|
@alpeb Please approve and merge this PR when you next get the chance. Thanks! |
* Add method IsNamespace() to *ResourceConfig to check if a given workload if of Kind namespace * Add method InjectNamespace() to *ResourceConfig: Unmarshals yaml to ResourceConfig object, appends given annotations and marshals back to yaml. Also supports overrideAnnotations. * Add field allowNsInject to resourceTransformerInject to allow Ns injections only through inject command * Update method ParseMetaAndYAML() to support namespace kind configs * Add relevant unit tests (including overridden annotations) Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
74f6cc2 to
f2332f3
Compare
* Rename cli/cmd/testdata/inject_emojivoto_namespace.good.* files to cli/cmd/testdata/inject_emojivoto_namespace_good.* Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
* Add support for uninject command to uninject namespace configs * Add relevant unit tests in cli/cmd/uninject_test.go Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
Fixes #3255
This PR adds support for
linkerdinject to annotate namespaces as follows :kubectl get ns/default -o yaml | linkerd inject -Anything added to the said namespace gets linkerd support.
Add method
IsNamespace()to*ResourceConfigto check if a givenworkload if of Kind namespace
Add method
InjectNamespace()to*ResourceConfig: Unmarshals yamlto ResourceConfig object, appends given annotations and marshals back
to yaml. Also supports overrideAnnotations.
Add field allowNsInject to resourceTransformerInject to allow Ns
injections only through inject command
Update method
ParseMetaAndYAML()to support namespace kind configsAdd relevant unit tests (including overridden annotations)
Signed-off-by: Mayank Shah mayankshah1614@gmail.com