rbd: set vaultAuthNamespace to vaultNamespace if empty

When we read the csi-kms-connection-details configmap
vaultAuthNamespace might not be set when we do the
conversion the vaultAuthNamespace might be set to empty
key and this commits check for the empty value of
vaultAuthNamespace and set the vaultAuthNamespace
to vaultNamespace.

setting empty value for vaultAuthNamespace happened due
to Marshalling at https://github.com/ceph/ceph-csi/blob/devel/
internal/kms/vault_tokens.go#L136-L139.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-09-08 13:28:30 +05:30 committed by mergify[bot]
parent e99dd3dea4
commit 8c8f34cf7a

View File

@ -192,11 +192,16 @@ func (vc *vaultConnection) initConnection(config map[string]interface{}) error {
if errors.Is(err, errConfigOptionInvalid) { if errors.Is(err, errConfigOptionInvalid) {
return err return err
} }
vaultAuthNamespace := vaultNamespace // optional, same as vaultNamespace vaultAuthNamespace := ""
err = setConfigString(&vaultAuthNamespace, config, "vaultAuthNamespace") err = setConfigString(&vaultAuthNamespace, config, "vaultAuthNamespace")
if errors.Is(err, errConfigOptionInvalid) { if errors.Is(err, errConfigOptionInvalid) {
return err return err
} }
// if the vaultAuthNamespace key is present and value is empty in config, set
// the optional vaultNamespace.
if vaultAuthNamespace == "" {
vaultAuthNamespace = vaultNamespace
}
// set the option if the value was not invalid // set the option if the value was not invalid
if firstInit || !errors.Is(err, errConfigOptionMissing) { if firstInit || !errors.Is(err, errConfigOptionMissing) {
vaultConfig[api.EnvVaultNamespace] = vaultAuthNamespace vaultConfig[api.EnvVaultNamespace] = vaultAuthNamespace