Skip to content

Bug 1821274: Add CSV Metadata to PackageManifests #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions pkg/package-server/apis/operators/packagemanifest.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package operators

import operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
import (
"encoding/json"

operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-registry/pkg/registry"
)

const (
// The yaml attribute that specifies the related images of the ClusterServiceVersion
relatedImages = "relatedImages"
)

// CreateCSVDescription creates a CSVDescription from a given CSV
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescription {
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion, csvJSON string) CSVDescription {
desc := CSVDescription{
DisplayName: csv.Spec.DisplayName,
Version: csv.Spec.Version,
Expand All @@ -22,6 +32,11 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
Owned: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Owned),
Required: descriptionsForAPIServices(csv.Spec.APIServiceDefinitions.Required),
},
Keywords: csv.Spec.Keywords,
Maturity: csv.Spec.Maturity,
NativeAPIs: csv.Spec.NativeAPIs,
MinKubeVersion: csv.Spec.MinKubeVersion,
RelatedImages: GetImages(csvJSON),
}

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

desc.Links = make([]AppLink, len(csv.Spec.Links))
for i, link := range csv.Spec.Links {
desc.Links[i] = AppLink{
Name: link.Name,
URL: link.URL,
}
}

desc.Maintainers = make([]Maintainer, len(csv.Spec.Maintainers))
for i, maintainer := range csv.Spec.Maintainers {
desc.Maintainers[i] = Maintainer{
Name: maintainer.Name,
Email: maintainer.Email,
}
}

return desc
}

Expand Down Expand Up @@ -69,3 +100,34 @@ func descriptionsForAPIServices(apis []operatorsv1alpha1.APIServiceDescription)
}
return descriptions
}

// GetImages returns a list of images listed in CSV (spec and deployments)
func GetImages(csvJSON string) []string {
var images []string

csv := &registry.ClusterServiceVersion{}
err := json.Unmarshal([]byte(csvJSON), &csv)
if err != nil {
return images
}

imageSet, err := csv.GetOperatorImages()
if err != nil {
return images
}

relatedImgSet, err := csv.GetRelatedImages()
if err != nil {
return images
}

for k := range relatedImgSet {
imageSet[k] = struct{}{}
}

for k := range imageSet {
images = append(images, k)
}

return images
}
17 changes: 17 additions & 0 deletions pkg/package-server/apis/operators/packagemanifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type CSVDescription struct {
// Provider is the CSV's provider
Provider AppLink
Annotations map[string]string
Keywords []string
Links []AppLink
Maintainers []Maintainer
Maturity string

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

CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions
APIServiceDefinitions operatorv1alpha1.APIServiceDefinitions
NativeAPIs []metav1.GroupVersionKind `json:"nativeApis,omitempty"`

// Minimum Kubernetes version for operator installation
MinKubeVersion string `json:"minKubeVersion,omitempty"`

// List of related images
RelatedImages []string `json:"relatedImages,omitempty"`
}

// AppLink defines a link to an application
Expand All @@ -113,6 +124,12 @@ type AppLink struct {
URL string
}

// Maintainer defines a project maintainer
type Maintainer struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
}

// Icon defines a base64 encoded icon and media type
type Icon struct {
Base64Data string
Expand Down
66 changes: 64 additions & 2 deletions pkg/package-server/apis/operators/v1/packagemanifest.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package v1

import operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
import (
"encoding/json"

operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-registry/pkg/registry"
)

const (
// The yaml attribute that specifies the related images of the ClusterServiceVersion
relatedImages = "relatedImages"
)

// CreateCSVDescription creates a CSVDescription from a given CSV
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescription {
func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion, csvJSON string) CSVDescription {
desc := CSVDescription{
DisplayName: csv.Spec.DisplayName,
Version: csv.Spec.Version,
Expand All @@ -16,6 +26,11 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
InstallModes: csv.Spec.InstallModes,
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
Keywords: csv.Spec.Keywords,
Maturity: csv.Spec.Maturity,
NativeAPIs: csv.Spec.NativeAPIs,
MinKubeVersion: csv.Spec.MinKubeVersion,
RelatedImages: GetImages(csvJSON),
}

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

desc.Links = make([]AppLink, len(csv.Spec.Links))
for i, link := range csv.Spec.Links {
desc.Links[i] = AppLink{
Name: link.Name,
URL: link.URL,
}
}

desc.Maintainers = make([]Maintainer, len(csv.Spec.Maintainers))
for i, maintainer := range csv.Spec.Maintainers {
desc.Maintainers[i] = Maintainer{
Name: maintainer.Name,
Email: maintainer.Email,
}
}

return desc
}

// GetImages returns a list of images listed in CSV (spec and deployments)
func GetImages(csvJSON string) []string {
var images []string

csv := &registry.ClusterServiceVersion{}
err := json.Unmarshal([]byte(csvJSON), &csv)
if err != nil {
return images
}

imageSet, err := csv.GetOperatorImages()
if err != nil {
return images
}

relatedImgSet, err := csv.GetRelatedImages()
if err != nil {
return images
}

for k := range relatedImgSet {
imageSet[k] = struct{}{}
}

for k := range imageSet {
images = append(images, k)
}

return images
}
20 changes: 20 additions & 0 deletions pkg/package-server/apis/operators/v1/packagemanifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ type CSVDescription struct {
// Provider is the CSV's provider
Provider AppLink `json:"provider,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
// +listType=set
Keywords []string `json:"keywords,omitempty"`
// +listType=set
Links []AppLink `json:"links,omitempty"`
// +listType=set
Maintainers []Maintainer `json:"maintainers,omitempty"`
Maturity string `json:"maturity,omitempty"`

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

CustomResourceDefinitions operatorv1alpha1.CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
APIServiceDefinitions operatorv1alpha1.APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
NativeAPIs []metav1.GroupVersionKind `json:"nativeApis,omitempty"`

// Minimum Kubernetes version for operator installation
MinKubeVersion string `json:"minKubeVersion,omitempty"`

// List of related images
RelatedImages []string `json:"relatedImages,omitempty"`
}

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

// Maintainer defines a project maintainer
type Maintainer struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
}

// Icon defines a base64 encoded icon and media type
type Icon struct {
Base64Data string `json:"base64data,omitempty"`
Expand Down
47 changes: 47 additions & 0 deletions pkg/package-server/apis/operators/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading