From 86cbd5030b2152096dd56228b55971df93278ffb Mon Sep 17 00:00:00 2001 From: Rahul Jain Date: Wed, 16 Aug 2023 14:43:18 -0700 Subject: [PATCH] Avoid waiting for inventory sync in np controller (#300) --- pkg/cloudprovider/plugins/aws/aws_ec2.go | 17 ----------------- .../plugins/aws/aws_security_impl.go | 10 +--------- .../plugins/azure/azure_compute.go | 18 ------------------ .../plugins/azure/azure_security_impl.go | 11 +---------- 4 files changed, 2 insertions(+), 54 deletions(-) diff --git a/pkg/cloudprovider/plugins/aws/aws_ec2.go b/pkg/cloudprovider/plugins/aws/aws_ec2.go index 71eb5519..bcc937f2 100644 --- a/pkg/cloudprovider/plugins/aws/aws_ec2.go +++ b/pkg/cloudprovider/plugins/aws/aws_ec2.go @@ -17,11 +17,9 @@ package aws import ( "fmt" "strings" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/cenkalti/backoff/v4" "github.com/mohae/deepcopy" "k8s.io/apimachinery/pkg/types" @@ -85,21 +83,6 @@ func (p *awsServiceSdkConfigProvider) compute() (awsEC2Wrapper, error) { return awsEC2, nil } -func (ec2Cfg *ec2ServiceConfig) waitForInventoryInit(duration time.Duration) error { - operation := func() error { - done := ec2Cfg.inventoryStats.IsInventoryInitialized() - if !done { - return fmt.Errorf("inventory for account %v not initialized (waited %v duration)", ec2Cfg.accountNamespacedName, duration) - } - return nil - } - - b := backoff.NewExponentialBackOff() - b.MaxElapsedTime = duration - - return backoff.Retry(operation, b) -} - // getCachedInstances returns instances from the cache applicable for the given selector. func (ec2Cfg *ec2ServiceConfig) getCachedInstances(selector *types.NamespacedName) []*ec2.Instance { snapshot := ec2Cfg.resourcesCache.GetSnapshot() diff --git a/pkg/cloudprovider/plugins/aws/aws_security_impl.go b/pkg/cloudprovider/plugins/aws/aws_security_impl.go index 2dcbcd57..d45e53c2 100644 --- a/pkg/cloudprovider/plugins/aws/aws_security_impl.go +++ b/pkg/cloudprovider/plugins/aws/aws_security_impl.go @@ -22,7 +22,6 @@ import ( "k8s.io/apimachinery/pkg/types" "antrea.io/nephe/pkg/cloudprovider/cloudresource" - "antrea.io/nephe/pkg/cloudprovider/plugins/internal" "antrea.io/nephe/pkg/cloudprovider/utils" ) @@ -244,19 +243,12 @@ func (c *awsCloud) GetEnforcedSecurity() []cloudresource.SynchronizationContent accCfg, err := c.cloudCommon.GetCloudAccountByName(name) if err != nil { - awsPluginLogger().Info("Enforced-security-cloud-view GET for account skipped", "err", err) return } accCfg.LockMutex() defer accCfg.UnlockMutex() - - ec2Service := accCfg.GetServiceConfig().(*ec2ServiceConfig) - if err := ec2Service.waitForInventoryInit(internal.InventoryInitWaitDuration); err != nil { - awsPluginLogger().Error(err, "Enforced-security-cloud-view GET for account skipped", "account", accCfg.GetNamespacedName()) - return - } - sendCh <- ec2Service.getNepheControllerManagedSecurityGroupsCloudView() + sendCh <- accCfg.GetServiceConfig().(*ec2ServiceConfig).getNepheControllerManagedSecurityGroupsCloudView() }(accNamespacedNameCopy, ch) } diff --git a/pkg/cloudprovider/plugins/azure/azure_compute.go b/pkg/cloudprovider/plugins/azure/azure_compute.go index 342ce684..eae9419f 100644 --- a/pkg/cloudprovider/plugins/azure/azure_compute.go +++ b/pkg/cloudprovider/plugins/azure/azure_compute.go @@ -18,10 +18,8 @@ import ( "context" "fmt" "strings" - "time" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" - "github.com/cenkalti/backoff/v4" "github.com/mohae/deepcopy" "k8s.io/apimachinery/pkg/types" @@ -102,22 +100,6 @@ func newComputeServiceConfig(account types.NamespacedName, service azureServiceC return config, nil } -func (computeCfg *computeServiceConfig) waitForInventoryInit(duration time.Duration) error { - operation := func() error { - done := computeCfg.inventoryStats.IsInventoryInitialized() - if !done { - return fmt.Errorf("inventory for account %v not initialized (waited %v duration)", - computeCfg.accountNamespacedName, duration) - } - return nil - } - - b := backoff.NewExponentialBackOff() - b.MaxElapsedTime = duration - - return backoff.Retry(operation, b) -} - // getCachedVirtualMachines returns virtualMachines specific to a selector from the cache for the subscription. func (computeCfg *computeServiceConfig) getCachedVirtualMachines(selector *types.NamespacedName) []*virtualMachineTable { snapshot := computeCfg.resourcesCache.GetSnapshot() diff --git a/pkg/cloudprovider/plugins/azure/azure_security_impl.go b/pkg/cloudprovider/plugins/azure/azure_security_impl.go index 104f47cd..8920f514 100644 --- a/pkg/cloudprovider/plugins/azure/azure_security_impl.go +++ b/pkg/cloudprovider/plugins/azure/azure_security_impl.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/types" "antrea.io/nephe/pkg/cloudprovider/cloudresource" - "antrea.io/nephe/pkg/cloudprovider/plugins/internal" ) // CreateSecurityGroup invokes cloud api and creates the cloud security group based on securityGroupIdentifier. @@ -228,20 +227,12 @@ func (c *azureCloud) GetEnforcedSecurity() []cloudresource.SynchronizationConten accCfg, err := c.cloudCommon.GetCloudAccountByName(name) if err != nil { - azurePluginLogger().Info("Enforced-security-cloud-view GET for account skipped", "err", - err) return } accCfg.LockMutex() defer accCfg.UnlockMutex() - - computeService := accCfg.GetServiceConfig().(*computeServiceConfig) - if err := computeService.waitForInventoryInit(internal.InventoryInitWaitDuration); err != nil { - azurePluginLogger().Error(err, "enforced-security-cloud-view GET for account skipped", "account", accCfg.GetNamespacedName()) - return - } - sendCh <- computeService.getNepheControllerManagedSecurityGroupsCloudView() + sendCh <- accCfg.GetServiceConfig().(*computeServiceConfig).getNepheControllerManagedSecurityGroupsCloudView() }(accNamespacedNameCopy, ch) }