66 "io/fs"
77 "log"
88 "os"
9+ "strings"
910
1011 "github.com/google/go-containerregistry/pkg/crane"
1112 v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -29,7 +30,7 @@ func main() {
2930 pflag .CommandLine .AddGoFlagSet (flag .CommandLine )
3031 pflag .Parse ()
3132
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 )
3334
3435 bundlesFullPath := fmt .Sprintf ("%s/%s" , imagesPath , bundlesSubPath )
3536 catalogsFullPath := fmt .Sprintf ("%s/%s" , imagesPath , catalogsSubPath )
@@ -42,16 +43,14 @@ func main() {
4243 if err != nil {
4344 log .Fatalf ("failed to build catalogs: %s" , err .Error ())
4445 }
45-
4646 // Push the images
47- // TODO without insecure option
4847 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 {
5049 log .Fatalf ("failed to push bundle images: %s" , err .Error ())
5150 }
5251 }
5352 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 {
5554 log .Fatalf ("failed to push catalog images: %s" , err .Error ())
5655 }
5756 }
@@ -60,26 +59,25 @@ func main() {
6059}
6160
6261func buildBundles (path string ) (map [string ]v1.Image , error ) {
63- bundles , err := processImageDirTree (path , "bundles/registry-v1/" )
62+ bundles , err := processImageDirTree (path )
6463 if err != nil {
6564 return nil , err
6665 }
66+ mutatedMap := make (map [string ]v1.Image , 0 )
6767 // Apply required bundle labels
6868 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" ))
7172 if err != nil {
7273 return nil , err
7374 }
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 })
7876 if err != nil {
7977 return nil , fmt .Errorf ("failed to apply image labels: %w" , err )
8078 }
8179 }
82- return bundles , nil
80+ return mutatedMap , nil
8381}
8482
8583type bundleAnnotations struct {
@@ -100,26 +98,27 @@ func getBundleLabels(path string) (map[string]string, error) {
10098}
10199
102100func buildCatalogs (path string ) (map [string ]v1.Image , error ) {
103- catalogs , err := processImageDirTree (path , "e2e/" )
101+ catalogs , err := processImageDirTree (path )
104102 if err != nil {
105103 return nil , err
106104 }
105+ mutatedMap := make (map [string ]v1.Image , 0 )
107106 // Apply required catalog label
108107 for key , img := range catalogs {
109108 cfg := v1.Config {
110109 Labels : map [string ]string {
111110 "operators.operatorframework.io.index.configs.v1" : "/configs" ,
112111 },
113112 }
114- catalogs [ key ], err = mutate .Config (img , cfg )
113+ mutatedMap [ fmt . Sprintf ( "e2e/%s" , key ) ], err = mutate .Config (img , cfg )
115114 if err != nil {
116115 return nil , fmt .Errorf ("failed to apply image labels: %w" , err )
117116 }
118117 }
119- return catalogs , nil
118+ return mutatedMap , nil
120119}
121120
122- func processImageDirTree (path string , repoPrefix string ) (map [string ]v1.Image , error ) {
121+ func processImageDirTree (path string ) (map [string ]v1.Image , error ) {
123122 imageMap := make (map [string ]v1.Image , 0 )
124123 images , err := os .ReadDir (path )
125124 if err != nil {
@@ -153,7 +152,7 @@ func processImageDirTree(path string, repoPrefix string) (map[string]v1.Image, e
153152 if err != nil {
154153 return nil , fmt .Errorf ("failed to generate image: %w" , err )
155154 }
156- imageMap [fmt .Sprintf ("%s%s :%s" , repoPrefix , entry .Name (), tag .Name ())] = image
155+ imageMap [fmt .Sprintf ("%s:%s" , entry .Name (), tag .Name ())] = image
157156 }
158157 }
159158 return imageMap , nil
0 commit comments