Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 4bdb561

Browse files
Adjust updateURLNodeImages function
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
1 parent 6bb32f9 commit 4bdb561

File tree

3,013 files changed

+32
-880694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,013 files changed

+32
-880694
lines changed

go.mod

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,39 @@ go 1.21
55
require (
66
github.com/SovereignCloudStack/csctl v0.0.2
77
github.com/minio/minio-go/v7 v7.0.69
8-
github.com/sovereignCloudStack/cluster-stack-provider-openstack v0.1.0-alpha.rc1
98
gopkg.in/yaml.v2 v2.4.0
109
)
1110

1211
require (
1312
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.3 // indirect
14-
github.com/beorn7/perks v1.0.1 // indirect
15-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
1613
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1714
github.com/dustin/go-humanize v1.0.1 // indirect
18-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
1915
github.com/emirpasic/gods v1.12.0 // indirect
20-
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
21-
github.com/fsnotify/fsnotify v1.7.0 // indirect
22-
github.com/go-logr/logr v1.3.0 // indirect
23-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
24-
github.com/go-openapi/jsonreference v0.20.2 // indirect
25-
github.com/go-openapi/swag v0.22.3 // indirect
26-
github.com/gogo/protobuf v1.3.2 // indirect
27-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
28-
github.com/golang/protobuf v1.5.3 // indirect
29-
github.com/google/gnostic-models v0.6.8 // indirect
30-
github.com/google/go-cmp v0.6.0 // indirect
31-
github.com/google/gofuzz v1.2.0 // indirect
3216
github.com/google/uuid v1.6.0 // indirect
33-
github.com/gophercloud/gophercloud v1.7.0 // indirect
34-
github.com/imdario/mergo v0.3.15 // indirect
3517
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
36-
github.com/josharian/intern v1.0.0 // indirect
3718
github.com/json-iterator/go v1.1.12 // indirect
3819
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
3920
github.com/klauspost/compress v1.17.6 // indirect
4021
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
41-
github.com/mailru/easyjson v0.7.7 // indirect
42-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
22+
github.com/kr/pretty v0.3.1 // indirect
4323
github.com/minio/md5-simd v1.1.2 // indirect
4424
github.com/minio/sha256-simd v1.0.1 // indirect
4525
github.com/mitchellh/go-homedir v1.1.0 // indirect
4626
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4727
github.com/modern-go/reflect2 v1.0.2 // indirect
48-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
49-
github.com/pkg/errors v0.9.1 // indirect
50-
github.com/prometheus/client_golang v1.17.0 // indirect
51-
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
52-
github.com/prometheus/common v0.44.0 // indirect
53-
github.com/prometheus/procfs v0.11.1 // indirect
5428
github.com/rs/xid v1.5.0 // indirect
5529
github.com/sergi/go-diff v1.1.0 // indirect
56-
github.com/spf13/pflag v1.0.5 // indirect
5730
github.com/src-d/gcfg v1.4.0 // indirect
5831
github.com/xanzy/ssh-agent v0.2.1 // indirect
5932
golang.org/x/crypto v0.19.0 // indirect
60-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
6133
golang.org/x/mod v0.15.0 // indirect
6234
golang.org/x/net v0.21.0 // indirect
63-
golang.org/x/oauth2 v0.17.0 // indirect
6435
golang.org/x/sys v0.17.0 // indirect
65-
golang.org/x/term v0.17.0 // indirect
6636
golang.org/x/text v0.14.0 // indirect
67-
golang.org/x/time v0.3.0 // indirect
68-
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
69-
google.golang.org/appengine v1.6.7 // indirect
70-
google.golang.org/protobuf v1.31.0 // indirect
71-
gopkg.in/inf.v0 v0.9.1 // indirect
37+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
7238
gopkg.in/ini.v1 v1.67.0 // indirect
7339
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
7440
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
7541
gopkg.in/warnings.v0 v0.1.2 // indirect
7642
gopkg.in/yaml.v3 v3.0.1 // indirect
77-
k8s.io/api v0.29.0 // indirect
78-
k8s.io/apiextensions-apiserver v0.29.0 // indirect
79-
k8s.io/apimachinery v0.29.0 // indirect
80-
k8s.io/client-go v0.29.0 // indirect
81-
k8s.io/component-base v0.29.0 // indirect
82-
k8s.io/klog/v2 v2.110.1 // indirect
83-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
84-
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
85-
sigs.k8s.io/cluster-api v1.6.0 // indirect
86-
sigs.k8s.io/cluster-api-provider-openstack v0.9.0 // indirect
87-
sigs.k8s.io/controller-runtime v0.16.3 // indirect
88-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
89-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
90-
sigs.k8s.io/yaml v1.4.0 // indirect
9143
)

go.sum

Lines changed: 2 additions & 158 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
csctlclusterstack "github.com/SovereignCloudStack/csctl/pkg/clusterstack"
2828
minio "github.com/minio/minio-go/v7"
2929
"github.com/minio/minio-go/v7/pkg/credentials"
30-
cspo "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
3130
"gopkg.in/yaml.v2"
3231
)
3332

@@ -42,16 +41,22 @@ type RegistryConfig struct {
4241
} `yaml:"config"`
4342
}
4443

