4
4
"encoding/json"
5
5
6
6
operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
7
+ "github.com/operator-framework/operator-registry/pkg/registry"
7
8
)
8
9
9
10
const (
@@ -12,7 +13,7 @@ const (
12
13
)
13
14
14
15
// CreateCSVDescription creates a CSVDescription from a given CSV
15
- func CreateCSVDescription (csv * operatorsv1alpha1.ClusterServiceVersion ) CSVDescription {
16
+ func CreateCSVDescription (csv * operatorsv1alpha1.ClusterServiceVersion , csvJSON string ) CSVDescription {
16
17
desc := CSVDescription {
17
18
DisplayName : csv .Spec .DisplayName ,
18
19
Version : csv .Spec .Version ,
@@ -27,7 +28,7 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
27
28
APIServiceDefinitions : csv .Spec .APIServiceDefinitions ,
28
29
NativeAPIs : csv .Spec .NativeAPIs ,
29
30
MinKubeVersion : csv .Spec .MinKubeVersion ,
30
- RelatedImages : GetImages (csv ),
31
+ RelatedImages : GetImages (csvJSON ),
31
32
}
32
33
33
34
icons := make ([]Icon , len (csv .Spec .Icon ))
@@ -45,65 +46,27 @@ func CreateCSVDescription(csv *operatorsv1alpha1.ClusterServiceVersion) CSVDescr
45
46
return desc
46
47
}
47
48
48
- // GetOperatorImages returns a list of images listed in Deployments
49
- func GetOperatorImages (csv * operatorsv1alpha1.ClusterServiceVersion ) map [string ]struct {} {
50
- imageSet := make (map [string ]struct {})
51
-
52
- for _ , deployment := range csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs {
53
- for _ , container := range deployment .Spec .Template .Spec .Containers {
54
- imageSet [container .Image ] = struct {}{}
55
- }
56
- for _ , initcont := range deployment .Spec .Template .Spec .InitContainers {
57
- imageSet [initcont .Image ] = struct {}{}
58
- }
59
- }
60
-
61
- return imageSet
62
- }
63
-
64
- // GetRelatedImages returns a list of related images listed in CSV spec
65
- func GetRelatedImages (csv * operatorsv1alpha1.ClusterServiceVersion ) map [string ]struct {} {
66
- var objMap map [string ]* json.RawMessage
67
- imageSet := make (map [string ]struct {})
49
+ // GetImages returns a list of images listed in CSV (spec and deployments)
50
+ func GetImages (csvJSON string ) []string {
51
+ var images []string
68
52
69
- csvJSON , err := json .Marshal (csv )
53
+ csv := & registry.ClusterServiceVersion {}
54
+ err := json .Unmarshal ([]byte (csvJSON ), & csv )
70
55
if err != nil {
71
- return imageSet
56
+ return images
72
57
}
73
58
74
- if err := json .Unmarshal (csvJSON , & objMap ); err != nil {
75
- return imageSet
76
- }
77
-
78
- rawValue , ok := objMap [relatedImages ]
79
- if ! ok || rawValue == nil {
80
- return imageSet
81
- }
82
-
83
- type relatedImage struct {
84
- Name string `json:"name"`
85
- Ref string `json:"image"`
86
- }
87
-
88
- var relatedImages []relatedImage
89
- if err = json .Unmarshal (* rawValue , & relatedImages ); err != nil {
90
- return imageSet
59
+ imageSet , err := csv .GetOperatorImages ()
60
+ if err != nil {
61
+ return images
91
62
}
92
63
93
- for _ , img := range relatedImages {
94
- imageSet [img .Ref ] = struct {}{}
64
+ relatedImgSet , err := csv .GetRelatedImages ()
65
+ if err != nil {
66
+ return images
95
67
}
96
68
97
- return imageSet
98
- }
99
-
100
- // GetImages returns a list of images listed in CSV (spec and deployments)
101
- func GetImages (csv * operatorsv1alpha1.ClusterServiceVersion ) []string {
102
- var images []string
103
-
104
- imageSet := GetOperatorImages (csv )
105
-
106
- for k := range GetRelatedImages (csv ) {
69
+ for k := range relatedImgSet {
107
70
imageSet [k ] = struct {}{}
108
71
}
109
72
0 commit comments