Fix uninject (#3236)

Now that we inject at the pod level by default, `linkerd uninject` should remove the `linkerd.io/inject: enabled`
annotation. Also added a test for that.

Fix #3156

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
This commit is contained in:
Alejandro Pedraza 2019-08-13 15:06:21 -05:00 committed by GitHub
parent d64a2f3689
commit 1e82f62d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 4 deletions

View File

@ -0,0 +1,38 @@
apiVersion: apps/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
name: web
namespace: emojivoto
spec:
replicas: 1
selector:
matchLabels:
app: web-svc
strategy: {}
template:
metadata:
annotations:
config.linkerd.io/admin-port: "1234"
creationTimestamp: null
labels:
app: web-svc
spec:
containers:
- env:
- name: WEB_PORT
value: "80"
- name: EMOJISVC_HOST
value: emoji-svc.emojivoto:8080
- name: VOTINGSVC_HOST
value: voting-svc.emojivoto:8080
- name: INDEX_BUNDLE
value: dist/index_bundle.js
image: buoyantio/emojivoto-web:v3
name: web-svc
ports:
- containerPort: 80
name: http
resources: {}
status: {}
---

View File

@ -23,6 +23,12 @@ func TestUninjectYAML(t *testing.T) {
goldenFileName: "inject_emojivoto_deployment.input.yml",
reportFileName: "inject_emojivoto_deployment_uninject.report",
},
{
// remove all the linkerd.io/* annotations
inputFileName: "inject_emojivoto_deployment_overridden_noinject.golden.yml",
goldenFileName: "inject_emojivoto_deployment_uninjected.input.yml",
reportFileName: "inject_emojivoto_deployment_uninject.report",
},
{
inputFileName: "inject_emojivoto_list.golden.yml",
goldenFileName: "inject_emojivoto_list.input.yml",

View File

@ -18,10 +18,10 @@ func (conf *ResourceConfig) Uninject(report *Report) ([]byte, error) {
conf.uninjectPodSpec(report)
if conf.workload.Meta != nil {
uninjectObjectMeta(conf.workload.Meta)
uninjectObjectMeta(conf.workload.Meta, report)
}
uninjectObjectMeta(conf.pod.meta)
uninjectObjectMeta(conf.pod.meta, report)
return conf.YamlMarshalObj()
}
@ -58,12 +58,16 @@ func (conf *ResourceConfig) uninjectPodSpec(report *Report) {
t.Volumes = volumes
}
func uninjectObjectMeta(t *metav1.ObjectMeta) {
func uninjectObjectMeta(t *metav1.ObjectMeta, report *Report) {
newAnnotations := make(map[string]string)
for key, val := range t.Annotations {
if !strings.HasPrefix(key, k8s.Prefix) || key == k8s.ProxyInjectAnnotation {
if !strings.HasPrefix(key, k8s.Prefix) ||
(key == k8s.ProxyInjectAnnotation && val == k8s.ProxyInjectDisabled) {
newAnnotations[key] = val
} else {
report.Uninjected.Proxy = true
}
}
t.Annotations = newAnnotations