Skip to content

Commit

Permalink
Merge pull request #133 from layer5io/kumarabd/feature/labs
Browse files Browse the repository at this point in the history
envoy filter
  • Loading branch information
kumarabd authored Oct 14, 2020
2 parents d95c2fe + f0e267c commit 1efc4ae
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 19 deletions.
42 changes: 42 additions & 0 deletions istio/config_templates/imagehub-filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: imagehub-filter
spec:
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND # will match inbound listeners in all sidecars
proxy:
proxyVersion: '^1\.7.*'
listener:
portNumber: 9091
filterChain:
filter:
name: envoy.http_connection_manager
subFilter:
name: envoy.router
patch:
operation: INSERT_BEFORE
value:
name: envoy.filter.http.wasm
typed_config:
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
value:
config:
configuration:
'@type': type.googleapis.com/google.protobuf.StringValue
value: "rate_limit_filter"
root_id: "rate_limit_filter"
vmConfig:
code:
local:
filename: "/var/lib/imagehub/filter.wasm"
runtime: envoy.wasm.runtime.v8
vmId: rate_limit_filter
allow_precompiled: true
workloadSelector:
labels:
app: api
version: v1
30 changes: 30 additions & 0 deletions istio/config_templates/imagehub-gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: imagehub-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: imagehub
spec:
hosts:
- "*"
gateways:
- imagehub-gateway
http:
- route:
- destination:
host: api
port:
number: 9091
42 changes: 42 additions & 0 deletions istio/config_templates/imagehub-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"spec": {
"template": {
"metadata": {
"annotations": {
"sidecar.istio.io/userVolumeMount": "[{\"mountPath\":\"/var/lib/imagehub\",\"name\":\"wasm-filter\"}]"
}
},
"spec": {
"initContainers": [
{
"command": [
"curl",
"-L",
"-o",
"/var/lib/imagehub/filter.wasm",
"https://github.com/layer5io/advanced-istio-service-mesh-workshop/raw/master/lab-7/ratelimiter/ratelimit-filter.wasm"
],
"image": "curlimages/curl",
"imagePullPolicy": "Always",
"name": "add-wasm",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/lib/imagehub",
"name": "wasm-filter"
}
]
}
],
"volumes": [
{
"emptyDir": {},
"name": "wasm-filter"
}
]
}
}
}
}
112 changes: 112 additions & 0 deletions istio/config_templates/imagehub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Copyright Layer5 Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
apiVersion: v1
kind: Service
metadata:
name: api
labels:
app: api
service: api
spec:
ports:
- port: 9091
name: http
selector:
app: api
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: imagehub-api
labels:
account: api
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-v1
labels:
app: api
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: api
version: v1
template:
metadata:
labels:
app: api
version: v1
spec:
serviceAccountName: imagehub-api
containers:
- name: api
image: layer5/image-hub-api:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9091
volumes:
- name: wasm-filter
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: web
labels:
app: web
service: web
spec:
ports:
- port: 8080
name: http
selector:
app: web
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: imagehub-web
labels:
account: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-v1
labels:
app: web
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: web
version: v1
template:
metadata:
labels:
app: web
version: v1
spec:
serviceAccountName: imagehub-web
containers:
- name: web
image: layer5/image-hub-web:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
45 changes: 45 additions & 0 deletions istio/install-istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ var (
jaegerInstallFile = path.Join(homepath, "config_templates/addons/jaeger.yaml")
zipkinInstallFile = path.Join(homepath, "config_templates/addons/extras/zipkin.yaml")
operatorInstallFile = path.Join(basePath, "samples/addons/extras/prometheus-operator.yaml")

imagehubInstallFile = path.Join(homepath, "config_templates/imagehub.yaml")
imagehubGatewayInstallFile = path.Join(homepath, "config_templates/imagehub-gateway.yaml")
imagehubEnvoyFilterFile = path.Join(homepath, "config_templates/imagehub-filter.yaml")
imagehubFilterPatchFile = path.Join(homepath, "config_templates/imagehub-patch.json")
)

type apiInfo struct {
Expand Down Expand Up @@ -420,6 +425,26 @@ func (iClient *Client) getPolicyYaml(template string) (string, error) {
return string(fileContents), nil
}

func (iClient *Client) getEnvoyFilterYAML() (string, error) {
fileContents, err := ioutil.ReadFile(imagehubEnvoyFilterFile)
if err != nil {
err = errors.Wrap(err, "unable to read file")
logrus.Error(err)
return "", err
}
return string(fileContents), nil
}

func (iClient *Client) getFilterPatchJSON() (string, error) {
fileContents, err := ioutil.ReadFile(imagehubFilterPatchFile)
if err != nil {
err = errors.Wrap(err, "unable to read file")
logrus.Error(err)
return "", err
}
return string(fileContents), nil
}

func (iClient *Client) getBookinfoDrYAML(template string) (string, error) {
fileContents, err := ioutil.ReadFile(fmt.Sprintf("%s/config_templates/%s", homepath, template))
if err != nil {
Expand Down Expand Up @@ -490,6 +515,26 @@ func (iClient *Client) getOperatorYAML() (string, error) {
return string(fileContents), nil
}

func (iClient *Client) getImagehubAppYAML() (string, error) {
fileContents, err := ioutil.ReadFile(imagehubInstallFile)
if err != nil {
err = errors.Wrap(err, "unable to read file")
logrus.Error(err)
return "", err
}
return string(fileContents), nil
}

func (iClient *Client) getImagehubGatewayYAML() (string, error) {
fileContents, err := ioutil.ReadFile(imagehubGatewayInstallFile)
if err != nil {
err = errors.Wrap(err, "unable to read file")
logrus.Error(err)
return "", err
}
return string(fileContents), nil
}

func (iClient *Client) getLatestIstioYAML() (string, error) {
return iClient.getIstioComponentYAML(installWithmTLSFile)
}
Expand Down
Loading

0 comments on commit 1efc4ae

Please sign in to comment.