Skip to content

Commit

Permalink
Avoid waiting for inventory sync in np controller (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
reachjainrahul authored Aug 16, 2023
1 parent 8a3306d commit 86cbd50
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 54 deletions.
17 changes: 0 additions & 17 deletions pkg/cloudprovider/plugins/aws/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down
10 changes: 1 addition & 9 deletions pkg/cloudprovider/plugins/aws/aws_security_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 0 additions & 18 deletions pkg/cloudprovider/plugins/azure/azure_compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down
11 changes: 1 addition & 10 deletions pkg/cloudprovider/plugins/azure/azure_security_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 86cbd50

Please sign in to comment.