Skip to content

Commit f7159b4

Browse files
author
Jan Schlicht
authored
Use 'appVersion' and 'operatorVersion' in API (#7)
This change reflects KUDO's version handling as described in KEP-19. Signed-off-by: Jan Schlicht <[email protected]>
1 parent 8d4b343 commit f7159b4

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ Consider an operator that is developed in a Git repository. The actual operator
2323
apiVersion: index.kudo.dev/v1alpha1
2424
kind: Operator
2525
name: MyOperator
26-
git-sources:
27-
- name: my-git-repository
28-
url: https://github.com/example/myoperator.git
26+
gitSources:
27+
- name: my-git-repository
28+
url: https://github.com/example/myoperator.git
2929
versions:
30-
- version: "1.0.0"
31-
git:
32-
source: my-git-repository
33-
directory: operator
34-
tag: "v1.0.0"
35-
- version: "2.0.0"
36-
git:
37-
source: my-git-repository
38-
directory: operator
39-
tag: "v2.0.0"
30+
- operatorVersion: "1.0.0"
31+
git:
32+
source: my-git-repository
33+
directory: operator
34+
tag: "v1.0.0"
35+
- operatorVersion: "2.0.0"
36+
git:
37+
source: my-git-repository
38+
directory: operator
39+
tag: "v2.0.0"
4040
```
4141
4242
Running `kitt update` with this YAML as an argument will check out the referenced Git repository with the specified tags `v1.0.0` and `v2.0.0`, build tarballs from the operator package in the `operator` folder, and add these tarballs to a KUDO repository.

pkg/apis/operator/v1alpha1/types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Operator struct {
88
Name string `yaml:"name"`
99

1010
// GitSources are optional references to Git repositories.
11-
GitSources []GitSource `yaml:"git-sources,omitempty"`
11+
GitSources []GitSource `yaml:"gitSources,omitempty"`
1212

1313
// Versions of the operator.
1414
Versions []Version `yaml:"versions"`
@@ -32,7 +32,11 @@ type GitSource struct {
3232

3333
// Version describes a version of a KUDO operator.
3434
type Version struct {
35-
Version string `yaml:"version"`
35+
// OperatorVersion of the KUDO operator.
36+
OperatorVersion string `yaml:"operatorVersion"`
37+
38+
// AppVersion of the KUDO operator, optional.
39+
AppVersion string `yaml:"appVersion,omitempty"`
3640

3741
// Git specifies a version as a directory in a Git repository with a
3842
// specific tag.

pkg/internal/apis/operator/encode/convert.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ func convertV1Alpha1GitSource(in v1alpha1.GitSource) operator.GitSource {
3636

3737
func convertV1Alpha1Version(in v1alpha1.Version) operator.Version {
3838
out := operator.Version{
39-
Version: in.Version,
40-
URL: in.URL,
39+
OperatorVersion: in.OperatorVersion,
40+
AppVersion: in.AppVersion,
41+
URL: in.URL,
4142
}
4243

4344
if in.Git != nil {

pkg/internal/apis/operator/types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package operator
22

3+
import "fmt"
4+
35
// Operator describes the location of a KUDO operator.
46
type Operator struct {
57
// Name of the operator.
@@ -23,7 +25,11 @@ type GitSource struct {
2325

2426
// Version describes a version of a KUDO operator.
2527
type Version struct {
26-
Version string
28+
// OperatorVersion of the KUDO operator.
29+
OperatorVersion string
30+
31+
// AppVersion of the KUDO operator, optional.
32+
AppVersion string
2733

2834
// Git specifies a version as a directory in a Git repository with a
2935
// specific tag.
@@ -33,6 +39,16 @@ type Version struct {
3339
URL *string
3440
}
3541

42+
// Version prints the version as a combination of appVersion and operatorVersion
43+
// as described in KEP-19.
44+
func (v Version) Version() string {
45+
if v.AppVersion != "" {
46+
return fmt.Sprintf("%s_%s", v.AppVersion, v.OperatorVersion)
47+
}
48+
49+
return v.OperatorVersion
50+
}
51+
3652
// Git references a specific tag of a Git repository of a KUDO operator.
3753
type Git struct {
3854
// Source references a 'GitSource' name. The source's Git repository is

pkg/update/update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func Update(
4747
for _, operator := range operators {
4848
for _, version := range operator.Versions {
4949
log.WithField("operator", operator.Name).
50-
WithField("version", version.Version).
50+
WithField("version", version.Version()).
5151
WithField("repository", repoURL).
5252
WithField("path", repoPath).
5353
Info("Updating operator")
@@ -68,7 +68,7 @@ func updateOperator(
6868
syncedRepo *repo.SyncedRepo,
6969
force bool,
7070
) (err error) {
71-
operatorName := fmt.Sprintf("%s-%s", operator.Name, version.Version)
71+
operatorName := fmt.Sprintf("%s-%s", operator.Name, version.Version())
7272

7373
resolver, err := getResolver(operator, version)
7474
if err != nil {
@@ -102,13 +102,13 @@ func updateOperator(
102102
}
103103

104104
log.WithField("operator", operator.Name).
105-
WithField("version", version.Version).
105+
WithField("version", version.Version()).
106106
WithField("repository", syncedRepo.URL).
107107
WithField("tarball", pkgName).
108108
Info("Added operator to the repository")
109109
} else {
110110
log.WithField("operator", operator.Name).
111-
WithField("version", version.Version).
111+
WithField("version", version.Version()).
112112
WithField("repository", syncedRepo.URL).
113113
Info("Operator is already in the repository")
114114
}

0 commit comments

Comments
 (0)