Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions docs/how_to_use_csctl_plugin_openstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,36 @@ This method can be used when the creator of the cluster-stacks has already built

### Build method

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:
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:

```bash
https://<endpoint>/<bucket-name>/<image-dir-name>
```
- for an `S3` type registry:

```bash
<endpoint>/<bucket-name>/<image-dir-name>
```

- for a `Swift` type registry:

```bash
<endpoint>/swift/v1/AUTH_<project-ID>/<bucket-name>/<image-dir-name>
```

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

> [!NOTE]
> URL creation does not work for OpenStack Swift.
> If you want to use URL creation for OpenStack Swift registry, please change the `registry.yaml` file accordingly:

```yaml
type: Swift
config:
endpoint: <endpoint>
bucket: <bucket_name>
accessKey: <access_key>
secretKey: <secret_key>
projectID: <openstack_project_id>
# verify: false # Only if you want to disable SSL certificate verification and use `http` url in endpoint
# cacert: <path/to/cacert> # Use this field only if the S3 storage endpoint certificate is signed by a custom(non-public) authority
```

## Installing csctl plugin for OpenStack

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ config:
bucket: <bucket_name>
accessKey: <access_key>
secretKey: <secret_key>
# projectID: <openstack_project_id> # Needs to be specified when type is equal to Swift and URL is not set in config.yaml file
# verify: false # Only if you want to disable SSL certificate verification and use `http` url in endpoint
# cacert: <path/to/cacert> # Use this field only if the S3 storage endpoint certificate is signed by a custom(non-public) authority
20 changes: 16 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type RegistryConfig struct {
SecretKey string `yaml:"secretKey"`
Verify *bool `yaml:"verify,omitempty"`
Cacert string `yaml:"cacert,omitempty"`
ProjectID string `yaml:"projectID,omitempty"` //nolint:tagliatelle // using 'projectID' instead of 'projectId'
} `yaml:"config"`
}

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

if registryConfig.Type != "S3" {
return fmt.Errorf("error, only S3 compatible registry is supported")
if registryConfig.Type != "S3" && registryConfig.Type != "Swift" {
return fmt.Errorf("error, only S3 or Swift compatible registry is supported")
}

// Remove "http://" or "https://" from the endpoint if present cause Endpoint cannot have fully qualified paths in minioClient.
Expand Down Expand Up @@ -313,8 +314,19 @@ func updateURLNodeImages(configFilePath, registryConfigPath, imageName string, i
if err := decoder.Decode(&registryConfig); err != nil {
return fmt.Errorf("error decoding registry config file: %w", err)
}
// Generate URL
newURL := fmt.Sprintf("%s%s/%s/%s", "https://", registryConfig.Config.Endpoint, registryConfig.Config.Bucket, imageName)

// Check registry type and projectID for Swift
if registryConfig.Type == "Swift" && registryConfig.Config.ProjectID == "" {
return fmt.Errorf("error, projectID must be specified for Swift registry")
}

// Generate URL based on registry type
var newURL string
if registryConfig.Type == "S3" {
newURL = fmt.Sprintf("%s/%s/%s", registryConfig.Config.Endpoint, registryConfig.Config.Bucket, imageName)
} else if registryConfig.Type == "Swift" {
newURL = fmt.Sprintf("%s/swift/v1/AUTH_%s/%s/%s", registryConfig.Config.Endpoint, registryConfig.Config.ProjectID, registryConfig.Config.Bucket, imageName)
}

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