Skip to content

Commit

Permalink
add more tests for exclude asset
Browse files Browse the repository at this point in the history
Signed-off-by: Anubhav Aeron <anubhav_aeron@intuit.com>
  • Loading branch information
Anubhav Aeron committed Sep 19, 2022
1 parent 24d2c01 commit 955da30
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 139 deletions.
3 changes: 0 additions & 3 deletions admiral/pkg/clusters/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,10 @@ func createDestinationRuleSkeletion(dr v1alpha32.DestinationRule, name string, n
}

func getServiceForDeployment(rc *RemoteController, deployment *k8sAppsV1.Deployment) *k8sV1.Service {

if deployment == nil {
return nil
}

cachedServices := rc.ServiceController.Cache.Get(deployment.Namespace)

if cachedServices == nil {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion admiral/pkg/clusters/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
)

func TestGetDependentClusters(t *testing.T) {

identityClusterCache := common.NewMapOfMaps()
identityClusterCache.Put("id1", "dep1", "cl1")
identityClusterCache.Put("id2", "dep2", "cl2")
Expand Down
1 change: 1 addition & 0 deletions admiral/pkg/clusters/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var registryTestSingleton sync.Once

func setupForRegistryTests() {
registryTestSingleton.Do(func() {
common.ResetSync()
p := common.AdmiralParams{
KubeconfigPath: "testdata/fake.config",
LabelSet: &common.LabelSet{},
Expand Down
21 changes: 14 additions & 7 deletions admiral/pkg/clusters/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func createServiceEntry(ctx context.Context, event admiral.EventType, rc *Remote
return tmpSe
}

func modifyServiceEntryForNewServiceOrPod(ctx context.Context, event admiral.EventType, env string, sourceIdentity string, remoteRegistry *RemoteRegistry) map[string]*networking.ServiceEntry {
func modifyServiceEntryForNewServiceOrPod(
ctx context.Context, event admiral.EventType, env string, sourceIdentity string,
remoteRegistry *RemoteRegistry) map[string]*networking.ServiceEntry {
defer util.LogElapsedTime("modifyServiceEntryForNewServiceOrPod", sourceIdentity, env, "")()
if CurrentAdmiralState.ReadOnly {
log.Infof(LogFormat, event, env, sourceIdentity, "", "Processing skipped as Admiral is in Read-only mode")
Expand Down Expand Up @@ -193,11 +195,12 @@ func modifyServiceEntryForNewServiceOrPod(ctx context.Context, event admiral.Eve

for key, serviceEntry := range serviceEntries {
if len(serviceEntry.Endpoints) == 0 {
AddServiceEntriesWithDr(ctx, remoteRegistry, map[string]string{sourceCluster: sourceCluster},

AddServiceEntriesWithDr(
ctx, remoteRegistry, map[string]string{sourceCluster: sourceCluster},
map[string]*networking.ServiceEntry{key: serviceEntry})
}
clusterIngress, _ := rc.ServiceController.Cache.GetLoadBalancer(common.GetAdmiralParams().LabelSet.GatewayApp, common.NamespaceIstioSystem)
clusterIngress, _ := rc.ServiceController.Cache.GetLoadBalancer(
common.GetAdmiralParams().LabelSet.GatewayApp, common.NamespaceIstioSystem)
for _, ep := range serviceEntry.Endpoints {
//replace istio ingress-gateway address with local fqdn, note that ingress-gateway can be empty (not provisoned, or is not up)
if ep.Address == clusterIngress || ep.Address == "" {
Expand Down Expand Up @@ -266,7 +269,6 @@ func modifyServiceEntryForNewServiceOrPod(ctx context.Context, event admiral.Eve
//i) Picks the GTP that was created most recently from the passed in GTP list based on GTP priority label (GTPs from all clusters)
//ii) Updates the global GTP cache with the selected GTP in i)
func updateGlobalGtpCache(cache *AdmiralCache, identity, env string, gtps map[string][]*v1.GlobalTrafficPolicy) {
defer util.LogElapsedTime("updateGlobalGtpCache", identity, env, "")()
gtpsOrdered := make([]*v1.GlobalTrafficPolicy, 0)
for _, gtpsInCluster := range gtps {
gtpsOrdered = append(gtpsOrdered, gtpsInCluster...)
Expand Down Expand Up @@ -378,7 +380,10 @@ func modifySidecarForLocalClusterCommunication(ctx context.Context, sidecarNames
return
}

sidecar, _ := sidecarConfig.IstioClient.NetworkingV1alpha3().Sidecars(sidecarNamespace).Get(ctx, common.GetWorkloadSidecarName(), v12.GetOptions{})
sidecar, err := sidecarConfig.IstioClient.NetworkingV1alpha3().Sidecars(sidecarNamespace).Get(ctx, common.GetWorkloadSidecarName(), v12.GetOptions{})
if err != nil {
return
}

if sidecar == nil || (sidecar.Spec.Egress == nil) {
return
Expand Down Expand Up @@ -735,7 +740,9 @@ func getUniqueAddress(ctx context.Context, admiralCache *AdmiralCache, globalFqd
needsCacheUpdate := false

for err == nil && counter < maxRetries {
address, needsCacheUpdate, err = GetLocalAddressForSe(ctx, getIstioResourceName(globalFqdn, "-se"), admiralCache.ServiceEntryAddressStore, admiralCache.ConfigMapController)
address, needsCacheUpdate, err = GetLocalAddressForSe(
ctx, getIstioResourceName(globalFqdn, "-se"),
admiralCache.ServiceEntryAddressStore, admiralCache.ConfigMapController)

if err != nil {
log.Errorf("Error getting local address for Service Entry. Err: %v", err)
Expand Down
Loading

0 comments on commit 955da30

Please sign in to comment.