Skip to content

Commit

Permalink
Fix wrong skipped message of linkerd inject for a namespace (#11179)
Browse files Browse the repository at this point in the history
Signed-off-by: Takumi Sue <[email protected]>
  • Loading branch information
mikutas authored Sep 6, 2023
1 parent 49f7d4e commit 4bef887
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
24 changes: 11 additions & 13 deletions cli/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,30 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
return nil, nil, errors.New("--manual must be set when injecting control plane components")
}

reports := []inject.Report{*report}

if conf.IsService() {
opaquePorts, ok := rt.overrideAnnotations[k8s.ProxyOpaquePortsAnnotation]
if ok {
annotations := map[string]string{k8s.ProxyOpaquePortsAnnotation: opaquePorts}
bytes, err = conf.AnnotateService(annotations)
report.Annotated = true
}
return bytes, reports, err
return bytes, []inject.Report{*report}, err
}
if rt.allowNsInject && conf.IsNamespace() {
bytes, err = conf.AnnotateNamespace(rt.overrideAnnotations)
report.Annotated = true
return bytes, reports, err
return bytes, []inject.Report{*report}, err
}
if conf.HasPodTemplate() {
if conf.HasPodTemplate() && len(rt.overrideAnnotations) > 0 {
conf.AppendPodAnnotations(rt.overrideAnnotations)
report.Annotated = true
}

if ok, _ := report.Injectable(); !ok {
if errs := report.ThrowInjectError(); len(errs) > 0 {
return bytes, reports, fmt.Errorf("failed to inject %s%s%s: %w", report.Kind, slash, report.Name, concatErrors(errs, ", "))
return bytes, []inject.Report{*report}, fmt.Errorf("failed to inject %s%s%s: %w", report.Kind, slash, report.Name, concatErrors(errs, ", "))
}
return bytes, reports, nil
return bytes, []inject.Report{*report}, nil
}

if rt.injectProxy {
Expand All @@ -210,7 +208,7 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
}

if len(patchJSON) == 0 {
return bytes, reports, nil
return bytes, []inject.Report{*report}, nil
}
log.Infof("patch generated for: %s", report.ResName())
log.Debugf("patch: %s", patchJSON)
Expand All @@ -230,7 +228,7 @@ func (rt resourceTransformerInject) transform(bytes []byte) ([]byte, []inject.Re
if err != nil {
return nil, nil, err
}
return injectedYAML, reports, nil
return injectedYAML, []inject.Report{*report}, nil
}

func (resourceTransformerInject) generateReport(reports []inject.Report, output io.Writer) {
Expand Down Expand Up @@ -333,20 +331,20 @@ func (resourceTransformerInject) generateReport(reports []inject.Report, output
}

for _, r := range reports {
if r.Annotated {
output.Write([]byte(fmt.Sprintf("%s \"%s\" annotated\n", r.Kind, r.Name)))
}
ok, _ := r.Injectable()
if ok {
output.Write([]byte(fmt.Sprintf("%s \"%s\" injected\n", r.Kind, r.Name)))
}
if !r.Annotated && !ok {
if !ok && !r.Annotated {
if r.Kind != "" {
output.Write([]byte(fmt.Sprintf("%s \"%s\" skipped\n", r.Kind, r.Name)))
} else {
output.Write([]byte(fmt.Sprintln("document missing \"kind\" field, skipped")))
}
}
if !ok && r.Annotated {
output.Write([]byte(fmt.Sprintf("%s \"%s\" annotated\n", r.Kind, r.Name)))
}
}

// Trailing newline to separate from kubectl output if piping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

namespace "emojivoto" skipped
namespace "emojivoto" annotated

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
√ pod specs do not include UDP ports
√ pods do not have automountServiceAccountToken set to "false" or service account token projection is enabled

namespace "emojivoto" skipped
namespace "emojivoto" annotated

2 changes: 1 addition & 1 deletion pkg/inject/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Report struct {
HostNetwork bool
Sidecar bool
UDP bool // true if any port in any container has `protocol: UDP`
UnsupportedResource bool
UnsupportedResource bool // unsupported to inject
InjectDisabled bool
InjectDisabledReason string
InjectAnnotationAt string
Expand Down

0 comments on commit 4bef887

Please sign in to comment.