From 30f009e136eba1d8cc9db75e41b2b5b5cc03180e Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Thu, 27 Jun 2024 15:11:57 +0200 Subject: [PATCH] Create cloudrc contents in openstack-config-secret We are currently only creating the `clouds.yaml` and `secure.yaml` for the openstack client and not the classic `cloudrc` file that was usually sourced for individual clients. This makes sense if there were parity between the openstck client and all the individual clients, but there are still missing features. For example: - The `openstack volume service list` cannot show the cluster. - The `openstack volume service list` cannot show the backend state. - There is no support for any of the default volume type commands: set, show, list, unset. These are some of the ones we know about, but there could be more. Users will need to use the old `cinder` client, so we should make it convenient for them by having the `cloudrc` available in the `openstackclient` pod. This patch adds the `cloudrc` key in the `openstack-config-secret` secret to make it possible for the `openstack-operator` to mount it in the `openstackclient` pod. --- controllers/keystoneapi_controller.go | 2 ++ pkg/keystone/cloudconfig.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/controllers/keystoneapi_controller.go b/controllers/keystoneapi_controller.go index 49b8e58b..bd59b33b 100644 --- a/controllers/keystoneapi_controller.go +++ b/controllers/keystoneapi_controller.go @@ -1280,8 +1280,10 @@ func (r *KeystoneAPIReconciler) reconcileCloudConfig( if err != nil { return err } + cloudrc := keystone.GenerateCloudrc(&openStackConfigSecret, &openStackConfig) secretString := map[string]string{ "secure.yaml": string(secretVal), + "cloudrc": string(cloudrc), } secrets := []util.Template{ diff --git a/pkg/keystone/cloudconfig.go b/pkg/keystone/cloudconfig.go index d4b9534f..0ea21f47 100644 --- a/pkg/keystone/cloudconfig.go +++ b/pkg/keystone/cloudconfig.go @@ -16,6 +16,8 @@ limitations under the License. package keystone +import "fmt" + // OpenStackConfig type type OpenStackConfig struct { Clouds struct { @@ -42,3 +44,17 @@ type OpenStackConfigSecret struct { } } } + +// generateCloudrc - generate file contents of a cloudrc file for the clients +// until there is parity with openstackclient. +func GenerateCloudrc(secret *OpenStackConfigSecret, config *OpenStackConfig) string { + auth := config.Clouds.Default.Auth + val := fmt.Sprintf( + "export OS_AUTH_URL=" + auth.AuthURL + + "\nexport OS_USERNAME=" + auth.UserName + + "\nexport OS_PROJECT_NAME=" + auth.ProjectName + + "\nexport OS_PROJECT_DOMAIN_NAME=" + auth.ProjectDomainName + + "\nexport OS_USER_DOMAIN_NAME=" + auth.UserDomainName + + "\nexport OS_PASSWORD=" + secret.Clouds.Default.Auth.Password) + return val +}