Skip to content

Commit 9966937

Browse files
committed
add Release version as an optional field in the CSV
Signed-off-by: grokspawn <jordan@nimblewidget.com>
1 parent e9c7bb5 commit 9966937

File tree

5 files changed

+82
-11
lines changed

5 files changed

+82
-11
lines changed

crds/operators.coreos.com_clusterserviceversions.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
jsonPath: .spec.version
2828
name: Version
2929
type: string
30+
- description: The release version of the CSV
31+
jsonPath: .spec.release
32+
name: Release
33+
type: string
3034
- description: The name of a CSV that this one replaces
3135
jsonPath: .spec.replaces
3236
name: Replaces
@@ -8988,6 +8992,8 @@ spec:
89888992
type: string
89898993
name:
89908994
type: string
8995+
release:
8996+
type: string
89918997
replaces:
89928998
description: The name of a CSV this one replaces. Should match the `metadata.Name` field of the old CSV.
89938999
type: string

crds/zz_defs.go

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/lib/release/release.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package release
2+
3+
import (
4+
"encoding/json"
5+
"strings"
6+
7+
semver "github.com/blang/semver/v4"
8+
)
9+
10+
// +k8s:openapi-gen=true
11+
// OperatorVersion is a wrapper around semver.Version which supports correct
12+
// marshaling to YAML and JSON.
13+
// +kubebuilder:validation:Type=string
14+
type OperatorRelease struct {
15+
Release []semver.PRVersion `json:"-"`
16+
}
17+
18+
// DeepCopyInto creates a deep-copy of the Version value.
19+
func (v *OperatorRelease) DeepCopyInto(out *OperatorRelease) {
20+
out.Release = make([]semver.PRVersion, len(v.Release))
21+
copy(out.Release, v.Release)
22+
}
23+
24+
// MarshalJSON implements the encoding/json.Marshaler interface.
25+
func (v OperatorRelease) MarshalJSON() ([]byte, error) {
26+
segments := []string{}
27+
for _, segment := range v.Release {
28+
segments = append(segments, segment.String())
29+
}
30+
return json.Marshal(strings.Join(segments, "."))
31+
}
32+
33+
// UnmarshalJSON implements the encoding/json.Unmarshaler interface.
34+
func (v *OperatorRelease) UnmarshalJSON(data []byte) (err error) {
35+
var versionString string
36+
37+
if err = json.Unmarshal(data, &versionString); err != nil {
38+
return
39+
}
40+
41+
segments := strings.Split(versionString, ".")
42+
for _, segment := range segments {
43+
release, err := semver.NewPRVersion(segment)
44+
if err != nil {
45+
return err
46+
}
47+
v.Release = append(v.Release, release)
48+
}
49+
50+
return nil
51+
}
52+
53+
// OpenAPISchemaType is used by the kube-openapi generator when constructing
54+
// the OpenAPI spec of this type.
55+
//
56+
// See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators
57+
func (_ OperatorRelease) OpenAPISchemaType() []string { return []string{"string"} }
58+
59+
// OpenAPISchemaFormat is used by the kube-openapi generator when constructing
60+
// the OpenAPI spec of this type.
61+
// "semver" is not a standard openapi format but tooling may use the value regardless
62+
func (_ OperatorRelease) OpenAPISchemaFormat() string { return "semver" }

pkg/operators/v1alpha1/clusterserviceversion_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/apimachinery/pkg/labels"
1414
"k8s.io/apimachinery/pkg/util/intstr"
1515

16+
"github.com/operator-framework/api/pkg/lib/release"
1617
"github.com/operator-framework/api/pkg/lib/version"
1718
)
1819

@@ -274,8 +275,10 @@ type APIServiceDefinitions struct {
274275
// that can manage apps for a given version.
275276
// +k8s:openapi-gen=true
276277
type ClusterServiceVersionSpec struct {
277-
InstallStrategy NamedInstallStrategy `json:"install"`
278-
Version version.OperatorVersion `json:"version,omitempty"`
278+
InstallStrategy NamedInstallStrategy `json:"install"`
279+
Version version.OperatorVersion `json:"version,omitempty"`
280+
// +optional
281+
Release release.OperatorRelease `json:"release,omitzero"`
279282
Maturity string `json:"maturity,omitempty"`
280283
CustomResourceDefinitions CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
281284
APIServiceDefinitions APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
@@ -595,6 +598,7 @@ type ResourceInstance struct {
595598
// +kubebuilder:subresource:status
596599
// +kubebuilder:printcolumn:name="Display",type=string,JSONPath=`.spec.displayName`,description="The name of the CSV"
597600
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.version`,description="The version of the CSV"
601+
// +kubebuilder:printcolumn:name="Release",type=string,JSONPath=`.spec.release`,description="The release version of the CSV"
598602
// +kubebuilder:printcolumn:name="Replaces",type=string,JSONPath=`.spec.replaces`,description="The name of a CSV that this one replaces"
599603
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
600604

pkg/operators/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)