mirror of https://github.com/linkerd/linkerd2.git
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:
parent
d64a2f3689
commit
1e82f62d6e
|
@ -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: {}
|
||||
---
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue