Skip to content

Commit

Permalink
Update pkg fix to handle v1 partial setters suffix/infix
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Aug 4, 2020
1 parent 57d110c commit 8d46209
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ require (
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
sigs.k8s.io/cli-utils v0.17.0
sigs.k8s.io/kustomize/cmd/config v0.4.3-0.20200730200907-17f935452fb9
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200730200907-17f935452fb9
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200804211140-436c688bd077
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ sigs.k8s.io/kustomize/kyaml v0.4.2 h1:9/Tb90gnThv4vgUldZOLnrT+9Esdh7+Og2UIq024Yk
sigs.k8s.io/kustomize/kyaml v0.4.2/go.mod h1:XJL84E6sOFeNrQ7CADiemc1B0EjIxHo3OhW4o1aJYNw=
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200730200907-17f935452fb9 h1:2s0A6Cg5nNItPZgBNCtRz21DSkk4sA60EaFC7aDAgB8=
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200730200907-17f935452fb9/go.mod h1:bEzbO5pN9OvlEeCLvFHo8Pu7SA26Herc2m60UeWZBdI=
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200804211140-436c688bd077 h1:2zQdupGxBwKMKXreiaAo4jRWYuCz6SRAemW5Yf1ybKk=
sigs.k8s.io/kustomize/kyaml v0.4.3-0.20200804211140-436c688bd077/go.mod h1:bEzbO5pN9OvlEeCLvFHo8Pu7SA26Herc2m60UeWZBdI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca/go.mod h1:IIgPezJWb76P0hotTxzDbWsMYB8APh18qZnxkomBpxA=
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18=
Expand Down
2 changes: 2 additions & 0 deletions internal/cmdfix/cmdfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/GoogleContainerTools/kpt/internal/util/fix"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
)

// NewRunner returns a command runner
Expand Down Expand Up @@ -74,5 +75,6 @@ func (r *Runner) preRunE(c *cobra.Command, args []string) error {
}

func (r *Runner) runE(c *cobra.Command, args []string) error {
fieldmeta.SetShortHandRef("$kpt-set")
return r.Fix.Run()
}
20 changes: 13 additions & 7 deletions internal/cmdfix/cmdfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ created setter with name cluster
created setter with name profile
created setter with name project
created 3 setters in total
created substitution with name subst-project-cluster
created substitution with name project-cluster-54235872
created 1 substitution in total
`,

expectedOutput: `apiVersion: install.istio.io/v1alpha2
kind: IstioControlPlane
metadata:
cluster: "someproj/someclus" # {"$kpt-set":"subst-project-cluster"}
cluster: "someproj/someclus" # {"$kpt-set":"project-cluster-54235872"}
spec:
profile: asm # {"$openapi":"profile"}
cluster: "someproj/someclus" # {"$kpt-set":"subst-project-cluster"}
profile: asm # {"$kpt-set":"profile"}
cluster: "someproj/someclus" # {"$kpt-set":"project-cluster-54235872"}
`,

expectedOpenAPI: `apiVersion: kustomization.dev/v1alpha1
Expand All @@ -93,10 +93,10 @@ openAPI:
setter:
name: project
value: someproj
io.k8s.cli.substitutions.subst-project-cluster:
io.k8s.cli.substitutions.project-cluster-54235872:
x-k8s-cli:
substitution:
name: subst-project-cluster
name: project-cluster-54235872
pattern: ${project}/${cluster}
values:
- marker: ${project}
Expand Down Expand Up @@ -124,7 +124,7 @@ created setter with name cluster (dry-run)
created setter with name profile (dry-run)
created setter with name project (dry-run)
created 3 setters in total (dry-run)
created substitution with name subst-project-cluster (dry-run)
created substitution with name project-cluster-54235872 (dry-run)
created 1 substitution in total (dry-run)
`,
expectedOutput: `apiVersion: install.istio.io/v1alpha2
Expand Down Expand Up @@ -220,6 +220,12 @@ spec:
return
}

actualOutput, err := ioutil.ReadFile(filepath.Join(dir, "deploy.yaml"))
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, test.expectedOutput, string(actualOutput))

if test.expectedOpenAPI != "" {
actualOpenAPI, err := ioutil.ReadFile(filepath.Join(dir, openAPIFileName))
if !assert.NoError(t, err) {
Expand Down

0 comments on commit 8d46209

Please sign in to comment.