github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/package-server/apis/operators/v1/packagemanifest.go (about) 1 package v1 2 3 import ( 4 "encoding/json" 5 6 opregistry "github.com/operator-framework/operator-registry/pkg/registry" 7 8 operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" 9 ) 10 11 const ( 12 // The yaml attribute that specifies the related images of the ClusterServiceVersion 13 relatedImages = "relatedImages" 14 ) 15 16 // CreateCSVDescription creates a CSVDescription from a given CSV 17 func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion, csvJSON string) CSVDescription { 18 desc := CSVDescription{ 19 DisplayName: csv.Spec.DisplayName, 20 Version: csv.Spec.Version, 21 Provider: AppLink{ 22 Name: csv.Spec.Provider.Name, 23 URL: csv.Spec.Provider.URL, 24 }, 25 Annotations: csv.GetAnnotations(), 26 LongDescription: csv.Spec.Description, 27 InstallModes: csv.Spec.InstallModes, 28 CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions, 29 APIServiceDefinitions: csv.Spec.APIServiceDefinitions, 30 NativeAPIs: csv.Spec.NativeAPIs, 31 MinKubeVersion: csv.Spec.MinKubeVersion, 32 RelatedImages: GetImages(csvJSON), 33 Keywords: csv.Spec.Keywords, 34 Maturity: csv.Spec.Maturity, 35 } 36 37 icons := make([]Icon, len(csv.Spec.Icon)) 38 for i, icon := range csv.Spec.Icon { 39 icons[i] = Icon{ 40 Base64Data: icon.Data, 41 Mediatype: icon.MediaType, 42 } 43 } 44 45 if len(icons) > 0 { 46 desc.Icon = icons 47 } 48 49 desc.Links = make([]AppLink, len(csv.Spec.Links)) 50 for i, link := range csv.Spec.Links { 51 desc.Links[i] = AppLink{ 52 Name: link.Name, 53 URL: link.URL, 54 } 55 } 56 57 desc.Maintainers = make([]Maintainer, len(csv.Spec.Maintainers)) 58 for i, maintainer := range csv.Spec.Maintainers { 59 desc.Maintainers[i] = Maintainer{ 60 Name: maintainer.Name, 61 Email: maintainer.Email, 62 } 63 } 64 65 return desc 66 } 67 68 // GetImages returns a list of images listed in CSV (spec and deployments) 69 func GetImages(csvJSON string) []string { 70 var images []string 71 72 csv := &opregistry.ClusterServiceVersion{} 73 err := json.Unmarshal([]byte(csvJSON), &csv) 74 if err != nil { 75 return images 76 } 77 78 imageSet, err := csv.GetOperatorImages() 79 if err != nil { 80 return images 81 } 82 83 relatedImgSet, err := csv.GetRelatedImages() 84 if err != nil { 85 return images 86 } 87 88 for k := range relatedImgSet { 89 imageSet[k] = struct{}{} 90 } 91 92 for k := range imageSet { 93 images = append(images, k) 94 } 95 96 return images 97 }