From 004ccbbbaeab91665000080bc04933c7083663ef Mon Sep 17 00:00:00 2001 From: aattuluri Date: Wed, 13 Jul 2022 18:16:04 -0700 Subject: [PATCH 1/3] Fix concurrent map access. Remove unwanted code Fix concurrent map access. Remove unwanted code to create SEs based on user created destination rules --- Makefile | 2 +- admiral/pkg/clusters/handler.go | 119 ------------------- admiral/pkg/clusters/registry_test.go | 53 +-------- admiral/pkg/clusters/serviceentry.go | 36 +++--- admiral/pkg/controller/admiral/dependency.go | 2 + admiral/pkg/controller/admiral/deployment.go | 42 +++---- admiral/pkg/controller/admiral/rollouts.go | 37 +++--- 7 files changed, 67 insertions(+), 224 deletions(-) diff --git a/Makefile b/Makefile index 36185303..105783b6 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SHELL := /bin/bash GOCMD?=go GOBUILD?=$(GOCMD) build GOCLEAN?=$(GOCMD) clean -GOTEST?=$(GOCMD) test +GOTEST?=$(GOCMD) test -race GOGET?=$(GOCMD) get GOBIN?=$(GOPATH)/bin OUT?=./out/ diff --git a/admiral/pkg/clusters/handler.go b/admiral/pkg/clusters/handler.go index 0064a4f0..a4acd5c0 100644 --- a/admiral/pkg/clusters/handler.go +++ b/admiral/pkg/clusters/handler.go @@ -258,10 +258,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu clusterId := dh.ClusterID - localDrName := obj.Name + "-local" - - var localIdentityId string - syncNamespace := common.GetSyncNamespace() r := dh.RemoteRegistry @@ -272,13 +268,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu log.Infof(LogFormat, "Event", "DestinationRule", obj.Name, clusterId, "Processing") - //Create label based service entry in source and dependent clusters for subset routing to work - host := destinationRule.Host - - basicSEName := getIstioResourceName(host, "-se") - - seName := getIstioResourceName(host, "-se") - allDependentClusters := make(map[string]string) util.MapCopy(allDependentClusters, dependentClusters) @@ -289,36 +278,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu rc := r.RemoteControllers[dependentCluster] - var newServiceEntry *v1alpha3.ServiceEntry - - var existsServiceEntry *v1alpha3.ServiceEntry - - var drServiceEntries = make(map[string]*v1alpha32.ServiceEntry) - - exist, err := rc.ServiceEntryController.IstioClient.NetworkingV1alpha3().ServiceEntries(syncNamespace).Get(basicSEName, v12.GetOptions{}) - - var identityId = "" - - if exist == nil || err != nil { - - log.Warnf(LogFormat, "Find", "ServiceEntry", basicSEName, dependentCluster, "Failed") - - } else { - - serviceEntry := exist.Spec - - identityRaw, ok := r.AdmiralCache.CnameIdentityCache.Load(serviceEntry.Hosts[0]) - - if ok { - identityId = fmt.Sprintf("%v", identityRaw) - if dependentCluster == clusterId { - localIdentityId = identityId - } - drServiceEntries = createSeWithDrLabels(rc, dependentCluster == clusterId, identityId, seName, &serviceEntry, &destinationRule, r.AdmiralCache.ServiceEntryAddressStore, r.AdmiralCache.ConfigMapController) - } - - } - if event == common.Delete { err := rc.DestinationRuleController.IstioClient.NetworkingV1alpha3().DestinationRules(syncNamespace).Delete(obj.Name, &v12.DeleteOptions{}) @@ -327,27 +286,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu } else { log.Errorf(LogErrFormat, "Delete", "DestinationRule", obj.Name, clusterId, err) } - err = rc.ServiceEntryController.IstioClient.NetworkingV1alpha3().ServiceEntries(syncNamespace).Delete(seName, &v12.DeleteOptions{}) - if err != nil { - log.Infof(LogFormat, "Delete", "ServiceEntry", seName, clusterId, "success") - } else { - log.Errorf(LogErrFormat, "Delete", "ServiceEntry", seName, clusterId, err) - } - for _, subset := range destinationRule.Subsets { - sseName := seName + common.Dash + subset.Name - err = rc.ServiceEntryController.IstioClient.NetworkingV1alpha3().ServiceEntries(syncNamespace).Delete(sseName, &v12.DeleteOptions{}) - if err != nil { - log.Infof(LogFormat, "Delete", "ServiceEntry", sseName, clusterId, "success") - } else { - log.Errorf(LogErrFormat, "Delete", "ServiceEntry", sseName, clusterId, err) - } - } - err = rc.DestinationRuleController.IstioClient.NetworkingV1alpha3().DestinationRules(syncNamespace).Delete(localDrName, &v12.DeleteOptions{}) - if err != nil { - log.Infof(LogFormat, "Delete", "DestinationRule", localDrName, clusterId, "success") - } else { - log.Errorf(LogErrFormat, "Delete", "DestinationRule", localDrName, clusterId, err) - } } else { @@ -357,28 +295,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu if dependentCluster != clusterId { addUpdateDestinationRule(obj, exist, syncNamespace, rc) } - - for _seName, se := range drServiceEntries { - existsServiceEntry, _ = rc.ServiceEntryController.IstioClient.NetworkingV1alpha3().ServiceEntries(syncNamespace).Get(_seName, v12.GetOptions{}) - newServiceEntry = createServiceEntrySkeletion(*se, _seName, syncNamespace) - if err != nil { - log.Warnf(LogErrFormat, "Create", "ServiceEntry", seName, clusterId, err) - } - if newServiceEntry != nil { - addUpdateServiceEntry(newServiceEntry, existsServiceEntry, syncNamespace, rc) - r.AdmiralCache.SeClusterCache.Put(newServiceEntry.Spec.Hosts[0], rc.ClusterID, rc.ClusterID) - } - //cache the subset service entries for updating them later for pod events - if dependentCluster == clusterId && se.Resolution == v1alpha32.ServiceEntry_STATIC { - r.AdmiralCache.SubsetServiceEntryIdentityCache.Store(identityId, map[string]string{_seName: clusterId}) - } - } - - if dependentCluster == clusterId { - //we need a destination rule with local fqdn for destination rules created with cnames to work in local cluster - createDestinationRuleForLocal(rc, localDrName, localIdentityId, clusterId, &destinationRule) - } - } } return @@ -404,41 +320,6 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu } } -func createDestinationRuleForLocal(remoteController *RemoteController, localDrName string, identityId string, clusterId string, - destinationRule *v1alpha32.DestinationRule) { - - deployment := remoteController.DeploymentController.Cache.Get(identityId) - - if deployment == nil || len(deployment.Deployments) == 0 { - log.Errorf(LogFormat, "Find", "deployment", identityId, remoteController.ClusterID, "Couldn't find deployment with identity") - return - } - - //TODO this will pull a random deployment from some cluster which might not be the right deployment - var deploymentInstance *k8sAppsV1.Deployment - for _, value := range deployment.Deployments { - deploymentInstance = value - break - } - - syncNamespace := common.GetSyncNamespace() - serviceInstance := getServiceForDeployment(remoteController, deploymentInstance) - - cname := common.GetCname(deploymentInstance, common.GetHostnameSuffix(), common.GetWorkloadIdentifier()) - if cname == destinationRule.Host { - destinationRule.Host = serviceInstance.Name + common.Sep + serviceInstance.Namespace + common.DotLocalDomainSuffix - existsDestinationRule, err := remoteController.DestinationRuleController.IstioClient.NetworkingV1alpha3().DestinationRules(syncNamespace).Get(localDrName, v12.GetOptions{}) - if err != nil { - log.Warnf(LogErrFormat, "Find", "DestinationRule", localDrName, clusterId, err) - } - newDestinationRule := createDestinationRuleSkeletion(*destinationRule, localDrName, syncNamespace) - - if newDestinationRule != nil { - addUpdateDestinationRule(newDestinationRule, existsDestinationRule, syncNamespace, remoteController) - } - } -} - func handleVirtualServiceEvent(obj *v1alpha3.VirtualService, vh *VirtualServiceHandler, event common.Event, resourceType common.ResourceType) error { log.Infof(LogFormat, "Event", resourceType, obj.Name, vh.ClusterID, "Received event") diff --git a/admiral/pkg/clusters/registry_test.go b/admiral/pkg/clusters/registry_test.go index a6fdf9cc..7bcc9bc2 100644 --- a/admiral/pkg/clusters/registry_test.go +++ b/admiral/pkg/clusters/registry_test.go @@ -48,7 +48,7 @@ func TestDeleteCacheControllerThatDoesntExist(t *testing.T) { w := RemoteRegistry{ RemoteControllers: make(map[string]*RemoteController), - StartTime: time.Now(), + StartTime: time.Now(), } err := w.deleteCacheController("I don't exit") @@ -62,7 +62,7 @@ func TestDeleteCacheController(t *testing.T) { w := RemoteRegistry{ RemoteControllers: make(map[string]*RemoteController), - StartTime: time.Now(), + StartTime: time.Now(), } r := rest.Config{ @@ -132,55 +132,6 @@ func TestCopySidecar(t *testing.T) { } } -func TestCreateDestinationRuleForLocalNoDeployLabel(t *testing.T) { - - config := rest.Config{ - Host: "localhost", - } - - d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) - - if e != nil { - t.Fail() - } - - rc := RemoteController{ - DeploymentController: d, - } - - des := networking.DestinationRule{ - Host: "test.com", - Subsets: []*networking.Subset{ - {Name: "subset1", Labels: map[string]string{"foo": "bar"}, TrafficPolicy: nil}, - }, - } - - createDestinationRuleForLocal(&rc, "local.name", "identity", "cluster1", &des) - -} - -func TestCreateDestinationRuleForLocal(t *testing.T) { - - rc, err := createMockRemoteController( - func(i interface{}) { - - }, - ) - - if err != nil { - t.Fail() - } - des := networking.DestinationRule{ - Host: "dev.bar.global", - Subsets: []*networking.Subset{ - {Name: "subset1", Labels: map[string]string{"foo": "bar"}, TrafficPolicy: nil}, - }, - } - - createDestinationRuleForLocal(rc, "local.name", "bar", "cluster1", &des) - -} - func createMockRemoteController(f func(interface{})) (*RemoteController, error) { config := rest.Config{ Host: "localhost", diff --git a/admiral/pkg/clusters/serviceentry.go b/admiral/pkg/clusters/serviceentry.go index 1ba1b067..ef752d71 100644 --- a/admiral/pkg/clusters/serviceentry.go +++ b/admiral/pkg/clusters/serviceentry.go @@ -74,7 +74,7 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s cnames := make(map[string]string) var serviceInstance *k8sV1.Service var weightedServices map[string]*WeightedService - var rollout *admiral.RolloutClusterEntry + var rollout *argo.Rollout var gtps = make(map[string][]*v1.GlobalTrafficPolicy) var namespace string @@ -84,29 +84,27 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s start := time.Now() for _, rc := range remoteRegistry.RemoteControllers { - deployment := rc.DeploymentController.Cache.Get(sourceIdentity) + deployment := rc.DeploymentController.Cache.Get(sourceIdentity, env) if rc.RolloutController != nil { - rollout = rc.RolloutController.Cache.Get(sourceIdentity) + rollout = rc.RolloutController.Cache.Get(sourceIdentity, env) } - if deployment != nil && deployment.Deployments[env] != nil { - deploymentInstance := deployment.Deployments[env] + if deployment != nil { - serviceInstance = getServiceForDeployment(rc, deploymentInstance) + serviceInstance = getServiceForDeployment(rc, deployment) if serviceInstance == nil { continue } - namespace = deploymentInstance.Namespace - localMeshPorts := GetMeshPorts(rc.ClusterID, serviceInstance, deploymentInstance) + namespace = deployment.Namespace + localMeshPorts := GetMeshPorts(rc.ClusterID, serviceInstance, deployment) - cname = common.GetCname(deploymentInstance, common.GetWorkloadIdentifier(), common.GetHostnameSuffix()) - sourceDeployments[rc.ClusterID] = deploymentInstance - createServiceEntry(event, rc, remoteRegistry.AdmiralCache, localMeshPorts, deploymentInstance, serviceEntries) - } else if rollout != nil && rollout.Rollouts[env] != nil { - rolloutInstance := rollout.Rollouts[env] + cname = common.GetCname(deployment, common.GetWorkloadIdentifier(), common.GetHostnameSuffix()) + sourceDeployments[rc.ClusterID] = deployment + createServiceEntry(event, rc, remoteRegistry.AdmiralCache, localMeshPorts, deployment, serviceEntries) + } else if rollout != nil { - weightedServices = getServiceForRollout(rc, rolloutInstance) + weightedServices = getServiceForRollout(rc, rollout) if len(weightedServices) == 0 { continue } @@ -116,13 +114,13 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s serviceInstance = sInstance.Service break } - namespace = rolloutInstance.Namespace - localMeshPorts := GetMeshPortsForRollout(rc.ClusterID, serviceInstance, rolloutInstance) + namespace = rollout.Namespace + localMeshPorts := GetMeshPortsForRollout(rc.ClusterID, serviceInstance, rollout) - cname = common.GetCnameForRollout(rolloutInstance, common.GetWorkloadIdentifier(), common.GetHostnameSuffix()) + cname = common.GetCnameForRollout(rollout, common.GetWorkloadIdentifier(), common.GetHostnameSuffix()) cnames[cname] = "1" - sourceRollouts[rc.ClusterID] = rolloutInstance - createServiceEntryForRollout(event, rc, remoteRegistry.AdmiralCache, localMeshPorts, rolloutInstance, serviceEntries) + sourceRollouts[rc.ClusterID] = rollout + createServiceEntryForRollout(event, rc, remoteRegistry.AdmiralCache, localMeshPorts, rollout, serviceEntries) } else { continue } diff --git a/admiral/pkg/controller/admiral/dependency.go b/admiral/pkg/controller/admiral/dependency.go index 5949f9bb..391387e4 100644 --- a/admiral/pkg/controller/admiral/dependency.go +++ b/admiral/pkg/controller/admiral/dependency.go @@ -45,6 +45,8 @@ func (d *depCache) getKey(dep *v1.Dependency) string { } func (d *depCache) Get(identity string) *v1.Dependency { + defer d.mutex.Unlock() + d.mutex.Lock() return d.cache[identity] } diff --git a/admiral/pkg/controller/admiral/deployment.go b/admiral/pkg/controller/admiral/deployment.go index a6b6b868..7c666232 100644 --- a/admiral/pkg/controller/admiral/deployment.go +++ b/admiral/pkg/controller/admiral/deployment.go @@ -45,36 +45,45 @@ func (p *deploymentCache) getKey(deployment *k8sAppsV1.Deployment) string { return common.GetDeploymentGlobalIdentifier(deployment) } -func (p *deploymentCache) Get(key string) *DeploymentClusterEntry { - return p.cache[key] +func (p *deploymentCache) Get(key string, env string) *k8sAppsV1.Deployment { + defer p.mutex.Unlock() + p.mutex.Lock() + dce := p.cache[key] + if dce != nil { + return dce.Deployments[env] + } else { + return nil + } } func (p *deploymentCache) UpdateDeploymentToClusterCache(key string, deployment *k8sAppsV1.Deployment) { defer p.mutex.Unlock() p.mutex.Lock() - v := p.Get(key) + env := common.GetEnv(deployment) + + dce := p.cache[key] - if v == nil { - v = &DeploymentClusterEntry{ + if dce == nil { + dce = &DeploymentClusterEntry{ Identity: key, Deployments: make(map[string]*k8sAppsV1.Deployment), } - p.cache[v.Identity] = v } - env := common.GetEnv(deployment) - v.Deployments[env] = deployment + dce.Deployments[env] = deployment + p.cache[dce.Identity] = dce } func (p *deploymentCache) DeleteFromDeploymentClusterCache(key string, deployment *k8sAppsV1.Deployment) { defer p.mutex.Unlock() p.mutex.Lock() - v := p.Get(key) + env := common.GetEnv(deployment) + + dce := p.cache[key] - if v != nil { - env := common.GetEnv(deployment) - delete(v.Deployments, env) + if dce != nil { + delete(dce.Deployments, env) } } @@ -109,13 +118,6 @@ func NewDeploymentController(clusterID string, stopCh <-chan struct{}, handler D return &deploymentController, nil } -func NewDeploymentControllerWithLabelOverride(stopCh <-chan struct{}, handler DeploymentHandler, config *rest.Config, resyncPeriod time.Duration, labelSet *common.LabelSet) (*DeploymentController, error) { - - dc, err := NewDeploymentController("", stopCh, handler, config, resyncPeriod) - dc.labelSet = labelSet - return dc, err -} - func (d *DeploymentController) Added(obj interface{}) { HandleAddUpdateDeployment(obj, d) } @@ -185,7 +187,7 @@ func (d *DeploymentController) GetDeploymentBySelectorInNamespace(serviceSelecto return []k8sAppsV1.Deployment{} } - filteredDeployments := make ([]k8sAppsV1.Deployment, 0) + filteredDeployments := make([]k8sAppsV1.Deployment, 0) for _, deployment := range matchedDeployments.Items { if common.IsServiceMatch(serviceSelector, deployment.Spec.Selector) { diff --git a/admiral/pkg/controller/admiral/rollouts.go b/admiral/pkg/controller/admiral/rollouts.go index 4e8a644e..5724cd48 100644 --- a/admiral/pkg/controller/admiral/rollouts.go +++ b/admiral/pkg/controller/admiral/rollouts.go @@ -61,8 +61,15 @@ func (p *rolloutCache) getKey(rollout *argo.Rollout) string { return common.GetRolloutGlobalIdentifier(rollout) } -func (p *rolloutCache) Get(key string) *RolloutClusterEntry { - return p.cache[key] +func (p *rolloutCache) Get(key string, env string) *argo.Rollout { + defer p.mutex.Unlock() + p.mutex.Lock() + rce := p.cache[key] + if rce == nil { + return nil + } else { + return rce.Rollouts[env] + } } func (p *rolloutCache) Delete(pod *RolloutClusterEntry) { @@ -75,28 +82,30 @@ func (p *rolloutCache) UpdateRolloutToClusterCache(key string, rollout *argo.Rol defer p.mutex.Unlock() p.mutex.Lock() - v := p.Get(key) + env := common.GetEnvForRollout(rollout) - if v == nil { - v = &RolloutClusterEntry{ + rce := p.cache[key] + + if rce == nil { + rce = &RolloutClusterEntry{ Identity: key, Rollouts: make(map[string]*argo.Rollout), } - p.cache[v.Identity] = v } - env := common.GetEnvForRollout(rollout) - v.Rollouts[env] = rollout + rce.Rollouts[env] = rollout + p.cache[rce.Identity] = rce } func (p *rolloutCache) DeleteFromRolloutToClusterCache(key string, rollout *argo.Rollout) { defer p.mutex.Unlock() p.mutex.Lock() - v := p.Get(key) + env := common.GetEnvForRollout(rollout) + + rce := p.cache[key] - if v != nil { - env := common.GetEnvForRollout(rollout) - delete(v.Rollouts, env) + if rce != nil { + delete(rce.Rollouts, env) } } @@ -204,10 +213,10 @@ func (d *RolloutController) GetRolloutBySelectorInNamespace(serviceSelector map[ } if matchedRollouts.Items == nil { - return make([]argo.Rollout,0) + return make([]argo.Rollout, 0) } - filteredRollouts := make ([]argo.Rollout, 0) + filteredRollouts := make([]argo.Rollout, 0) for _, rollout := range matchedRollouts.Items { if common.IsServiceMatch(serviceSelector, rollout.Spec.Selector) { From 6c3b8601056a76683be80932701361e5feff6dd6 Mon Sep 17 00:00:00 2001 From: aattuluri Date: Thu, 14 Jul 2022 15:09:29 -0700 Subject: [PATCH 2/3] Remove dead code. --- admiral/pkg/clusters/serviceentry.go | 43 ---------------------------- 1 file changed, 43 deletions(-) diff --git a/admiral/pkg/clusters/serviceentry.go b/admiral/pkg/clusters/serviceentry.go index ef752d71..3a774760 100644 --- a/admiral/pkg/clusters/serviceentry.go +++ b/admiral/pkg/clusters/serviceentry.go @@ -389,49 +389,6 @@ func copySidecar(sidecar *v1alpha3.Sidecar) *v1alpha3.Sidecar { return newSidecarObj } -func createSeWithDrLabels(remoteController *RemoteController, localCluster bool, identityId string, seName string, se *networking.ServiceEntry, - dr *networking.DestinationRule, seAddressCache *ServiceEntryAddressStore, configmapController admiral.ConfigMapControllerInterface) map[string]*networking.ServiceEntry { - var allSes = make(map[string]*networking.ServiceEntry) - var newSe = copyServiceEntry(se) - - address, _, err := GetLocalAddressForSe(seName, seAddressCache, configmapController) - if err != nil { - log.Warnf("Failed to get address for dr service entry. Not creating it. err:%v", err) - return nil - } - newSe.Addresses = []string{address} - - var endpoints = make([]*networking.ServiceEntry_Endpoint, 0) - - for _, endpoint := range se.Endpoints { - for _, subset := range dr.Subsets { - newEndpoint := copyEndpoint(endpoint) - newEndpoint.Labels = subset.Labels - - ////create a service entry with name subsetSeName - //if localCluster { - // subsetSeName := seName + common.Dash + subset.Name - // subsetSeAddress := strings.Split(se.Hosts[0], common.DotMesh)[0] + common.Sep + subset.Name + common.DotMesh BROKEN MUST FIX //todo fix the cname format here - // - // //TODO uncomment the line below when subset routing across clusters is fixed - // //newEndpoint.Address = subsetSeAddress - // - // subSetSe := createSeWithPodIps(remoteController, identityId, subsetSeName, subsetSeAddress, newSe, newEndpoint, subset, seAddressMap) - // if subSetSe != nil { - // allSes[subsetSeName] = subSetSe - // //TODO create default DestinationRules for these subset SEs - // } - //} - - endpoints = append(endpoints, newEndpoint) - - } - } - newSe.Endpoints = endpoints - allSes[seName] = newSe - return allSes -} - //This will create the default service entries and also additional ones specified in GTP func AddServiceEntriesWithDr(cache *AdmiralCache, sourceClusters map[string]string, rcs map[string]*RemoteController, serviceEntries map[string]*networking.ServiceEntry) { syncNamespace := common.GetSyncNamespace() From 4b8551fd7b066727a62d1e9df5faa2c6e3d0a1b2 Mon Sep 17 00:00:00 2001 From: aattuluri Date: Thu, 14 Jul 2022 15:40:10 -0700 Subject: [PATCH 3/3] Remove tests for deleted code. --- admiral/pkg/clusters/serviceentry_test.go | 52 ++--------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/admiral/pkg/clusters/serviceentry_test.go b/admiral/pkg/clusters/serviceentry_test.go index a8ed9189..b0de7915 100644 --- a/admiral/pkg/clusters/serviceentry_test.go +++ b/admiral/pkg/clusters/serviceentry_test.go @@ -31,52 +31,6 @@ import ( "k8s.io/client-go/rest" ) -func TestCreateSeWithDrLabels(t *testing.T) { - - se := istionetworkingv1alpha3.ServiceEntry{ - Hosts: []string{"test.com"}, - Endpoints: []*istionetworkingv1alpha3.ServiceEntry_Endpoint{ - {Address: "127.0.0.1", Ports: map[string]uint32{"https": 80}, Labels: map[string]string{}, Network: "mesh1", Locality: "us-west", Weight: 100}, - }, - } - - des := istionetworkingv1alpha3.DestinationRule{ - Host: "test.com", - Subsets: []*istionetworkingv1alpha3.Subset{ - {Name: "subset1", Labels: map[string]string{"foo": "bar"}, TrafficPolicy: nil}, - }, - } - - cacheWithNoEntry := ServiceEntryAddressStore{ - EntryAddresses: map[string]string{"test-se": "1.2.3.4"}, - Addresses: []string{"1.2.3.4"}, - } - - emptyCacheController := test.FakeConfigMapController{ - GetError: nil, - PutError: nil, - ConfigmapToReturn: buildFakeConfigMapFromAddressStore(&cacheWithNoEntry, "123"), - } - - res := createSeWithDrLabels(nil, false, "", "test-se", &se, &des, &cacheWithNoEntry, &emptyCacheController) - - if res == nil { - t.Fail() - } - - newSe := res["test-se"] // Test for Rollout - - value := newSe.Endpoints[0].Labels["foo"] - - if value != "bar" { - t.Fail() - } - - if newSe.Addresses[0] != "1.2.3.4" { - t.Errorf("Address set incorrectly from cache, expected 1.2.3.4, got %v", newSe.Addresses[0]) - } -} - func TestAddServiceEntriesWithDr(t *testing.T) { admiralCache := AdmiralCache{} @@ -289,7 +243,7 @@ func TestCreateServiceEntryForNewServiceOrPod(t *testing.T) { KubeconfigPath: "testdata/fake.config", } rr, _ := InitAdmiral(context.Background(), p) - rr.StartTime = time.Now().Add(-60*time.Second) + rr.StartTime = time.Now().Add(-60 * time.Second) config := rest.Config{ Host: "localhost", @@ -876,7 +830,7 @@ func TestCreateServiceEntryForNewServiceOrPodRolloutsUsecase(t *testing.T) { rr, _ := InitAdmiral(context.Background(), p) - rr.StartTime = time.Now().Add(-60*time.Second) + rr.StartTime = time.Now().Add(-60 * time.Second) config := rest.Config{ Host: "localhost", @@ -1014,7 +968,7 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) { config := rest.Config{ Host: "localhost", } - rr.StartTime = time.Now().Add(-60*time.Second) + rr.StartTime = time.Now().Add(-60 * time.Second) d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300))