Skip to content

Commit 41f8271

Browse files
Merge pull request #1552 from awgreene/pkg-svr-keywords
Bug 1821274: Add CSV Metadata to PackageManifests
2 parents 0326066 + 59f7749 commit 41f8271

File tree

11 files changed

+495
-30
lines changed

11 files changed

+495
-30
lines changed

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

Lines changed: 64 additions & 2 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,6 +32,11 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
2232
Owned: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Owned),
2333
Required: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Required),
2434
},
35+
Keywords: csv.Spec.Keywords,
36+
Maturity: csv.Spec.Maturity,
37+
NativeAPIs: csv.Spec.NativeAPIs,
38+
MinKubeVersion: csv.Spec.MinKubeVersion,
39+
RelatedImages: GetImages(csvJSON),
2540
}
2641

2742
icons := make([]Icon, len(csv.Spec.Icon))
@@ -36,6 +51,22 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
3651
desc.Icon = icons
3752
}
3853

54+
desc.Links = make([]AppLink, len(csv.Spec.Links))
55+
for i, link := range csv.Spec.Links {
56+
desc.Links[i] = AppLink{
57+
Name: link.Name,
58+
URL: link.URL,
59+
}
60+
}
61+
62+
desc.Maintainers = make([]Maintainer, len(csv.Spec.Maintainers))
63+
for i, maintainer := range csv.Spec.Maintainers {
64+
desc.Maintainers[i] = Maintainer{
65+
Name: maintainer.Name,
66+
Email: maintainer.Email,
67+
}
68+
}
69+
3970
return desc
4071
}
4172

@@ -69,3 +100,34 @@ func descriptionsForAPIServices(apis []operatorsv1alpha1.APIServiceDescription)
69100
}
70101
return descriptions
71102
}
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ type CSVDescription struct {
9696
// Provider is the CSV's provider
9797
Provider AppLink
9898
Annotations map[string]string
99+
Keywords []string
100+
Links []AppLink
101+
Maintainers []Maintainer
102+
Maturity string
99103

100104
// LongDescription is the CSV's description
101105
LongDescription string
@@ -105,6 +109,13 @@ type CSVDescription struct {
105109

106110
CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions
107111
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"`
108119
}
109120

110121
// AppLink defines a link to an application
@@ -113,6 +124,12 @@ type AppLink struct {
113124
URL string
114125
}
115126

127+
// Maintainer defines a project maintainer
128+
type Maintainer struct {
129+
Name string `json:"name,omitempty"`
130+
Email string `json:"email,omitempty"`
131+
}
132+
116133
// Icon defines a base64 encoded icon and media type
117134
type Icon struct {
118135
Base64Data string

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

Lines changed: 64 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,
@@ -16,6 +26,11 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
1626
InstallModes: csv.Spec.InstallModes,
1727
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
1828
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
29+
Keywords: csv.Spec.Keywords,
30+
Maturity: csv.Spec.Maturity,
31+
NativeAPIs: csv.Spec.NativeAPIs,
32+
MinKubeVersion: csv.Spec.MinKubeVersion,
33+
RelatedImages: GetImages(csvJSON),
1934
}
2035

2136
icons := make([]Icon, len(csv.Spec.Icon))
@@ -30,5 +45,52 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
3045
desc.Icon = icons
3146
}
3247

48+
desc.Links = make([]AppLink, len(csv.Spec.Links))
49+
for i, link := range csv.Spec.Links {
50+
desc.Links[i] = AppLink{
51+
Name: link.Name,
52+
URL: link.URL,
53+
}
54+
}
55+
56+
desc.Maintainers = make([]Maintainer, len(csv.Spec.Maintainers))
57+
for i, maintainer := range csv.Spec.Maintainers {
58+
desc.Maintainers[i] = Maintainer{
59+
Name: maintainer.Name,
60+
Email: maintainer.Email,
61+
}
62+
}
63+
3364
return desc
3465
}
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ type CSVDescription struct {
9696
// Provider is the CSV's provider
9797
Provider AppLink `json:"provider,omitempty"`
9898
Annotations map[string]string `json:"annotations,omitempty"`
99+
// +listType=set
100+
Keywords []string `json:"keywords,omitempty"`
101+
// +listType=set
102+
Links []AppLink `json:"links,omitempty"`
103+
// +listType=set
104+
Maintainers []Maintainer `json:"maintainers,omitempty"`
105+
Maturity string `json:"maturity,omitempty"`
99106

100107
// LongDescription is the CSV's description
101108
LongDescription string `json:"description,omitempty"`
@@ -105,6 +112,13 @@ type CSVDescription struct {
105112

106113
CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
107114
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"`
108122
}
109123

110124
// AppLink defines a link to an application
@@ -113,6 +127,12 @@ type AppLink struct {
113127
URL string `json:"url,omitempty"`
114128
}
115129

130+
// Maintainer defines a project maintainer
131+
type Maintainer struct {
132+
Name string `json:"name,omitempty"`
133+
Email string `json:"email,omitempty"`
134+
}
135+
116136
// Icon defines a base64 encoded icon and media type
117137
type Icon struct {
118138
Base64Data string `json:"base64data,omitempty"`

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

Lines changed: 47 additions & 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)