Skip to content

Commit

Permalink
Adding constant and paramters for envoy filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygonuguntla committed Jul 12, 2022
1 parent 4abc3e1 commit cc4ca43
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion admiral/cmd/admiral/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func GetRootCmd(args []string) *cobra.Command {
rootCmd.PersistentFlags().StringVar(&params.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(&params.MetricsEnabled, "metrics", true, "Enable prometheus metrics collections")

rootCmd.PersistentFlags().StringVar(&params.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
}

Expand Down
17 changes: 12 additions & 5 deletions admiral/pkg/clusters/envoyfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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}},
}}}},
}}}},
},
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -152,6 +160,5 @@ func constructEnvoyFilterStruct(routingPolicy *v1.RoutingPolicy, workloadSelecto
},
},
}
return envoyfilterSpec
}

2 changes: 1 addition & 1 deletion admiral/pkg/clusters/envoyfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/clusters/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions admiral/pkg/controller/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
RolloutPodHashLabel = "rollouts-pod-template-hash"
RolloutActiveServiceSuffix = "active-service"
RolloutStableServiceSuffix = "stable-service"
EnvoyFilterSuffix = "1.13"
)

type Event int
Expand Down
4 changes: 4 additions & 0 deletions admiral/pkg/controller/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func GetWorkloadSidecarUpdate() string {
return admiralParams.WorkloadSidecarUpdate
}

func GetEnvoyFilterVersion() string {
return admiralParams.EnvoyFilterVersion
}

func GetWorkloadSidecarName() string {
return admiralParams.WorkloadSidecarName
}
Expand Down
1 change: 1 addition & 0 deletions admiral/pkg/controller/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type AdmiralParams struct {
MetricsEnabled bool
WorkloadSidecarUpdate string
WorkloadSidecarName string
EnvoyFilterVersion string
}

func (b AdmiralParams) String() string {
Expand Down

0 comments on commit cc4ca43

Please sign in to comment.