6
6
"io/fs"
7
7
"log"
8
8
"os"
9
+ "strings"
9
10
10
11
"github.com/google/go-containerregistry/pkg/crane"
11
12
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -29,7 +30,7 @@ func main() {
29
30
pflag .CommandLine .AddGoFlagSet (flag .CommandLine )
30
31
pflag .Parse ()
31
32
32
- log .Printf ("registry configured with path %s, listening on %s" , imagesPath , registryAddr )
33
+ log .Printf ("push operation configured with images path %s and destination %s" , imagesPath , registryAddr )
33
34
34
35
bundlesFullPath := fmt .Sprintf ("%s/%s" , imagesPath , bundlesSubPath )
35
36
catalogsFullPath := fmt .Sprintf ("%s/%s" , imagesPath , catalogsSubPath )
@@ -42,16 +43,14 @@ func main() {
42
43
if err != nil {
43
44
log .Fatalf ("failed to build catalogs: %s" , err .Error ())
44
45
}
45
-
46
46
// Push the images
47
- // TODO without insecure option
48
47
for name , image := range bundles {
49
- if err := crane .Push (image , fmt .Sprintf ("%s/%s" , registryAddr , name ), crane . Insecure ); err != nil {
48
+ if err := crane .Push (image , fmt .Sprintf ("%s/%s" , registryAddr , name )); err != nil {
50
49
log .Fatalf ("failed to push bundle images: %s" , err .Error ())
51
50
}
52
51
}
53
52
for name , image := range catalogs {
54
- if err := crane .Push (image , fmt .Sprintf ("%s/%s" , registryAddr , name ), crane . Insecure ); err != nil {
53
+ if err := crane .Push (image , fmt .Sprintf ("%s/%s" , registryAddr , name )); err != nil {
55
54
log .Fatalf ("failed to push catalog images: %s" , err .Error ())
56
55
}
57
56
}
@@ -60,26 +59,25 @@ func main() {
60
59
}
61
60
62
61
func buildBundles (path string ) (map [string ]v1.Image , error ) {
63
- bundles , err := processImageDirTree (path , "bundles/registry-v1/" )
62
+ bundles , err := processImageDirTree (path )
64
63
if err != nil {
65
64
return nil , err
66
65
}
66
+ mutatedMap := make (map [string ]v1.Image , 0 )
67
67
// Apply required bundle labels
68
68
for key , img := range bundles {
69
- //TODO
70
- labels , err := getBundleLabels (fmt .Sprintf ("%s/%s" , path , "prometheus-operator/v1.0.0/metadata/annotations.yaml" ))
69
+ // Replace ':' between image name and image tag for file path
70
+ metadataPath := strings .Replace (key , ":" , "/" , 1 )
71
+ labels , err := getBundleLabels (fmt .Sprintf ("%s/%s/%s" , path , metadataPath , "metadata/annotations.yaml" ))
71
72
if err != nil {
72
73
return nil , err
73
74
}
74
- cfg := v1.Config {
75
- Labels : labels ,
76
- }
77
- bundles [key ], err = mutate .Config (img , cfg )
75
+ mutatedMap [fmt .Sprintf ("bundles/registry-v1/%s" , key )], err = mutate .Config (img , v1.Config {Labels : labels })
78
76
if err != nil {
79
77
return nil , fmt .Errorf ("failed to apply image labels: %w" , err )
80
78
}
81
79
}
82
- return bundles , nil
80
+ return mutatedMap , nil
83
81
}
84
82
85
83
type bundleAnnotations struct {
@@ -100,26 +98,27 @@ func getBundleLabels(path string) (map[string]string, error) {
100
98
}
101
99
102
100
func buildCatalogs (path string ) (map [string ]v1.Image , error ) {
103
- catalogs , err := processImageDirTree (path , "e2e/" )
101
+ catalogs , err := processImageDirTree (path )
104
102
if err != nil {
105
103
return nil , err
106
104
}
105
+ mutatedMap := make (map [string ]v1.Image , 0 )
107
106
// Apply required catalog label
108
107
for key , img := range catalogs {
109
108
cfg := v1.Config {
110
109
Labels : map [string ]string {
111
110
"operators.operatorframework.io.index.configs.v1" : "/configs" ,
112
111
},
113
112
}
114
- catalogs [ key ], err = mutate .Config (img , cfg )
113
+ mutatedMap [ fmt . Sprintf ( "e2e/%s" , key ) ], err = mutate .Config (img , cfg )
115
114
if err != nil {
116
115
return nil , fmt .Errorf ("failed to apply image labels: %w" , err )
117
116
}
118
117
}
119
- return catalogs , nil
118
+ return mutatedMap , nil
120
119
}
121
120
122
- func processImageDirTree (path string , repoPrefix string ) (map [string ]v1.Image , error ) {
121
+ func processImageDirTree (path string ) (map [string ]v1.Image , error ) {
123
122
imageMap := make (map [string ]v1.Image , 0 )
124
123
images , err := os .ReadDir (path )
125
124
if err != nil {
@@ -153,7 +152,7 @@ func processImageDirTree(path string, repoPrefix string) (map[string]v1.Image, e
153
152
if err != nil {
154
153
return nil , fmt .Errorf ("failed to generate image: %w" , err )
155
154
}
156
- imageMap [fmt .Sprintf ("%s%s :%s" , repoPrefix , entry .Name (), tag .Name ())] = image
155
+ imageMap [fmt .Sprintf ("%s:%s" , entry .Name (), tag .Name ())] = image
157
156
}
158
157
}
159
158
return imageMap , nil
0 commit comments