Skip to content

Commit

Permalink
Modified code for patches and patchJson6902 which will throw error is…
Browse files Browse the repository at this point in the history
… target is not found

removed changes for patch

modified plugin and removed changes from generated file

added test case for patchesJson6902

modified test and generated data
  • Loading branch information
laxmikantbpandhare committed Jul 19, 2022
1 parent 8a72945 commit 941a44b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/internal/builtins/PatchJson6902Transformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions api/krusty/extendedpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,3 +1213,45 @@ spec:
app: busybox
`)
}

func TestTargetMissingPatchError(t *testing.T) {
th := kusttest_test.MakeHarness(t)
makeCommonFileForExtendedPatchTest(th)
th.WriteK("base", `
resources:
- servicemonitor.yaml
patchesJson6902:
- target:
group: monitoring.coreos.com
kind: ServiceMonitor
name: starboard-exporter
namespace: starboard
version: v2
path: patch.0.yaml
`)
th.WriteF("base/servicemonitor.yaml", `
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: starboard-exporter
name: starboard-exporter
namespace: starboard
spec:
endpoints:
- path: /metrics
port: metrics
selector:
matchLabels:
app.kubernetes.io/instance: starboard-exporter
app.kubernetes.io/name: starboard-exporter
`)
th.WriteF("base/patch.0.yaml", `
- op: add
path: /metadata/labels/release
value: kube-prometheus-stack
`)
err := th.RunWithErr("base", th.MakeDefaultOptions())
assert.Contains(t, err.Error(), "patchesJson6902 target not found for ServiceMonitor.v2.monitoring.coreos.com/starboard-exporter.starboard:a=:l= Bailing out.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (p *plugin) Transform(m resmap.ResMap) error {
if err != nil {
return err
}

if resources == nil {
return fmt.Errorf("patchesJson6902 target not found for %s Bailing out.", p.Target)
}

for _, res := range resources {
internalAnnotations := kioutil.GetInternalAnnotations(&res.RNode)

Expand Down

0 comments on commit 941a44b

Please sign in to comment.