Skip to content

Commit 59f7749

Browse files
dinhxuanvuawgreene
authored andcommitted
Add more CSV information to the PackageManifest
Transfer `spec.relatedImages`, `spec.minKubeVersion`, and `spec.nativeAPIs` information from the CSV onto the packagemanifest response. CSVs are transformed from the in-bundle representation to the packagemanifest by selecting fields to display. Those additional fields will support the UI. Signed-off-by: Vu Dinh <[email protected]>
1 parent 0a33915 commit 59f7749

File tree

11 files changed

+234
-32
lines changed

11 files changed

+234
-32
lines changed

pkg/package-server/apis/operators/packagemanifest.go

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package operators
22

3-
import operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
3+
import (
4+
"encoding/json"
5+
6+
operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
7+
"github.com/operator-framework/operator-registry/pkg/registry"
8+
)
9+
10+
const (
11+
// The yaml attribute that specifies the related images of the ClusterServiceVersion
12+
relatedImages = "relatedImages"
13+
)
414

515
// CreateCSVDescription creates a CSVDescription from a given CSV
6-
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescription {
16+
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion, csvJSON string) CSVDescription {
717
desc := CSVDescription{
818
DisplayName: csv.Spec.DisplayName,
919
Version: csv.Spec.Version,
@@ -22,8 +32,11 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
2232
Owned: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Owned),
2333
Required: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Required),
2434
},
25-
Keywords: csv.Spec.Keywords,
26-
Maturity: csv.Spec.Maturity,
35+
Keywords: csv.Spec.Keywords,
36+
Maturity: csv.Spec.Maturity,
37+
NativeAPIs: csv.Spec.NativeAPIs,
38+
MinKubeVersion: csv.Spec.MinKubeVersion,
39+
RelatedImages: GetImages(csvJSON),
2740
}
2841

2942
icons := make([]Icon, len(csv.Spec.Icon))
@@ -87,3 +100,34 @@ func descriptionsForAPIServices(apis []operatorsv1alpha1.APIServiceDescription)
87100
}
88101
return descriptions
89102
}
103+
104+
// GetImages returns a list of images listed in CSV (spec and deployments)
105+
func GetImages(csvJSON string) []string {
106+
var images []string
107+
108+
csv := &registry.ClusterServiceVersion{}
109+
err := json.Unmarshal([]byte(csvJSON), &csv)
110+
if err != nil {
111+
return images
112+
}
113+
114+
imageSet, err := csv.GetOperatorImages()
115+
if err != nil {
116+
return images
117+
}
118+
119+
relatedImgSet, err := csv.GetRelatedImages()
120+
if err != nil {
121+
return images
122+
}
123+
124+
for k := range relatedImgSet {
125+
imageSet[k] = struct{}{}
126+
}
127+
128+
for k := range imageSet {
129+
images = append(images, k)
130+
}
131+
132+
return images
133+
}

pkg/package-server/apis/operators/packagemanifest_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ type CSVDescription struct {
109109

110110
CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions
111111
APIServiceDefinitions operatorv1alpha1.APIServiceDefinitions
112+
NativeAPIs []metav1.GroupVersionKind `json:"nativeApis,omitempty"`
113+
114+
// Minimum Kubernetes version for operator installation
115+
MinKubeVersion string `json:"minKubeVersion,omitempty"`
116+
117+
// List of related images
118+
RelatedImages []string `json:"relatedImages,omitempty"`
112119
}
113120

114121
// AppLink defines a link to an application

pkg/package-server/apis/operators/v1/packagemanifest.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package v1
22

3-
import operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
3+
import (
4+
"encoding/json"
5+
6+
operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
7+
"github.com/operator-framework/operator-registry/pkg/registry"
8+
)
9+
10+
const (
11+
// The yaml attribute that specifies the related images of the ClusterServiceVersion
12+
relatedImages = "relatedImages"
13+
)
414

515
// CreateCSVDescription creates a CSVDescription from a given CSV
6-
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescription {
16+
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion, csvJSON string) CSVDescription {
717
desc := CSVDescription{
818
DisplayName: csv.Spec.DisplayName,
919
Version: csv.Spec.Version,
@@ -18,6 +28,9 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
1828
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
1929
Keywords: csv.Spec.Keywords,
2030
Maturity: csv.Spec.Maturity,
31+
NativeAPIs: csv.Spec.NativeAPIs,
32+
MinKubeVersion: csv.Spec.MinKubeVersion,
33+
RelatedImages: GetImages(csvJSON),
2134
}
2235

2336
icons := make([]Icon, len(csv.Spec.Icon))
@@ -50,3 +63,34 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
5063

5164
return desc
5265
}
66+
67+
// GetImages returns a list of images listed in CSV (spec and deployments)
68+
func GetImages(csvJSON string) []string {
69+
var images []string
70+
71+
csv := &registry.ClusterServiceVersion{}
72+
err := json.Unmarshal([]byte(csvJSON), &csv)
73+
if err != nil {
74+
return images
75+
}
76+
77+
imageSet, err := csv.GetOperatorImages()
78+
if err != nil {
79+
return images
80+
}
81+
82+
relatedImgSet, err := csv.GetRelatedImages()
83+
if err != nil {
84+
return images
85+
}
86+
87+
for k := range relatedImgSet {
88+
imageSet[k] = struct{}{}
89+
}
90+
91+
for k := range imageSet {
92+
images = append(images, k)
93+
}
94+
95+
return images
96+
}

pkg/package-server/apis/operators/v1/packagemanifest_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ type CSVDescription struct {
112112

113113
CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
114114
APIServiceDefinitions operatorv1alpha1.APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
115+
NativeAPIs []metav1.GroupVersionKind `json:"nativeApis,omitempty"`
116+
117+
// Minimum Kubernetes version for operator installation
118+
MinKubeVersion string `json:"minKubeVersion,omitempty"`
119+
120+
// List of related images
121+
RelatedImages []string `json:"relatedImages,omitempty"`
115122
}
116123

117124
// AppLink defines a link to an application

pkg/package-server/apis/operators/v1/zz_generated.conversion.go

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

pkg/package-server/apis/operators/v1/zz_generated.deepcopy.go

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

pkg/package-server/apis/operators/zz_generated.deepcopy.go

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

pkg/package-server/client/openapi/zz_generated.openapi.go

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/package-server/provider/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func newPackageManifest(ctx context.Context, logger *logrus.Entry, pkg *api.Pack
503503
manifest.Status.Channels = append(manifest.Status.Channels, operators.PackageChannel{
504504
Name: pkgChannel.GetName(),
505505
CurrentCSV: csv.GetName(),
506-
CurrentCSVDesc: operators.CreateCSVDescription(&csv),
506+
CurrentCSVDesc: operators.CreateCSVDescription(&csv, bundle.GetCsvJson()),
507507
})
508508

509509
if manifest.Status.DefaultChannel != "" && pkgChannel.GetName() == manifest.Status.DefaultChannel || !providerSet {

0 commit comments

Comments
 (0)