From 83423f2c09628068d892057c9772c143b1ae7160 Mon Sep 17 00:00:00 2001 From: swetha Date: Thu, 31 Aug 2023 18:35:38 -0700 Subject: [PATCH] optimized the code to reduce the no. of api calls made --- pkg/frontend/encryptionathost_validation.go | 23 ++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/frontend/encryptionathost_validation.go b/pkg/frontend/encryptionathost_validation.go index 10b50a26506..0ff99e3610a 100644 --- a/pkg/frontend/encryptionathost_validation.go +++ b/pkg/frontend/encryptionathost_validation.go @@ -34,19 +34,18 @@ func (e encryptionAtHostValidator) ValidateEncryptionAtHost(ctx context.Context, } func validateEncryptionAtHost(ctx context.Context, subFeatureRegistrationsClient features.SubscriptionFeatureRegistrationsClient, oc *api.OpenShiftCluster) error { - encryptionSettings := make(map[api.EncryptionAtHost]bool) - - encryptionSettings[oc.Properties.MasterProfile.EncryptionAtHost] = true - - for _, wp := range oc.Properties.WorkerProfiles { - encryptionSettings[wp.EncryptionAtHost] = true + var hasEncryptionAtHostEnabled bool + profilesToCheck := append([]api.WorkerProfile{{EncryptionAtHost: oc.Properties.MasterProfile.EncryptionAtHost}}, oc.Properties.WorkerProfiles...) + for _, profile := range profilesToCheck { + if profile.EncryptionAtHost == api.EncryptionAtHostEnabled { + hasEncryptionAtHostEnabled = true + break + } } - - for setting := range encryptionSettings { - if setting == api.EncryptionAtHostEnabled { - if err := IsRegisteredForEncryptionAtHostFeature(ctx, subFeatureRegistrationsClient); err != nil { - return err - } + if hasEncryptionAtHostEnabled { + err := IsRegisteredForEncryptionAtHostFeature(ctx, subFeatureRegistrationsClient) + if err != nil { + return err } }