Skip to content

Commit 2e7398e

Browse files
Add optional node-image-registry-path flag
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
1 parent abf0d67 commit 2e7398e

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

example/cluster-stacks/openstack/ferrol/csctl.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ config:
77
apiVersion: openstack.csctl.clusterstack.x-k8s.io/v1alpha1
88
config:
99
method: get
10-
# method: build
11-
# images:
12-
# - control-plane-ubuntu-2204
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
apiVersion: openstack.infrastructure.clusterstack.x-k8s.io/v1alpha1
22
openStackNodeImages:
3-
- url: https://swift.services.a.regiocloud.tech/swift/v1/AUTH_b182637428444b9aa302bb8d5a5a418c/openstack-k8s-capi-images/ubuntu-2204-kube-v1.27/ubuntu-2204-kube-v1.27.8.qcow2
4-
# imageDir: <image-directory-in-node-images-folder> # define only if you choose the build method
5-
createOpts:
6-
name: ubuntu-capi-image-v1.27.8
7-
disk_format: qcow2
8-
container_format: bare
9-
visibility: shared
3+
- url: https://api.gx-scs.sovereignit.cloud:8080/test-bucket/control-plane-ubuntu-2204
4+
imageDir: control-plane-ubuntu-2204
5+
createOpts:
6+
name: ubuntu-capi-image-v1.27.8
7+
disk_format: qcow2
8+
container_format: bare
9+
visibility: shared
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type: S3
22
config:
3-
endpoint: <endpoint>
4-
bucket: <bucket_name>
5-
accessKey: <access_key>
6-
secretKey: <secret_key>
3+
endpoint: api.gx-scs.sovereignit.cloud:8080
4+
bucket: test-bucket
5+
accessKey: 83350aaa6a20428a8f0b247b4602fd47
6+
secretKey: 6291ec05a3884e4d8ffabaf9eead767b

main.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ const (
6666
)
6767

6868
func 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]
7070
This command is a csctl plugin.
7171
https://github.com/SovereignCloudStack/csctl
7272
`, os.Args[0])
7373
}
7474

7575
func 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

Comments
 (0)