Skip to content

Commit

Permalink
Merge pull request #238 from utkarsh-pro/utkarsh-pro/feature/envoy-fi…
Browse files Browse the repository at this point in the history
…lter

Add support for Envoy Filter
  • Loading branch information
leecalcote authored Jun 21, 2021
2 parents 837b352 + 8955835 commit fa47813
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 13 deletions.
12 changes: 6 additions & 6 deletions istio/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ var (
// generated when kubernetes client is nil
ErrNilClientCode = "istio_test_code"

// ErrParseVirtualServiceCode represents the error code which is
// generated when virtual service parsing fails
ErrParseVirtualServiceCode = "istio_test_code"
// ErrParseIstioCoreComponentCode represents the error code which is
// generated when istio core component manifest parsing fails
ErrParseIstioCoreComponentCode = "istio_test_code"

// ErrInvalidOAMComponentTypeCode represents the error code which is
// generated when an invalid oam component is requested
Expand Down Expand Up @@ -191,9 +191,9 @@ func ErrIstioVet(err error) error {
return errors.NewDefault(ErrIstioVetCode, err.Error())
}

// ErrParseVirtualService is the error when vsc parsing fails
func ErrParseVirtualService(err error) error {
return errors.NewDefault(ErrParseVirtualServiceCode, err.Error())
// ErrParseIstioCoreComponent is the error when istio core component manifest parsing fails
func ErrParseIstioCoreComponent(err error) error {
return errors.NewDefault(ErrParseIstioCoreComponentCode, err.Error())
}

// ErrInvalidOAMComponentType is the error when the OAM component name is not valid
Expand Down
28 changes: 21 additions & 7 deletions istio/oam.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (istio *Istio) HandleComponents(comps []v1alpha1.Component, isDel bool) (st
compFuncMap := map[string]CompHandler{
"IstioMesh": handleComponentIstioMesh,
"VirtualService": handleComponentVirtualService,
"EnvoyFilterIstio": handleComponentEnvoyFilter,
"GrafanaIstioAddon": handleComponentIstioAddon,
"PrometheusIstioAddon": handleComponentIstioAddon,
"ZipkinIstioAddon": handleComponentIstioAddon,
Expand Down Expand Up @@ -117,9 +118,22 @@ func handleComponentIstioMesh(istio *Istio, comp v1alpha1.Component, isDel bool)
}

func handleComponentVirtualService(istio *Istio, comp v1alpha1.Component, isDel bool) (string, error) {
virtualSvc := map[string]interface{}{
"apiVersion": "networking.istio.io/v1beta1",
"kind": "VirtualService",
return handleIstioCoreComponent(istio, comp, isDel, "networking.istio.io/v1beta1", "VirtualService")
}

func handleComponentEnvoyFilter(istio *Istio, comp v1alpha1.Component, isDel bool) (string, error) {
return handleIstioCoreComponent(istio, comp, isDel, "networking.istio.io/v1alpha3", "EnvoyFilter")
}

func handleIstioCoreComponent(
istio *Istio,
comp v1alpha1.Component,
isDel bool,
apiVersion,
kind string) (string, error) {
component := map[string]interface{}{
"apiVersion": apiVersion,
"kind": kind,
"metadata": map[string]interface{}{
"name": comp.Name,
"annotations": comp.Annotations,
Expand All @@ -129,16 +143,16 @@ func handleComponentVirtualService(istio *Istio, comp v1alpha1.Component, isDel
}

// Convert to yaml
yamlByt, err := yaml.Marshal(virtualSvc)
yamlByt, err := yaml.Marshal(component)
if err != nil {
err = ErrParseVirtualService(err)
err = ErrParseIstioCoreComponent(err)
istio.Log.Error(err)
return "", err
}

msg := fmt.Sprintf("created virtual service \"%s\" in namespace \"%s\"", comp.Name, comp.Namespace)
msg := fmt.Sprintf("created %s \"%s\" in namespace \"%s\"", kind, comp.Name, comp.Namespace)
if isDel {
msg = fmt.Sprintf("deleted virtual service \"%s\" in namespace \"%s\"", comp.Name, comp.Namespace)
msg = fmt.Sprintf("deleted %s config \"%s\" in namespace \"%s\"", kind, comp.Name, comp.Namespace)
}

return msg, istio.applyManifest(yamlByt, isDel, comp.Namespace)
Expand Down
1 change: 1 addition & 0 deletions istio/oam/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func RegisterWorkloads(runtime, host string) error {
"zipkinistioaddon",
"jaegeristioaddon",
"virtualservice",
"envoyfilter",
}

oamRDP := []adapter.OAMRegistrantDefinitionPath{}
Expand Down
278 changes: 278 additions & 0 deletions templates/oam/workloads/envoyfilter.meshery.layer5.io.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
{
"description": "Customizing Envoy configuration generated by Istio. See more details at: https://istio.io/docs/reference/config/networking/envoy-filter.html",
"properties": {
"configPatches": {
"description": "One or more patches with match conditions.",
"items": {
"properties": {
"applyTo": {
"enum": [
"INVALID",
"LISTENER",
"FILTER_CHAIN",
"NETWORK_FILTER",
"HTTP_FILTER",
"ROUTE_CONFIGURATION",
"VIRTUAL_HOST",
"HTTP_ROUTE",
"CLUSTER",
"EXTENSION_CONFIG"
],
"type": "string"
},
"match": {
"description": "Match on listener/route configuration/cluster.",
"oneOf": [
{
"not": {
"anyOf": [
{
"required": ["listener"]
},
{
"required": ["routeConfiguration"]
},
{
"required": ["cluster"]
}
]
}
},
{
"required": ["listener"]
},
{
"required": ["routeConfiguration"]
},
{
"required": ["cluster"]
}
],
"properties": {
"cluster": {
"description": "Match on envoy cluster attributes.",
"properties": {
"name": {
"description": "The exact name of the cluster to match.",
"format": "string",
"type": "string"
},
"portNumber": {
"description": "The service port for which this cluster was generated.",
"type": "integer"
},
"service": {
"description": "The fully qualified service name for this cluster.",
"format": "string",
"type": "string"
},
"subset": {
"description": "The subset associated with the service.",
"format": "string",
"type": "string"
}
},
"type": "object"
},
"context": {
"description": "The specific config generation context to match on.",
"enum": [
"ANY",
"SIDECAR_INBOUND",
"SIDECAR_OUTBOUND",
"GATEWAY"
],
"type": "string"
},
"listener": {
"description": "Match on envoy listener attributes.",
"properties": {
"filterChain": {
"description": "Match a specific filter chain in a listener.",
"properties": {
"applicationProtocols": {
"description": "Applies only to sidecars.",
"format": "string",
"type": "string"
},
"destinationPort": {
"description": "The destination_port value used by a filter chain's match condition.",
"type": "integer"
},
"filter": {
"description": "The name of a specific filter to apply the patch to.",
"properties": {
"name": {
"description": "The filter name to match on.",
"format": "string",
"type": "string"
},
"subFilter": {
"properties": {
"name": {
"description": "The filter name to match on.",
"format": "string",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"name": {
"description": "The name assigned to the filter chain.",
"format": "string",
"type": "string"
},
"sni": {
"description": "The SNI value used by a filter chain's match condition.",
"format": "string",
"type": "string"
},
"transportProtocol": {
"description": "Applies only to `SIDECAR_INBOUND` context.",
"format": "string",
"type": "string"
}
},
"type": "object"
},
"name": {
"description": "Match a specific listener by its name.",
"format": "string",
"type": "string"
},
"portName": {
"format": "string",
"type": "string"
},
"portNumber": {
"type": "integer"
}
},
"type": "object"
},
"proxy": {
"description": "Match on properties associated with a proxy.",
"properties": {
"metadata": {
"additionalProperties": {
"format": "string",
"type": "string"
},
"type": "object"
},
"proxyVersion": {
"format": "string",
"type": "string"
}
},
"type": "object"
},
"routeConfiguration": {
"description": "Match on envoy HTTP route configuration attributes.",
"properties": {
"gateway": {
"format": "string",
"type": "string"
},
"name": {
"description": "Route configuration name to match on.",
"format": "string",
"type": "string"
},
"portName": {
"description": "Applicable only for GATEWAY context.",
"format": "string",
"type": "string"
},
"portNumber": {
"type": "integer"
},
"vhost": {
"properties": {
"name": {
"format": "string",
"type": "string"
},
"route": {
"description": "Match a specific route within the virtual host.",
"properties": {
"action": {
"description": "Match a route with specific action type.",
"enum": [
"ANY",
"ROUTE",
"REDIRECT",
"DIRECT_RESPONSE"
],
"type": "string"
},
"name": {
"format": "string",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
},
"patch": {
"description": "The patch to apply along with the operation.",
"properties": {
"filterClass": {
"description": "Determines the filter insertion order.",
"enum": ["UNSPECIFIED", "AUTHN", "AUTHZ", "STATS"],
"type": "string"
},
"operation": {
"description": "Determines how the patch should be applied.",
"enum": [
"INVALID",
"MERGE",
"ADD",
"REMOVE",
"INSERT_BEFORE",
"INSERT_AFTER",
"INSERT_FIRST",
"REPLACE"
],
"type": "string"
},
"value": {
"description": "The JSON config of the object being patched.",
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
},
"type": "array"
},
"workloadSelector": {
"properties": {
"labels": {
"additionalProperties": {
"format": "string",
"type": "string"
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Envoy Filter"
}
12 changes: 12 additions & 0 deletions templates/oam/workloads/envoyfilter_definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apiVersion": "core.oam.dev/v1alpha1",
"kind": "WorkloadDefinition",
"metadata": {
"name": "EnvoyFilterIstio"
},
"spec": {
"definitionRef": {
"name": "envoyfilter.meshery.layer5.io"
}
}
}

0 comments on commit fa47813

Please sign in to comment.