Skip to content

Commit

Permalink
APIversion added to the params file (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz authored Nov 1, 2019
1 parent 061b1eb commit a071e91
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/testdata/index.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
entries:
zookeeper:
- appVersion: 3.4.10
digest: cbacc2e23ef1accc9308acbeff92f1aa8d2ddf712c76f50c114e817fb1a2a166
digest: fa9ba293e60d0770e686eab2618dadce896bdb556e1afd4554705487863f2089
maintainers:
- email: [email protected]
name: Alena Varkockova
Expand Down
10 changes: 9 additions & 1 deletion pkg/kudoctl/packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type PackageFiles struct {
}

type ParametersFile struct {
Params []v1beta1.Parameter `json:"parameters"`
APIVersion string `json:"apiVersion,omitempty"`
Params []v1beta1.Parameter `json:"parameters"`
}

// Operator is a representation of the KEP-9 Operator YAML
Expand Down Expand Up @@ -125,6 +126,13 @@ func readParametersFile(fileBytes []byte) (ParametersFile, error) {
if err := yaml.Unmarshal(fileBytes, &paramsFile); err != nil {
return paramsFile, err
}
if paramsFile.APIVersion == "" {
paramsFile.APIVersion = APIVersion
}
if paramsFile.APIVersion != APIVersion {
return paramsFile, fmt.Errorf("expecting supported API version %s but got %s", APIVersion, paramsFile.APIVersion)
}

return paramsFile, nil
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/kudoctl/packages/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,19 @@ func loadResourcesFromPath(goldenPath string) (*Resources, error) {

func Test_readParametersFile(t *testing.T) {
noParams := `
apiVersion: kudo.dev/v1beta1
parameters:
`
param := `
apiVersion: kudo.dev/v1beta1
parameters:
- name: example
`
example := make([]v1beta1.Parameter, 1)
example[0] = v1beta1.Parameter{Name: "example"}

bad := `
apiVersion: kudo.dev/v1beta1
parameters:
- oops:
`
Expand All @@ -139,9 +142,9 @@ parameters:
want ParametersFile
wantErr bool
}{
{"no data", []byte{}, ParametersFile{}, false},
{"no parameters", []byte(noParams), ParametersFile{}, false},
{"parameters", []byte(param), ParametersFile{example}, false},
{"no data", []byte{}, ParametersFile{APIVersion: APIVersion}, false},
{"no parameters", []byte(noParams), ParametersFile{APIVersion: APIVersion}, false},
{"parameters", []byte(param), ParametersFile{APIVersion, example}, false},
{"bad data", []byte(bad), ParametersFile{}, true},
}
for _, tt := range tests {
Expand Down
Binary file modified pkg/kudoctl/packages/testdata/zk.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/kudoctl/packages/testdata/zk/params.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: memory
description: Amount of memory to provide to Zookeeper pods
Expand Down
1 change: 1 addition & 0 deletions test/e2e/cli-install-uninstall/first-operator/params.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: replicas
description: Number of replicas that should be run as part of the deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: memory
description: Amount of memory to provide to Zookeeper pods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: replicas
description: Number of replicas that should be run as part of the deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: version
description: Version of image
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
apiVersion: kudo.dev/v1beta1
parameters:
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: version
description: Version of image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
parameters:
- name: version
description: Version of image
Expand Down

0 comments on commit a071e91

Please sign in to comment.