@@ -66,16 +66,17 @@ const (
6666)
6767
6868func usage () {
69- fmt .Printf (`%s create-node-images cluster-stack-directory cluster-stack-release-directory
69+ fmt .Printf (`%s create-node-images cluster-stack-directory cluster-stack-release-directory [node-image-registry-path]
7070This command is a csctl plugin.
7171https://github.com/SovereignCloudStack/csctl
7272` , os .Args [0 ])
7373}
7474
7575func main () {
76- numArgs := 5
77- if len (os .Args ) != numArgs {
78- fmt .Printf ("Wrong number of arguments. Expected %d got %d\n " , numArgs , len (os .Args ))
76+ minArgs := 4
77+ maxArgs := 5
78+ if len (os .Args ) < minArgs || len (os .Args ) > maxArgs {
79+ fmt .Printf ("Wrong number of arguments. Expected %d or %d, got %d\n " , minArgs , maxArgs , len (os .Args ))
7980 usage ()
8081 os .Exit (1 )
8182 }
@@ -89,7 +90,7 @@ func main() {
8990 fmt .Println (err .Error ())
9091 os .Exit (1 )
9192 }
92- configFilePath := filepath .Join (clusterStackPath , "node-images" )
93+ configFilePath := filepath .Join (clusterStackPath , "node-images" , "config.yaml" )
9394 config , err := GetConfig (configFilePath )
9495 if err != nil {
9596 fmt .Println (err .Error ())
@@ -105,6 +106,8 @@ func main() {
105106 fmt .Println (err .Error ())
106107 os .Exit (1 )
107108 }
109+ registryConfigPath := os .Args [4 ]
110+
108111 method := csctlConfig .Config .Provider .Config ["method" ]
109112 switch method {
110113 case "get" :
@@ -142,8 +145,11 @@ func main() {
142145 fmt .Println ("Packer build completed successfully." )
143146
144147 // Todo: Use --node-image-registry flag to pass path to registry.yaml
145- registryConfigPath := filepath .Join (clusterStackPath , "node-images" , "registry.yaml" )
146-
148+ _ , err = os .Stat (registryConfigPath )
149+ if err != nil {
150+ fmt .Println (err .Error ())
151+ os .Exit (1 )
152+ }
147153 // Get the current working directory
148154 currentDir , err := os .Getwd ()
149155 if err != nil {
@@ -306,12 +312,11 @@ func copyFile(src, dest string) error {
306312 return nil
307313}
308314
309- // GetConfig returns CsctlConfig.
310- func GetConfig (path string ) (NodeImages , error ) {
311- configPath := filepath .Join (path , "config.yaml" )
315+ // GetConfig returns Config.
316+ func GetConfig (configPath string ) (NodeImages , error ) {
312317 configFileData , err := os .ReadFile (filepath .Clean (configPath ))
313318 if err != nil {
314- return NodeImages {}, fmt .Errorf ("failed to read csctl config: %w" , err )
319+ return NodeImages {}, fmt .Errorf ("failed to read config file : %w" , err )
315320 }
316321
317322 nd := NodeImages {}
0 commit comments