diff --git a/admiral/cmd/admiral/cmd/root.go b/admiral/cmd/admiral/cmd/root.go index d34462a5..d47e1fe7 100644 --- a/admiral/cmd/admiral/cmd/root.go +++ b/admiral/cmd/admiral/cmd/root.go @@ -131,7 +131,8 @@ func GetRootCmd(args []string) *cobra.Command { rootCmd.PersistentFlags().StringVar(¶ms.LabelSet.GatewayApp, "gateway_app", "istio-ingressgateway", "The the value of the `app` label to use to match and find the service that represents the ingress for cross cluster traffic (AUTO_PASSTHROUGH mode)") rootCmd.PersistentFlags().BoolVar(¶ms.MetricsEnabled, "metrics", true, "Enable prometheus metrics collections") - + rootCmd.PersistentFlags().StringVar(¶ms.EnvoyFilterVersion, "envoy_filter_version", "^1\\.10|3.*", + "The value of envoy filter version is used to match the proxy version for envoy filter created by routing policy") return rootCmd } diff --git a/admiral/pkg/clusters/envoyfilter.go b/admiral/pkg/clusters/envoyfilter.go index 18afea71..b5257ccf 100644 --- a/admiral/pkg/clusters/envoyfilter.go +++ b/admiral/pkg/clusters/envoyfilter.go @@ -16,6 +16,8 @@ import ( var ( getSha1 = common.GetSha1 ) +const wasmPath = "/etc/istio/extensions/dynamicrouter.wasm" + func createOrUpdateEnvoyFilter( rc *RemoteController, routingPolicy *v1.RoutingPolicy, eventType admiral.EventType, workloadIdentityKey string, admiralCache *AdmiralCache) (*networking.EnvoyFilter, error) { workloadSelectors := make(map[string]string) @@ -29,7 +31,7 @@ func createOrUpdateEnvoyFilter( rc *RemoteController, routingPolicy *v1.RoutingP log.Error("error ocurred while computing workload labels sha1") return nil, err } - envoyFilterName := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicy.Spec.Plugin), selectorLabelsSha, "1.10") + envoyFilterName := fmt.Sprintf("%s-dynamicrouting-%s-%s", strings.ToLower(routingPolicy.Spec.Plugin), selectorLabelsSha, common.EnvoyFilterSuffix) envoyfilter := &networking.EnvoyFilter{ TypeMeta: metaV1.TypeMeta{ Kind: "EnvoyFilter", @@ -78,12 +80,13 @@ func constructEnvoyFilterStruct(routingPolicy *v1.RoutingPolicy, workloadSelecto }, } + vmConfig := types.Struct{ Fields: map[string]*types.Value{ "runtime": {Kind: &types.Value_StringValue{StringValue: "envoy.wasm.runtime.v8"}}, "code": {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{ "local": {Kind: &types.Value_StructValue{StructValue: &types.Struct{Fields: map[string]*types.Value{ - "filename": {Kind: &types.Value_StringValue{StringValue: "/etc/istio/extensions/dynamicrouter.wasm"}}, + "filename": {Kind: &types.Value_StringValue{StringValue: wasmPath}}, }}}}, }}}}, }, @@ -112,7 +115,12 @@ func constructEnvoyFilterStruct(routingPolicy *v1.RoutingPolicy, workloadSelecto }, } - envoyfilterSpec := &v1alpha3.EnvoyFilter{ + envoyfilterSpec := getEnvoyFilterSpec(workloadSelectorLabels, typedConfig) + return envoyfilterSpec +} + +func getEnvoyFilterSpec(workloadSelectorLabels map[string]string, typedConfig types.Struct) *v1alpha3.EnvoyFilter { + return &v1alpha3.EnvoyFilter{ WorkloadSelector: &v1alpha3.WorkloadSelector{Labels: workloadSelectorLabels}, ConfigPatches: []*v1alpha3.EnvoyFilter_EnvoyConfigObjectPatch{ @@ -121,7 +129,7 @@ func constructEnvoyFilterStruct(routingPolicy *v1.RoutingPolicy, workloadSelecto Match: &v1alpha3.EnvoyFilter_EnvoyConfigObjectMatch{ Context: v1alpha3.EnvoyFilter_SIDECAR_OUTBOUND, // TODO: Figure out the possibility of using this for istio version upgrades. Can we add multiple filters with different proxy version Match here? - Proxy: &v1alpha3.EnvoyFilter_ProxyMatch{ProxyVersion: `^1\.10.*`}, + Proxy: &v1alpha3.EnvoyFilter_ProxyMatch{ProxyVersion: common.GetEnvoyFilterVersion()}, ObjectTypes: &v1alpha3.EnvoyFilter_EnvoyConfigObjectMatch_Listener{ Listener: &v1alpha3.EnvoyFilter_ListenerMatch{ FilterChain: &v1alpha3.EnvoyFilter_ListenerMatch_FilterChainMatch{ @@ -152,6 +160,5 @@ func constructEnvoyFilterStruct(routingPolicy *v1.RoutingPolicy, workloadSelecto }, }, } - return envoyfilterSpec } diff --git a/admiral/pkg/clusters/envoyfilter_test.go b/admiral/pkg/clusters/envoyfilter_test.go index baea26a3..f4230df1 100644 --- a/admiral/pkg/clusters/envoyfilter_test.go +++ b/admiral/pkg/clusters/envoyfilter_test.go @@ -94,7 +94,7 @@ func TestCreateOrUpdateEnvoyFilter(t *testing.T) { envoyfilter, err = createOrUpdateEnvoyFilter(remoteController, routingPolicyFoo, admiral.Add, "bar", registry.AdmiralCache) assert.Equal(t, "bar", envoyfilter.Spec.WorkloadSelector.GetLabels()["identity"]) assert.Equal(t, "stage", envoyfilter.Spec.WorkloadSelector.GetLabels()["admiral.io/env"]) - assert.Equal(t, "test-dynamicrouting-d0fdd-1.10", envoyfilter.Name) + assert.Equal(t, "test-dynamicrouting-d0fdd-1.13", envoyfilter.Name) envoyfilter, err = createOrUpdateEnvoyFilter(remoteController, routingPolicyFoo, admiral.Update, "bar", registry.AdmiralCache) assert.Nil(t, err) diff --git a/admiral/pkg/clusters/registry.go b/admiral/pkg/clusters/registry.go index 24f0fb82..5d016be1 100644 --- a/admiral/pkg/clusters/registry.go +++ b/admiral/pkg/clusters/registry.go @@ -199,7 +199,7 @@ func (r *RemoteRegistry) createCacheController(clientConfig *rest.Config, cluste rc.RoutingPolicyController, err = admiral.NewRoutingPoliciesController(stop, &RoutingPolicyHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, 1 * time.Minute) if err != nil { - return fmt.Errorf("error with VirtualServiceController init: %v", err) + return fmt.Errorf("error with virtualServiceController init: %v", err) } log.Infof("starting node controller clusterID: %v", clusterID) diff --git a/admiral/pkg/controller/common/common.go b/admiral/pkg/controller/common/common.go index d3750bc9..c9d036e5 100644 --- a/admiral/pkg/controller/common/common.go +++ b/admiral/pkg/controller/common/common.go @@ -42,6 +42,7 @@ const ( RolloutPodHashLabel = "rollouts-pod-template-hash" RolloutActiveServiceSuffix = "active-service" RolloutStableServiceSuffix = "stable-service" + EnvoyFilterSuffix = "1.13" ) type Event int diff --git a/admiral/pkg/controller/common/config.go b/admiral/pkg/controller/common/config.go index 4dd342ab..3396d645 100644 --- a/admiral/pkg/controller/common/config.go +++ b/admiral/pkg/controller/common/config.go @@ -88,6 +88,10 @@ func GetWorkloadSidecarUpdate() string { return admiralParams.WorkloadSidecarUpdate } +func GetEnvoyFilterVersion() string { + return admiralParams.EnvoyFilterVersion +} + func GetWorkloadSidecarName() string { return admiralParams.WorkloadSidecarName } diff --git a/admiral/pkg/controller/common/types.go b/admiral/pkg/controller/common/types.go index 91e20a26..200e3ae8 100644 --- a/admiral/pkg/controller/common/types.go +++ b/admiral/pkg/controller/common/types.go @@ -45,6 +45,7 @@ type AdmiralParams struct { MetricsEnabled bool WorkloadSidecarUpdate string WorkloadSidecarName string + EnvoyFilterVersion string } func (b AdmiralParams) String() string {