Skip to content

Commit

Permalink
Add API version for operator.yaml (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz authored Nov 1, 2019
1 parent 97166e9 commit e73cb5b
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/repo_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestRepoIndexCmd(t *testing.T) {
riCmd := newRepoIndexCmd(fs, out, &time)
for key, value := range tt.flags {
if err := riCmd.Flags().Set(key, value); err != nil {
t.Fatal(err)
t.Fatalf("%s: %v", tt.name, err)
}
}
err := riCmd.RunE(riCmd, tt.arguments)
Expand Down
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: fa8d91d993397b0c8738d30826db4c562ad46affb4cc4acae9ade653d91258e0
digest: 0ab20aad336fa631e532d234cd98c75b755b3cac00f87abbf21165d48a017575
maintainers:
- email: [email protected]
name: Alena Varkockova
Expand Down
17 changes: 12 additions & 5 deletions pkg/kudoctl/packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const (
operatorFileName = "operator.yaml"
templateFileNameRegex = "templates/.*.yaml"
paramsFileName = "params.yaml"
ServerAPIVersion = "kudo.dev/v1alpha1"
PackageAPIVersion = "kudo.dev/v1beta1"
)

const apiVersion = "kudo.dev/v1alpha1"

// Resources is collection of CRDs that are used when installing operator
// during installation, package format is converted to this structure
type Resources struct {
Expand All @@ -47,6 +47,7 @@ type PackageFiles struct {

// Operator is a representation of the KEP-9 Operator YAML
type Operator struct {
APIVersion string `json:"apiVersion,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Version string `json:"version"`
Expand Down Expand Up @@ -87,6 +88,12 @@ func parsePackageFile(filePath string, fileBytes []byte, currentPackage *Package
if err := yaml.Unmarshal(fileBytes, &currentPackage.Operator); err != nil {
return errors.Wrap(err, "failed to unmarshal operator file")
}
if currentPackage.Operator.APIVersion == "" {
currentPackage.Operator.APIVersion = PackageAPIVersion
}
if currentPackage.Operator.APIVersion != PackageAPIVersion {
return fmt.Errorf("expecting supported API version %s but got %s", PackageAPIVersion, currentPackage.Operator.APIVersion)
}
case isTemplateFile(filePath):
pathParts := strings.Split(filePath, "templates/")
name := pathParts[len(pathParts)-1]
Expand Down Expand Up @@ -177,7 +184,7 @@ func (p *PackageFiles) getCRDs() (*Resources, error) {
operator := &v1alpha1.Operator{
TypeMeta: metav1.TypeMeta{
Kind: "Operator",
APIVersion: apiVersion,
APIVersion: ServerAPIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: p.Operator.Name,
Expand All @@ -196,7 +203,7 @@ func (p *PackageFiles) getCRDs() (*Resources, error) {
fv := &v1alpha1.OperatorVersion{
TypeMeta: metav1.TypeMeta{
Kind: "OperatorVersion",
APIVersion: apiVersion,
APIVersion: ServerAPIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", p.Operator.Name, p.Operator.Version),
Expand All @@ -220,7 +227,7 @@ func (p *PackageFiles) getCRDs() (*Resources, error) {
instance := &v1alpha1.Instance{
TypeMeta: metav1.TypeMeta{
Kind: "Instance",
APIVersion: apiVersion,
APIVersion: ServerAPIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-instance", p.Operator.Name),
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/packages/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestReadFileSystemPackage(t *testing.T) {
goldenFiles string
}{
{"zookeeper", "zk1", "testdata/zk", "testdata/zk-crd-golden1"},
{"zookeeper", "zk2", "testdata/zk.tgz", "testdata/zk-crd-golden2"},
{"zookeeper zipped", "zk2", "testdata/zk.tgz", "testdata/zk-crd-golden2"},
}
var fs = afero.NewOsFs()

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/operator.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "zookeeper"
version: "0.1.0"
appVersion: "3.4.10"
Expand Down
1 change: 1 addition & 0 deletions pkg/kudoctl/util/repo/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func TestAddPackageVersionErrorConditions(t *testing.T) {

func TestMapPackageFileToPackageVersion(t *testing.T) {
o := packages.Operator{
APIVersion: packages.ServerAPIVersion,
Name: "kafka",
Description: "",
Version: "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "first-operator"
version: "0.1.0"
kubernetesVersion: 1.13.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "cli-install-operator"
version: "0.1.0"
kudoVersion: 0.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "first-operator"
version: "0.1.0"
kubernetesVersion: 1.13.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "crd-operator"
version: "0.1.0"
kubernetesVersion: 1.13
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "crd-operator"
version: "0.1.0"
kubernetesVersion: 1.13
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "upgrade-operator"
version: "0.1.0"
kubernetesVersion: 1.13
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apiVersion: kudo.dev/v1beta1
name: "upgrade-operator"
version: "0.2.0"
kubernetesVersion: 1.13
Expand Down

0 comments on commit e73cb5b

Please sign in to comment.