9
9
"github.com/operator-framework/deppy/pkg/deppy"
10
10
"github.com/operator-framework/deppy/pkg/deppy/input"
11
11
"github.com/operator-framework/operator-registry/alpha/declcfg"
12
- "github.com/operator-framework/operator-registry/alpha/model"
13
12
"github.com/operator-framework/operator-registry/alpha/property"
14
13
"sigs.k8s.io/controller-runtime/pkg/client"
15
14
@@ -81,12 +80,12 @@ func getEntities(ctx context.Context, cl client.Client) (input.EntityList, error
81
80
return nil , err
82
81
}
83
82
for _ , catalog := range catalogList .Items {
84
- model , err := fetchCatalogModel (ctx , cl , catalog .Name )
83
+ channels , bundles , err := fetchMetadata (ctx , cl , catalog .Name )
85
84
if err != nil {
86
85
return nil , err
87
86
}
88
87
89
- catalogEntitiesList , err := ModelToEntities ( model , catalog .Name )
88
+ catalogEntitiesList , err := MetadataToEntities ( catalog .Name , channels , bundles )
90
89
if err != nil {
91
90
return nil , err
92
91
}
@@ -97,31 +96,71 @@ func getEntities(ctx context.Context, cl client.Client) (input.EntityList, error
97
96
return allEntitiesList , nil
98
97
}
99
98
100
- func fetchCatalogModel (ctx context.Context , cl client.Client , catalogName string ) (model.Model , error ) {
101
- packages , err := fetch [declcfg.Package ](ctx , cl , declcfg .SchemaPackage , catalogName )
102
- if err != nil {
103
- return nil , err
99
+ func MetadataToEntities (catalogName string , channels []declcfg.Channel , bundles []declcfg.Bundle ) (input.EntityList , error ) {
100
+ entityList := input.EntityList {}
101
+
102
+ bundlesMap := map [string ]* declcfg.Bundle {}
103
+ for i := range bundles {
104
+ bundlesMap [bundles [i ].Name ] = & bundles [i ]
105
+ }
106
+
107
+ for _ , ch := range channels {
108
+ for _ , chEntry := range ch .Entries {
109
+ bundle , ok := bundlesMap [chEntry .Name ]
110
+ if ! ok {
111
+ return nil , fmt .Errorf ("package %s channel %s contains a bundle %s, but it does not exist" , ch .Package , ch .Name , chEntry .Name )
112
+ }
113
+
114
+ props := map [string ]string {}
115
+
116
+ for _ , prop := range bundle .Properties {
117
+ switch prop .Type {
118
+ case property .TypePackage :
119
+ // this is already a json marshalled object, so it doesn't need to be marshalled
120
+ // like the other ones
121
+ props [property .TypePackage ] = string (prop .Value )
122
+ case entities .PropertyBundleMediaType :
123
+ props [entities .PropertyBundleMediaType ] = string (prop .Value )
124
+ }
125
+ }
126
+
127
+ imgValue , err := json .Marshal (bundle .Image )
128
+ if err != nil {
129
+ return nil , err
130
+ }
131
+ props [entities .PropertyBundlePath ] = string (imgValue )
132
+
133
+ channelValue , _ := json .Marshal (property.Channel {ChannelName : ch .Name , Priority : 0 })
134
+ props [property .TypeChannel ] = string (channelValue )
135
+ replacesValue , _ := json .Marshal (entities.ChannelEntry {
136
+ Name : bundle .Name ,
137
+ Replaces : chEntry .Replaces ,
138
+ })
139
+ props [entities .PropertyBundleChannelEntry ] = string (replacesValue )
140
+
141
+ catalogScopedEntryName := fmt .Sprintf ("%s-%s" , catalogName , bundle .Name )
142
+ entity := input.Entity {
143
+ ID : deppy .IdentifierFromString (fmt .Sprintf ("%s%s%s" , catalogScopedEntryName , bundle .Package , ch .Name )),
144
+ Properties : props ,
145
+ }
146
+ entityList = append (entityList , entity )
147
+ }
104
148
}
149
+
150
+ return entityList , nil
151
+ }
152
+
153
+ func fetchMetadata (ctx context.Context , cl client.Client , catalogName string ) ([]declcfg.Channel , []declcfg.Bundle , error ) {
105
154
channels , err := fetch [declcfg.Channel ](ctx , cl , declcfg .SchemaChannel , catalogName )
106
155
if err != nil {
107
- return nil , err
156
+ return nil , nil , err
108
157
}
109
158
bundles , err := fetch [declcfg.Bundle ](ctx , cl , declcfg .SchemaBundle , catalogName )
110
159
if err != nil {
111
- return nil , err
112
- }
113
-
114
- cfg := & declcfg.DeclarativeConfig {
115
- Packages : packages ,
116
- Channels : channels ,
117
- Bundles : bundles ,
118
- }
119
- model , err := declcfg .ConvertToModel (* cfg )
120
- if err != nil {
121
- return nil , err
160
+ return nil , nil , err
122
161
}
123
162
124
- return model , nil
163
+ return channels , bundles , nil
125
164
}
126
165
127
166
type declcfgSchemas interface {
@@ -147,49 +186,3 @@ func fetch[T declcfgSchemas](ctx context.Context, cl client.Client, schema, cata
147
186
148
187
return contents , nil
149
188
}
150
-
151
- func ModelToEntities (model model.Model , catalogName string ) (input.EntityList , error ) {
152
- entityList := input.EntityList {}
153
-
154
- for _ , pkg := range model {
155
- for _ , ch := range pkg .Channels {
156
- for _ , bundle := range ch .Bundles {
157
- props := map [string ]string {}
158
-
159
- for _ , prop := range bundle .Properties {
160
- switch prop .Type {
161
- case property .TypePackage :
162
- // this is already a json marshalled object, so it doesn't need to be marshalled
163
- // like the other ones
164
- props [property .TypePackage ] = string (prop .Value )
165
- case entities .PropertyBundleMediaType :
166
- props [entities .PropertyBundleMediaType ] = string (prop .Value )
167
- }
168
- }
169
-
170
- imgValue , err := json .Marshal (bundle .Image )
171
- if err != nil {
172
- return nil , err
173
- }
174
- props [entities .PropertyBundlePath ] = string (imgValue )
175
-
176
- channelValue , _ := json .Marshal (property.Channel {ChannelName : ch .Name , Priority : 0 })
177
- props [property .TypeChannel ] = string (channelValue )
178
- replacesValue , _ := json .Marshal (entities.ChannelEntry {
179
- Name : bundle .Name ,
180
- Replaces : bundle .Replaces ,
181
- })
182
- props [entities .PropertyBundleChannelEntry ] = string (replacesValue )
183
-
184
- catalogScopedEntryName := fmt .Sprintf ("%s-%s" , catalogName , bundle .Name )
185
- entity := input.Entity {
186
- ID : deppy .IdentifierFromString (fmt .Sprintf ("%s%s%s" , catalogScopedEntryName , bundle .Package .Name , ch .Name )),
187
- Properties : props ,
188
- }
189
- entityList = append (entityList , entity )
190
- }
191
- }
192
- }
193
-
194
- return entityList , nil
195
- }
0 commit comments