-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ad932
commit efaa128
Showing
40 changed files
with
1,177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.vscode | ||
.envrc | ||
exercises/istio/istio-* |
13 changes: 13 additions & 0 deletions
13
exercises/istio/advanced-lab1/hellovmservice-210121-161541.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: hello-vm | ||
labels: | ||
app: hello-vm | ||
spec: | ||
ports: | ||
- port: 80 | ||
name: http-vm | ||
targetPort: 80 | ||
selector: | ||
app: hello-vm |
36 changes: 36 additions & 0 deletions
36
exercises/istio/advanced-lab1/helloworld-210121-161541.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: hello-world | ||
labels: | ||
app: hello-world | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: hello-world | ||
template: | ||
metadata: | ||
labels: | ||
app: hello-world | ||
spec: | ||
containers: | ||
- image: gcr.io/tetratelabs/hello-world:1.0.0 | ||
imagePullPolicy: Always | ||
name: svc | ||
ports: | ||
- containerPort: 3000 | ||
--- | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: hello-world | ||
labels: | ||
app: hello-world | ||
spec: | ||
selector: | ||
app: hello-world | ||
ports: | ||
- port: 80 | ||
name: http | ||
targetPort: 3000 |
13 changes: 13 additions & 0 deletions
13
exercises/istio/advanced-lab1/workloadgroup-210121-161541.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: WorkloadGroup | ||
metadata: | ||
name: hello-vm | ||
namespace: vm-namespace | ||
spec: | ||
metadata: | ||
annotations: {} | ||
labels: | ||
app: hello-vm | ||
template: | ||
ports: {} | ||
serviceAccount: vm-sa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM scratch | ||
COPY main.wasm ./plugin.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: httpbin | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: httpbin | ||
labels: | ||
app: httpbin | ||
service: httpbin | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8000 | ||
targetPort: 80 | ||
selector: | ||
app: httpbin | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: httpbin | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: httpbin | ||
version: v1 | ||
template: | ||
metadata: | ||
labels: | ||
app: httpbin | ||
version: v1 | ||
spec: | ||
serviceAccountName: httpbin | ||
containers: | ||
- image: docker.io/kennethreitz/httpbin | ||
imagePullPolicy: IfNotPresent | ||
name: httpbin | ||
ports: | ||
- containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/valyala/fastjson" | ||
|
||
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" | ||
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" | ||
) | ||
|
||
func main() { | ||
proxywasm.SetVMContext(&vmContext{}) | ||
} | ||
|
||
// Override types.DefaultPluginContext. | ||
func (ctx pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { | ||
data, err := proxywasm.GetPluginConfiguration() | ||
if err != nil { | ||
proxywasm.LogCriticalf("error reading plugin configuration: %v", err) | ||
} | ||
|
||
var p fastjson.Parser | ||
v, err := p.ParseBytes(data) | ||
if err != nil { | ||
proxywasm.LogCriticalf("error parsing configuration: %v", err) | ||
} | ||
|
||
obj, err := v.Object() | ||
if err != nil { | ||
proxywasm.LogCriticalf("error getting object from json value: %v", err) | ||
} | ||
|
||
obj.Visit(func(k []byte, v *fastjson.Value) { | ||
ctx.additionalHeaders[string(k)] = string(v.GetStringBytes()) | ||
}) | ||
|
||
return types.OnPluginStartStatusOK | ||
} | ||
|
||
type vmContext struct { | ||
// Embed the default VM context here, | ||
// so that we don't need to reimplement all the methods. | ||
types.DefaultVMContext | ||
} | ||
|
||
// Override types.DefaultVMContext. | ||
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { | ||
return &pluginContext{contextID: contextID, additionalHeaders: map[string]string{}} | ||
} | ||
|
||
type pluginContext struct { | ||
// Embed the default plugin context here, | ||
// so that we don't need to reimplement all the methods. | ||
types.DefaultPluginContext | ||
additionalHeaders map[string]string | ||
contextID uint32 | ||
} | ||
|
||
// Override types.DefaultPluginContext. | ||
func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { | ||
proxywasm.LogInfo("NewHttpContext") | ||
return &httpContext{contextID: contextID, additionalHeaders: ctx.additionalHeaders} | ||
} | ||
|
||
type httpContext struct { | ||
// Embed the default http context here, | ||
// so that we don't need to reimplement all the methods. | ||
types.DefaultHttpContext | ||
contextID uint32 | ||
additionalHeaders map[string]string | ||
} | ||
|
||
func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { | ||
proxywasm.LogInfo("OnHttpResponseHeaders") | ||
|
||
for key, value := range ctx.additionalHeaders { | ||
if err := proxywasm.AddHttpResponseHeader(key, value); err != nil { | ||
proxywasm.LogCriticalf("failed to add header: %v", err) | ||
return types.ActionPause | ||
} | ||
proxywasm.LogInfof("header set: %s=%s", key, value) | ||
} | ||
|
||
return types.ActionContinue | ||
} |
13 changes: 13 additions & 0 deletions
13
exercises/istio/advanced-lab2/wasmplugin-230608-120141.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: extensions.istio.io/v1alpha1 | ||
kind: WasmPlugin | ||
metadata: | ||
name: wasm-example | ||
namespace: default | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: httpbin | ||
url: oci://$REPOSITORY/wasm:v1 | ||
pluginConfig: | ||
header_1: first_header | ||
header_2: second_header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Gateway | ||
metadata: | ||
name: gateway | ||
spec: | ||
selector: | ||
istio: ingressgateway | ||
servers: | ||
- port: | ||
number: 80 | ||
name: http | ||
protocol: HTTP | ||
hosts: | ||
- '*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: hello-world | ||
labels: | ||
app: hello-world | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: hello-world | ||
template: | ||
metadata: | ||
labels: | ||
app: hello-world | ||
spec: | ||
containers: | ||
- image: gcr.io/tetratelabs/hello-world:1.0.0 | ||
imagePullPolicy: Always | ||
name: svc | ||
ports: | ||
- containerPort: 3000 | ||
--- | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: hello-world | ||
labels: | ||
app: hello-world | ||
spec: | ||
selector: | ||
app: hello-world | ||
ports: | ||
- port: 80 | ||
name: http | ||
targetPort: 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: hello-world | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- gateway | ||
http: | ||
- route: | ||
- destination: | ||
host: hello-world.default.svc.cluster.local | ||
port: | ||
number: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: customers-v1 | ||
labels: | ||
app: customers | ||
version: v1 | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: customers | ||
version: v1 | ||
template: | ||
metadata: | ||
labels: | ||
app: customers | ||
version: v1 | ||
spec: | ||
containers: | ||
- image: gcr.io/tetratelabs/customers:1.0.0 | ||
imagePullPolicy: Always | ||
name: svc | ||
ports: | ||
- containerPort: 3000 | ||
--- | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: customers | ||
labels: | ||
app: customers | ||
spec: | ||
selector: | ||
app: customers | ||
ports: | ||
- port: 80 | ||
name: http | ||
targetPort: 3000 | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: DestinationRule | ||
metadata: | ||
name: customers | ||
spec: | ||
host: customers.default.svc.cluster.local | ||
subsets: | ||
- name: v1 | ||
labels: | ||
version: v1 | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: customers | ||
spec: | ||
hosts: | ||
- 'customers.default.svc.cluster.local' | ||
http: | ||
- route: | ||
- destination: | ||
host: customers.default.svc.cluster.local | ||
port: | ||
number: 80 | ||
subset: v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: customers | ||
spec: | ||
hosts: | ||
- 'customers.default.svc.cluster.local' | ||
http: | ||
- route: | ||
- destination: | ||
host: customers.default.svc.cluster.local | ||
port: | ||
number: 80 | ||
subset: v1 | ||
fault: | ||
delay: | ||
percent: 50 | ||
fixedDelay: 5s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: customers | ||
spec: | ||
hosts: | ||
- 'customers.default.svc.cluster.local' | ||
http: | ||
- route: | ||
- destination: | ||
host: customers.default.svc.cluster.local | ||
port: | ||
number: 80 | ||
subset: v1 | ||
fault: | ||
abort: | ||
httpStatus: 500 | ||
percentage: | ||
value: 50 |
Oops, something went wrong.