From a7bd59e47d71cf094c8cf698cc060381d7dde230 Mon Sep 17 00:00:00 2001 From: Arun Kumar Mohan Date: Thu, 11 Jul 2024 15:43:29 +0530 Subject: [PATCH] Change to accept 'KMSServerAddress' automatically A minor code change to automatically set 'KMSServerAddress' while we add a new KMS configuration. Signed-off-by: Arun Kumar Mohan --- controllers/storagecluster/cephcluster.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/controllers/storagecluster/cephcluster.go b/controllers/storagecluster/cephcluster.go index 1c5a3d6d83..0a974c1d2f 100644 --- a/controllers/storagecluster/cephcluster.go +++ b/controllers/storagecluster/cephcluster.go @@ -180,14 +180,17 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1. // reset the KMS connection's error field, // it will be anyway set if there is an error sc.Status.KMSServerConnection.KMSServerConnectionError = "" - if kmsConfigMap.Data["KMS_PROVIDER"] == "vault" { - sc.Status.KMSServerConnection.KMSServerAddress = kmsConfigMap.Data["VAULT_ADDR"] - } else if kmsConfigMap.Data["KMS_PROVIDER"] == AzureKSMProvider { - sc.Status.KMSServerConnection.KMSServerAddress = kmsConfigMap.Data["AZURE_VAULT_URL"] - } else if kmsConfigMap.Data["KMS_PROVIDER"] == ThalesKMSProvider { - sc.Status.KMSServerConnection.KMSServerAddress = kmsConfigMap.Data["KMIP_ENDPOINT"] - } - if err = reachKMSProvider(kmsConfigMap); err != nil { + // get the current KMS provider name + currKMSProvider := kmsConfigMap.Data[KMSProviderKey] + // according to the KMS provider, get the corresponding address/endpoint key + // and use it to set 'KMSServerAddress' status + kmsAddrssKey := kmsProviderAddressKeyMap[currKMSProvider] + sc.Status.KMSServerConnection.KMSServerAddress = kmsConfigMap.Data[kmsAddrssKey] + // if the KMS connection address is empty, log it as an error and continue + if sc.Status.KMSServerConnection.KMSServerAddress == "" { + r.Log.Error(nil, "An empty KMS server connection address found", + "KMSProviderName", currKMSProvider, "KMSAddressKey", kmsAddrssKey) + } else if err = reachKMSProvider(kmsConfigMap); err != nil { sc.Status.KMSServerConnection.KMSServerConnectionError = err.Error() r.Log.Error(err, "Address provided in KMS ConfigMap is not reachable.", "KMSConfigMap", klog.KRef(kmsConfigMap.Namespace, kmsConfigMap.Name)) return reconcile.Result{}, err