Skip to content

Commit

Permalink
Use 'appVersion' and 'operatorVersion' in API (#7)
Browse files Browse the repository at this point in the history
This change reflects KUDO's version handling as described in KEP-19.

Signed-off-by: Jan Schlicht <[email protected]>
  • Loading branch information
Jan Schlicht authored Jul 17, 2020
1 parent 8d4b343 commit f7159b4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ Consider an operator that is developed in a Git repository. The actual operator
apiVersion: index.kudo.dev/v1alpha1
kind: Operator
name: MyOperator
git-sources:
- name: my-git-repository
url: https://github.com/example/myoperator.git
gitSources:
- name: my-git-repository
url: https://github.com/example/myoperator.git
versions:
- version: "1.0.0"
git:
source: my-git-repository
directory: operator
tag: "v1.0.0"
- version: "2.0.0"
git:
source: my-git-repository
directory: operator
tag: "v2.0.0"
- operatorVersion: "1.0.0"
git:
source: my-git-repository
directory: operator
tag: "v1.0.0"
- operatorVersion: "2.0.0"
git:
source: my-git-repository
directory: operator
tag: "v2.0.0"
```
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.
8 changes: 6 additions & 2 deletions pkg/apis/operator/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Operator struct {
Name string `yaml:"name"`

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

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

// Version describes a version of a KUDO operator.
type Version struct {
Version string `yaml:"version"`
// OperatorVersion of the KUDO operator.
OperatorVersion string `yaml:"operatorVersion"`

// AppVersion of the KUDO operator, optional.
AppVersion string `yaml:"appVersion,omitempty"`

// Git specifies a version as a directory in a Git repository with a
// specific tag.
Expand Down
5 changes: 3 additions & 2 deletions pkg/internal/apis/operator/encode/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func convertV1Alpha1GitSource(in v1alpha1.GitSource) operator.GitSource {

func convertV1Alpha1Version(in v1alpha1.Version) operator.Version {
out := operator.Version{
Version: in.Version,
URL: in.URL,
OperatorVersion: in.OperatorVersion,
AppVersion: in.AppVersion,
URL: in.URL,
}

if in.Git != nil {
Expand Down
18 changes: 17 additions & 1 deletion pkg/internal/apis/operator/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package operator

import "fmt"

// Operator describes the location of a KUDO operator.
type Operator struct {
// Name of the operator.
Expand All @@ -23,7 +25,11 @@ type GitSource struct {

// Version describes a version of a KUDO operator.
type Version struct {
Version string
// OperatorVersion of the KUDO operator.
OperatorVersion string

// AppVersion of the KUDO operator, optional.
AppVersion string

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

// Version prints the version as a combination of appVersion and operatorVersion
// as described in KEP-19.
func (v Version) Version() string {
if v.AppVersion != "" {
return fmt.Sprintf("%s_%s", v.AppVersion, v.OperatorVersion)
}

return v.OperatorVersion
}

// Git references a specific tag of a Git repository of a KUDO operator.
type Git struct {
// Source references a 'GitSource' name. The source's Git repository is
Expand Down
8 changes: 4 additions & 4 deletions pkg/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Update(
for _, operator := range operators {
for _, version := range operator.Versions {
log.WithField("operator", operator.Name).
WithField("version", version.Version).
WithField("version", version.Version()).
WithField("repository", repoURL).
WithField("path", repoPath).
Info("Updating operator")
Expand All @@ -68,7 +68,7 @@ func updateOperator(
syncedRepo *repo.SyncedRepo,
force bool,
) (err error) {
operatorName := fmt.Sprintf("%s-%s", operator.Name, version.Version)
operatorName := fmt.Sprintf("%s-%s", operator.Name, version.Version())

resolver, err := getResolver(operator, version)
if err != nil {
Expand Down Expand Up @@ -102,13 +102,13 @@ func updateOperator(
}

log.WithField("operator", operator.Name).
WithField("version", version.Version).
WithField("version", version.Version()).
WithField("repository", syncedRepo.URL).
WithField("tarball", pkgName).
Info("Added operator to the repository")
} else {
log.WithField("operator", operator.Name).
WithField("version", version.Version).
WithField("version", version.Version()).
WithField("repository", syncedRepo.URL).
Info("Operator is already in the repository")
}
Expand Down

0 comments on commit f7159b4

Please sign in to comment.