45-
// OpenStackNodeImages represents the structure of the OpenStackNodeImages.
46-
type OpenStackNodeImages struct {
47-
cspo.OpenStackNodeImage
48-
ImageDir string `yaml:"imageDir,omitempty"`
44+
// OpenStackNodeImage represents the structure of the OpenStackNodeImage.
45+
type OpenStackNodeImage struct {
46+
URL string `yaml:"url"`
47+
ImageDir string `yaml:"imageDir,omitempty"`
48+
CreateOpts struct {
49+
Name string `yaml:"name"`
50+
DiskFormat string `yaml:"disk_format"` //nolint:tagliatelle // The `DiskFormat` field in this struct corresponds to the `disk_format` in https://pkg.go.dev/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images#CreateOpts
51+
ContainerFormat string `yaml:"container_format"` //nolint:tagliatelle // The `ContainerFormat` field in this struct corresponds to the `container_format` in https://pkg.go.dev/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images#CreateOpts
52+
Visibility string `yaml:"visibility"`
53+
} `yaml:"createOpts"`
4954
}
5055

5156
// NodeImages represents the structure of the config.yaml file.
5257
type NodeImages struct {
53-
APIVersion string `yaml:"apiVersion"`
54-
OpenStackNodeImages []OpenStackNodeImages `yaml:"openStackNodeImages"`
58+
APIVersion string `yaml:"apiVersion"`
59+
OpenStackNodeImages []OpenStackNodeImage `yaml:"openStackNodeImages"`
5560
}
5661

5762
const (
@@ -113,7 +118,7 @@ func main() {
113118
}
114119
fmt.Println("config.yaml copied to releaseDir as node-images.yaml successfully!")
115120
case "build":
116-
for _, image := range config.OpenStackNodeImages {
121+
for imageOrder, image := range config.OpenStackNodeImages {
117122
if image.ImageDir == "" {
118123
fmt.Printf("No images to build, image directory is not defined in config.yaml file")
119124
os.Exit(1)
@@ -161,7 +166,7 @@ func main() {
161166
}
162167

163168
// Update URL in config.yaml if it is necessary
164-
if err := updateURLNodeImages(configFilePath, registryConfigPath, image.ImageDir); err != nil {
169+
if err := updateURLNodeImages(configFilePath, registryConfigPath, image.ImageDir, imageOrder); err != nil {
165170
fmt.Printf("Error updating URL in config.yaml: %v\n", err)
166171
os.Exit(1)
167172
}
@@ -233,7 +238,7 @@ func pushToS3(filePath, fileName, registryConfigPath string) error {
233238
return nil
234239
}
235240

236-
func updateURLNodeImages(configFilePath, registryConfigPath, imageName string) error {
241+
func updateURLNodeImages(configFilePath, registryConfigPath, imageName string, imageOrder int) error {
237242
// Read the config.yaml file
238243
// #nosec G304
239244
nodeImageData, err := os.ReadFile(configFilePath)
@@ -248,13 +253,8 @@ func updateURLNodeImages(configFilePath, registryConfigPath, imageName string) e
248253
}
249254

250255
// Check if the URL already exists for the given image
251-
var imageURLExists bool
252-
for _, image := range nodeImages.OpenStackNodeImages {
253-
if image.URL != "" {
254-
imageURLExists = true
255-
break
256-
}
257-
}
256+
imageURLExists := nodeImages.OpenStackNodeImages[imageOrder].URL != ""
257+
258258
// If the URL doesn't exist, update it for the image
259259
if !imageURLExists {
260260
// Load registry configuration from YAML file
@@ -272,10 +272,9 @@ func updateURLNodeImages(configFilePath, registryConfigPath, imageName string) e
272272
}
273273
// Generate URL
274274
newURL := fmt.Sprintf("%s%s/%s/%s", "https://", registryConfig.Config.Endpoint, registryConfig.Config.Bucket, imageName)
275-
for i := range nodeImages.OpenStackNodeImages {
276-
nodeImages.OpenStackNodeImages[i].URL = newURL
277-
break
278-
}
275+
276+
// Assign the generated URL to the correct node-image
277+
nodeImages.OpenStackNodeImages[imageOrder].URL = newURL
279278

280279
// Marshal the updated struct back to YAML
281280
updatedNodeImageData, err := yaml.Marshal(&nodeImages)
@@ -332,7 +331,12 @@ func GetConfig(configPath string) (NodeImages, error) {
332331
// Ensure all fields in OpenStackNodeImages are defined
333332
for _, image := range nd.OpenStackNodeImages {
334333
switch {
335-
case image.CreateOpts == nil:
334+
case image.CreateOpts == (struct {
335+
Name string `yaml:"name"`
336+
DiskFormat string `yaml:"disk_format"` //nolint:tagliatelle // The `DiskFormat` field in this struct corresponds to the `disk_format` in https://pkg.go.dev/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images#CreateOpts
337+
ContainerFormat string `yaml:"container_format"` //nolint:tagliatelle // The `ContainerFormat` field in this struct corresponds to the `container_format` in https://pkg.go.dev/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images#CreateOpts
338+
Visibility string `yaml:"visibility"`
339+
}{}):
336340
return NodeImages{}, fmt.Errorf("field CreateOpts must not be empty")
337341
case image.CreateOpts.Name == "":
338342
return NodeImages{}, fmt.Errorf("field 'name' in CreateOpts must be defined")

vendor/github.com/beorn7/perks/LICENSE

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)