diff --git a/.github/workflows/golang-ci-lint.yml b/.github/workflows/golang-ci-lint.yml index 0e12e1e1..5629e64a 100644 --- a/.github/workflows/golang-ci-lint.yml +++ b/.github/workflows/golang-ci-lint.yml @@ -20,7 +20,7 @@ jobs: uses: golangci/golangci-lint-action@v2 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.43.0 + version: v1.47.3 skip-go-installation: true # Optional: working directory, useful for monorepos diff --git a/admiral/pkg/clusters/envoyfilter.go b/admiral/pkg/clusters/envoyfilter.go index 82eb625d..186748ed 100644 --- a/admiral/pkg/clusters/envoyfilter.go +++ b/admiral/pkg/clusters/envoyfilter.go @@ -1,6 +1,7 @@ package clusters import ( + "errors" "fmt" "github.com/gogo/protobuf/types" v1 "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1" @@ -11,7 +12,6 @@ import ( networking "istio.io/client-go/pkg/apis/networking/v1alpha3" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" - "errors" ) var ( @@ -177,9 +177,7 @@ func getHosts(routingPolicy *v1.RoutingPolicy) string { for _, host := range routingPolicy.Spec.Hosts { hosts += host + "," } - if strings.HasSuffix(hosts, ",") { - hosts = hosts[:len(hosts)-len(",")] - } + hosts = strings.TrimSuffix(hosts,",") return hostsKey + hosts } diff --git a/admiral/pkg/clusters/envoyfilter_test.go b/admiral/pkg/clusters/envoyfilter_test.go index 8d2d8f40..f4a44fa8 100644 --- a/admiral/pkg/clusters/envoyfilter_test.go +++ b/admiral/pkg/clusters/envoyfilter_test.go @@ -30,6 +30,7 @@ func TestCreateOrUpdateEnvoyFilter(t *testing.T) { ClusterRegistriesNamespace: "default", DependenciesNamespace: "default", SecretResolver: "", + EnvoyFilterVersion: "1.13", } p.LabelSet.WorkloadIdentityKey = "identity" @@ -51,7 +52,7 @@ func TestCreateOrUpdateEnvoyFilter(t *testing.T) { remoteController.RoutingPolicyController = routingPolicyController - registry.RemoteControllers = map[string]*RemoteController{"cluster-1": remoteController} + registry.remoteControllers = map[string]*RemoteController{"cluster-1": remoteController} registry.AdmiralCache.RoutingPolicyFilterCache = rpFilterCache // foo is dependent upon bar and bar has a deployment in the same cluster. diff --git a/admiral/pkg/clusters/registry_test.go b/admiral/pkg/clusters/registry_test.go index 70250b65..d51a5f5a 100644 --- a/admiral/pkg/clusters/registry_test.go +++ b/admiral/pkg/clusters/registry_test.go @@ -36,6 +36,8 @@ func init() { SecretResolver: "", WorkloadSidecarUpdate: "enabled", WorkloadSidecarName: "default", + EnableRoutingPolicy: true, + EnvoyFilterVersion: "1.13", } p.LabelSet.WorkloadIdentityKey = "identity" diff --git a/admiral/pkg/clusters/serviceentry_test.go b/admiral/pkg/clusters/serviceentry_test.go index 8c0fc465..ed7f46d4 100644 --- a/admiral/pkg/clusters/serviceentry_test.go +++ b/admiral/pkg/clusters/serviceentry_test.go @@ -908,6 +908,7 @@ func TestCreateServiceEntryForNewServiceOrPodRolloutsUsecase(t *testing.T) { GlobalTrafficCache: &globalTrafficCache{}, DependencyNamespaceCache: common.NewSidecarEgressMap(), SeClusterCache: common.NewMapOfMaps(), + WorkloadSelectorCache: common.NewMapOfMaps(), } rr.AdmiralCache = admiralCache @@ -1044,6 +1045,7 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) { GlobalTrafficCache: &globalTrafficCache{}, DependencyNamespaceCache: common.NewSidecarEgressMap(), SeClusterCache: common.NewMapOfMaps(), + WorkloadSelectorCache: common.NewMapOfMaps(), } rr.AdmiralCache = admiralCache diff --git a/admiral/pkg/clusters/types_test.go b/admiral/pkg/clusters/types_test.go index 503f5248..d6ced9e3 100644 --- a/admiral/pkg/clusters/types_test.go +++ b/admiral/pkg/clusters/types_test.go @@ -36,6 +36,8 @@ func init() { ClusterRegistriesNamespace: "default", DependenciesNamespace: "default", SecretResolver: "", + EnableRoutingPolicy: true, + EnvoyFilterVersion: "1.13", } p.LabelSet.WorkloadIdentityKey = "identity" @@ -277,6 +279,8 @@ func TestRoutingPolicyHandler(t *testing.T) { ClusterRegistriesNamespace: "default", DependenciesNamespace: "default", SecretResolver: "", + EnableRoutingPolicy: true, + EnvoyFilterVersion: "1.13", } p.LabelSet.WorkloadIdentityKey = "identity" @@ -298,7 +302,7 @@ func TestRoutingPolicyHandler(t *testing.T) { }) remoteController.RoutingPolicyController = routingPolicyController - registry.RemoteControllers = map[string]*RemoteController{"cluster-1": remoteController} + registry.remoteControllers = map[string]*RemoteController{"cluster-1": remoteController} registry.AdmiralCache.RoutingPolicyFilterCache = rpFilterCache // foo is dependent upon bar and bar has a deployment in the same cluster. @@ -313,6 +317,10 @@ func TestRoutingPolicyHandler(t *testing.T) { // foo1 is dependent upon bar 1 but bar1 does not have a deployment so it is missing from identityClusterCache registry.AdmiralCache.IdentityDependencyCache.Put("foo1", "bar1", "bar1") + var mp = common.NewMap() + mp.Put("k1","v1") + registry.AdmiralCache.WorkloadSelectorCache.PutMap("bar"+remoteController.ClusterID, mp) + registry.AdmiralCache.WorkloadSelectorCache.PutMap("bar2differentCluster", mp) handler.RemoteRegistry = registry @@ -337,6 +345,7 @@ func TestRoutingPolicyHandler(t *testing.T) { Status: v1.RoutingPolicyStatus{}, } + routingPolicyFoo1 := routingPolicyFoo.DeepCopy() routingPolicyFoo1.Labels[common.GetWorkloadIdentifier()] = "foo1" @@ -369,6 +378,7 @@ func TestRoutingPolicyHandler(t *testing.T) { } + time.Sleep(time.Second*30) for _, c := range testCases { t.Run(c.name, func(t *testing.T) { handler.Added(c.routingPolicy) @@ -379,7 +389,7 @@ func TestRoutingPolicyHandler(t *testing.T) { if err != nil { t.Error("Error ocurred while computing workload Labels sha1") } - envoyFilterName := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(c.routingPolicy.Spec.Plugin), selectorLabelsSha, "1.10") + envoyFilterName := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(c.routingPolicy.Spec.Plugin), selectorLabelsSha, "1.13") filterMap := filterCacheValue[remoteController.ClusterID] assert.NotNil(t, filterMap) assert.NotNil(t, filterMap[envoyFilterName]) @@ -394,17 +404,19 @@ func TestRoutingPolicyHandler(t *testing.T) { }) } + + // Test for multiple filters registry.AdmiralCache.IdentityDependencyCache.Put("foo", "bar3", "bar3") registry.AdmiralCache.IdentityClusterCache.Put("bar3", remoteController.ClusterID, remoteController.ClusterID) - + registry.AdmiralCache.WorkloadSelectorCache.PutMap("bar3"+remoteController.ClusterID, mp) handler.Added(routingPolicyFoo) selectorLabelsShaBar3, err := common.GetSha1("bar3"+common.GetRoutingPolicyEnv(routingPolicyFoo)) if err != nil { t.Error("Error ocurred while computing workload Labels sha1") } - envoyFilterNameBar3 := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicyFoo.Spec.Plugin), selectorLabelsShaBar3, "1.10") + envoyFilterNameBar3 := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicyFoo.Spec.Plugin), selectorLabelsShaBar3, "1.13") filterCacheValue := registry.AdmiralCache.RoutingPolicyFilterCache.Get("bar3stage") assert.NotNil(t, filterCacheValue) @@ -415,13 +427,14 @@ func TestRoutingPolicyHandler(t *testing.T) { registry.AdmiralCache.IdentityDependencyCache.Put("foo", "bar4", "bar4") registry.AdmiralCache.IdentityClusterCache.Put("bar4", remoteController.ClusterID, remoteController.ClusterID) + registry.AdmiralCache.WorkloadSelectorCache.PutMap("bar4"+remoteController.ClusterID, mp) handler.Updated(routingPolicyFoo) selectorLabelsShaBar4, err := common.GetSha1("bar4"+common.GetRoutingPolicyEnv(routingPolicyFoo)) if err != nil { t.Error("Error ocurred while computing workload Labels sha1") } - envoyFilterNameBar4 := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicyFoo.Spec.Plugin), selectorLabelsShaBar4, "1.10") + envoyFilterNameBar4 := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicyFoo.Spec.Plugin), selectorLabelsShaBar4, "1.13") filterCacheValue = registry.AdmiralCache.RoutingPolicyFilterCache.Get("bar4stage") assert.NotNil(t, filterCacheValue) diff --git a/admiral/pkg/controller/common/common_test.go b/admiral/pkg/controller/common/common_test.go index 775745ba..6eba18da 100644 --- a/admiral/pkg/controller/common/common_test.go +++ b/admiral/pkg/controller/common/common_test.go @@ -30,6 +30,8 @@ func init() { WorkloadSidecarName: "default", WorkloadSidecarUpdate: "disabled", MetricsEnabled: true, + EnableRoutingPolicy: true, + EnvoyFilterVersion: "1.13", } p.LabelSet.WorkloadIdentityKey = "identity" diff --git a/admiral/pkg/controller/common/types.go b/admiral/pkg/controller/common/types.go index cf7fc45b..f1e0e9e0 100644 --- a/admiral/pkg/controller/common/types.go +++ b/admiral/pkg/controller/common/types.go @@ -64,7 +64,9 @@ func (b AdmiralParams) String() string { fmt.Sprintf("SecretResolver=%v ", b.SecretResolver) + fmt.Sprintf("AdmiralStateCheckername=%v ", b.AdmiralStateCheckerName) + fmt.Sprintf("DRStateStoreConfigPath=%v ", b.DRStateStoreConfigPath) + - fmt.Sprintf("ServiceEntryIPPrefix=%v ", b.ServiceEntryIPPrefix) + fmt.Sprintf("ServiceEntryIPPrefix=%v ", b.ServiceEntryIPPrefix) + + fmt.Sprintf("EnvoyFilterVersion=%v ", b.EnvoyFilterVersion) + + fmt.Sprintf("EnableRoutingPolicy=%v ", b.EnableRoutingPolicy) } type LabelSet struct {