Skip to content

Commit acc40b5

Browse files
✨ Generate for URL for SWIFT (#29)
* Generate for URL for SWIFT Signed-off-by: michal.gubricky <[email protected]> * Update docs Signed-off-by: michal.gubricky <[email protected]> * Fix golint error Signed-off-by: michal.gubricky <[email protected]> * Update docs on how patterns for urls is generated Signed-off-by: michal.gubricky <[email protected]> * Update docs/how_to_use_csctl_plugin_openstack.md Co-authored-by: Roman Hros <[email protected]> Signed-off-by: Michal Gubricky <[email protected]> --------- Signed-off-by: michal.gubricky <[email protected]> Signed-off-by: Michal Gubricky <[email protected]> Co-authored-by: Roman Hros <[email protected]>
1 parent 7f536ac commit acc40b5

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

docs/how_to_use_csctl_plugin_openstack.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,36 @@ This method can be used when the creator of the cluster-stacks has already built
1919

2020
### Build method
2121

22-
The use case for this method is the opposite of the `Get` method. It means that the cluster-stack creator intends to use an image that has not yet been built. The plugin then builds image(s) based on Packer scripts in the `node-images` folder and pushes these image(s) to an S3 bucket. In this mode, you need to provide the path to your S3 storage credentials using the `--node-image-registry` flag, see [registry.yaml](../example/cluster-stacks/openstack/ferrol/node-images/registry.yaml). The URL does not need to be set in `config.yaml`, plugin can creates for you based on this pattern:
22+
The use case for this method is the opposite of the `Get` method. It means that the cluster-stack creator intends to use an image that has not yet been built. The plugin then builds image(s) based on Packer scripts in the `node-images` folder and pushes these image(s) to an S3 bucket. In this mode, you need to provide the path to your S3 storage credentials using the `--node-image-registry` flag, see [registry.yaml](../example/cluster-stacks/openstack/ferrol/node-images/registry.yaml). The URL does not need to be set in `config.yaml`. The plugin can create it for you based on the following patterns:
2323

24-
```bash
25-
https://<endpoint>/<bucket-name>/<image-dir-name>
26-
```
24+
- for an `S3` type registry:
25+
26+
```bash
27+
<endpoint>/<bucket-name>/<image-dir-name>
28+
```
29+
30+
- for a `Swift` type registry:
31+
32+
```bash
33+
<endpoint>/swift/v1/AUTH_<project-ID>/<bucket-name>/<image-dir-name>
34+
```
2735

2836
Be aware of that in this method you need to specify `imageDir` in `config.yaml` file.
2937

3038
> [!NOTE]
31-
> URL creation does not work for OpenStack Swift.
39+
> If you want to use URL creation for OpenStack Swift registry, please change the `registry.yaml` file accordingly:
40+
41+
```yaml
42+
type: Swift
43+
config:
44+
endpoint: <endpoint>
45+
bucket: <bucket_name>
46+
accessKey: <access_key>
47+
secretKey: <secret_key>
48+
projectID: <openstack_project_id>
49+
# verify: false # Only if you want to disable SSL certificate verification and use `http` url in endpoint
50+
# cacert: <path/to/cacert> # Use this field only if the S3 storage endpoint certificate is signed by a custom(non-public) authority
51+
```
3252

3353
## Installing csctl plugin for OpenStack
3454

example/cluster-stacks/openstack/ferrol/node-images/registry.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ config:
44
bucket: <bucket_name>
55
accessKey: <access_key>
66
secretKey: <secret_key>
7+
# projectID: <openstack_project_id> # Needs to be specified when type is equal to Swift and URL is not set in config.yaml file
78
# verify: false # Only if you want to disable SSL certificate verification and use `http` url in endpoint
89
# cacert: <path/to/cacert> # Use this field only if the S3 storage endpoint certificate is signed by a custom(non-public) authority

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type RegistryConfig struct {
4444
SecretKey string `yaml:"secretKey"`
4545
Verify *bool `yaml:"verify,omitempty"`
4646
Cacert string `yaml:"cacert,omitempty"`
47+
ProjectID string `yaml:"projectID,omitempty"` //nolint:tagliatelle // using 'projectID' instead of 'projectId'
4748
} `yaml:"config"`
4849
}
4950

@@ -211,8 +212,8 @@ func pushToS3(filePath, fileName, registryConfigPath string) error {
211212
return fmt.Errorf("error decoding registry config file: %w", err)
212213
}
213214

214-
if registryConfig.Type != "S3" {
215-
return fmt.Errorf("error, only S3 compatible registry is supported")
215+
if registryConfig.Type != "S3" && registryConfig.Type != "Swift" {
216+
return fmt.Errorf("error, only S3 or Swift compatible registry is supported")
216217
}
217218

218219
// Remove "http://" or "https://" from the endpoint if present cause Endpoint cannot have fully qualified paths in minioClient.
@@ -313,8 +314,19 @@ func updateURLNodeImages(configFilePath, registryConfigPath, imageName string, i
313314
if err := decoder.Decode(&registryConfig); err != nil {
314315
return fmt.Errorf("error decoding registry config file: %w", err)
315316
}
316-
// Generate URL
317-
newURL := fmt.Sprintf("%s%s/%s/%s", "https://", registryConfig.Config.Endpoint, registryConfig.Config.Bucket, imageName)
317+
318+
// Check registry type and projectID for Swift
319+
if registryConfig.Type == "Swift" && registryConfig.Config.ProjectID == "" {
320+
return fmt.Errorf("error, projectID must be specified for Swift registry")
321+
}
322+
323+
// Generate URL based on registry type
324+
var newURL string
325+
if registryConfig.Type == "S3" {
326+
newURL = fmt.Sprintf("%s/%s/%s", registryConfig.Config.Endpoint, registryConfig.Config.Bucket, imageName)
327+
} else if registryConfig.Type == "Swift" {
328+
newURL = fmt.Sprintf("%s/swift/v1/AUTH_%s/%s/%s", registryConfig.Config.Endpoint, registryConfig.Config.ProjectID, registryConfig.Config.Bucket, imageName)
329+
}
318330

319331
// Assign the generated URL to the correct node-image
320332
nodeImages.OpenStackNodeImages[imageOrder].URL = newURL

0 commit comments

Comments
 (0)