Skip to content

Commit

Permalink
feat: Update examples for Tanzu Sources for Knative
Browse files Browse the repository at this point in the history
Closes: vmware-samples#1073
Signed-off-by: William Lam <[email protected]>
  • Loading branch information
William Lam committed Aug 4, 2023
1 parent 8a07c4f commit 1cd0e39
Show file tree
Hide file tree
Showing 65 changed files with 84 additions and 153 deletions.
4 changes: 2 additions & 2 deletions examples/knative/go/kn-go-nsx-tag-sync/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
broker: default
filter:
attributes:
subject: com.vmware.cis.tagging.attach
subject: com.vmware.vsphere.com.vmware.cis.tagging.attach.v0
subscriber:
ref:
apiVersion: v1
Expand All @@ -80,7 +80,7 @@ spec:
broker: default
filter:
attributes:
subject: com.vmware.cis.tagging.detach
subject: com.vmware.vsphere.com.vmware.cis.tagging.detach.v0
subscriber:
ref:
apiVersion: v1
Expand Down
2 changes: 1 addition & 1 deletion examples/knative/go/kn-go-preemption/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
broker: default
filter:
attributes:
subject: AlarmStatusChangedEvent
type: com.vmware.vsphere.AlarmStatusChangedEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
3 changes: 1 addition & 2 deletions examples/knative/go/kn-go-tagging/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ spec:
broker: default
filter:
attributes:
subject: VmPoweredOffEvent
type: com.vmware.event.router/event
type: com.vmware.vsphere.VmPoweredOffEvent.v0
subscriber:
ref:
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: AlarmStatusChangedEvent
type: com.vmware.vsphere.AlarmStatusChangedEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The ce-subject value should match the event router subject in function.yaml
$subject = "AlarmStatusChangedEvent"
$payloadPath = "./test-payload.json"

if ( $args.Count -gt 0 ) {
Expand All @@ -21,8 +20,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = $($subject);
"ce-type" = "com.vmware.vsphere.AlarmStatusChangedEvent.v0";
}
$body = Get-Content -Raw -Path $payloadPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ curl -d@$PAYLOAD_PATH \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/event' \
-H 'ce-subject: '$SUBJECT \
-H 'ce-type: com.vmware.vsphere.AlarmStatusChangedEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/eventex
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: com.vmware.vc.HA.ClusterFailoverActionCompletedEvent
type: com.vmware.vsphere.com.vmware.vc.HA.ClusterFailoverActionCompletedEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The ce-subject value should match the event router subject in function.yaml
$subject = "com.vmware.vc.HA.ClusterFailoverActionCompletedEvent"
$payloadPath = "./test-payload.json"

if ( $args.Count -gt 0 ) {
Expand All @@ -21,8 +20,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/eventex";
"ce-subject" = $($subject);
"ce-type" = "com.vmware.vsphere.com.vmware.vc.HA.ClusterFailoverActionCompletedEvent.v0";
}
$body = Get-Content -Raw -Path $payloadPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# The ce-subject value should match the event router subject in function.yaml
echo "Testing Function ..."
PAYLOAD_PATH="test-payload.json"
SUBJECT="com.vmware.vc.HA.ClusterFailoverActionCompletedEvent"

if [ $# -gt 0 ]; then
if test -f "$1"; then
Expand All @@ -22,8 +21,7 @@ curl -d@$PAYLOAD_PATH \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/eventex' \
-H 'ce-subject: '$SUBJECT \
-H 'ce-type: com.vmware.vsphere.com.vmware.vc.HA.ClusterFailoverActionCompletedEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
12 changes: 3 additions & 9 deletions examples/knative/powercli/kn-pcli-hostmaint-alarms/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
autoscaling.knative.dev/minScale: "1"
spec:
containers:
- image: us.gcr.io/daisy-284300/veba/kn-pcli-hostmaint-alarms:1.1
- image: us.gcr.io/daisy-284300/veba/kn-pcli-hostmaint-alarms:1.2
envFrom:
- secretRef:
name: hostmaint-secret
Expand All @@ -30,10 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: ExitMaintenanceModeEvent
type: com.vmware.vsphere.ExitMaintenanceModeEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand All @@ -50,10 +47,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: EnteredMaintenanceModeEvent
type: com.vmware.vsphere.EnteredMaintenanceModeEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Function Process-Handler {
}

if (${env:FUNCTION_DEBUG} -eq "true") {
Write-Host "$(Get-Date) - DEBUG: Event - $($cloudEvent.subject)"
Write-Host "$(Get-Date) - DEBUG: Event - $($cloudEvent.type)"
}
$hostName = $cloudEventData.Host.Name
$moRef = New-Object VMware.Vim.ManagedObjectReference
Expand All @@ -99,7 +99,7 @@ Function Process-Handler {
throw $_
}

if ($cloudEvent.subject -eq "EnteredMaintenanceModeEvent") {
if ($cloudEvent.type -eq "com.vmware.vsphere.EnteredMaintenanceModeEvent.v0") {
# Disable alarm actions on the host
Write-Host "$(Get-Date) - Disabling alarm actions on host: $hostName"
try {
Expand All @@ -111,7 +111,7 @@ Function Process-Handler {
}
}

if ($cloudEvent.subject -eq "ExitMaintenanceModeEvent") {
if ($cloudEvent.type -eq "com.vmware.vsphere.ExitMaintenanceModeEvent.v0") {
# Enable alarm actions on the host
Write-Host "$(Get-Date) - Enabling alarm actions on host: $hostName"
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The ce-subject value should match the event router subject in function.yaml
$subject = "EnteredMaintenanceModeEvent"
$payloadPath = "./enter-maint-payload.json"

if ( $args.Count -gt 0 ) {
Expand All @@ -21,8 +20,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = $($subject);
"ce-type" = "com.vmware.vsphere.EnteredMaintenanceModeEvent.v0";
}
$body = Get-Content -Raw -Path $payloadPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# The ce-subject value should match the event router subject in function.yaml
echo "Testing Function ..."
PAYLOAD_PATH="enter-maint-payload.json"
SUBJECT="EnteredMaintenanceModeEvent"

if [ $# -gt 0 ]; then
if test -f "$1"; then
Expand All @@ -22,8 +21,7 @@ curl -d@$PAYLOAD_PATH \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/event' \
-H 'ce-subject: '$SUBJECT \
-H 'ce-type: com.vmware.vsphere.EnteredMaintenanceModeEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
4 changes: 2 additions & 2 deletions examples/knative/powercli/kn-pcli-nsx-tag-sync/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
broker: default
filter:
attributes:
subject: com.vmware.cis.tagging.attach
subject: com.vmware.vsphere.com.vmware.cis.tagging.attach.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand All @@ -47,7 +47,7 @@ spec:
broker: default
filter:
attributes:
subject: com.vmware.cis.tagging.detach
subject: com.vmware.vsphere.com.vmware.cis.tagging.detach.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "d70079f9-fddd-4b7f-aa76-1193f28b0611";
"ce-source" = "https://vcenter.local/sdk";
"ce-type" = "com.vmware.event.router/eventex";
"ce-subject" = "com.vmware.cis.tagging.attach";
"ce-type" = "com.vmware.vsphere.com.vmware.cis.tagging.attach.v0";
}

$body = Get-Content -Raw -Path "./test-payload.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ curl [email protected] \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/eventex' \
-H 'ce-subject: com.vmware.cis.tagging.attach' \
-H 'ce-type: com.vmware.vsphere.com.vmware.cis.tagging.attach.v0' \
-X POST localhost:8080

echo "See docker container console for output"
7 changes: 2 additions & 5 deletions examples/knative/powercli/kn-pcli-pg-check/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
autoscaling.knative.dev/minScale: "1"
spec:
containers:
- image: us.gcr.io/daisy-284300/veba/kn-pcli-pg-check:1.1
- image: us.gcr.io/daisy-284300/veba/kn-pcli-pg-check:1.2
envFrom:
- secretRef:
name: pg-check-secret
Expand All @@ -30,10 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: VmReconfiguredEvent
type: com.vmware.vsphere.VmReconfiguredEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
2 changes: 1 addition & 1 deletion examples/knative/powercli/kn-pcli-pg-check/handler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Function Process-Handler {
fields = @(
@{
title = "EventType";
value = $cloudEvent.Subject;
value = $cloudEvent.Type;
short = "false";
}
@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = "VmReconfiguredEvent";
"ce-type" = "com.vmware.vsphere.VmReconfiguredEvent.v0";
}

$payloadPath = "./test-payload.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ curl -d@$PAYLOAD_PATH \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/event' \
-H 'ce-subject: VmReconfiguredEvent' \
-H 'ce-type: com.vmware.vsphere.VmReconfiguredEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
3 changes: 1 addition & 2 deletions examples/knative/powercli/kn-pcli-tag/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
subject: DrsVmPoweredOnEvent
type: com.vmware.vsphere.DrsVmPoweredOnEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = "DrsVmPoweredOnEvent";
"ce-type" = "com.vmware.vsphere.DrsVmPoweredOnEvent.v0";
}

$body = Get-Content -Raw -Path "./test-payload.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ curl [email protected] \
-H 'ce-specversion: 1.0' \
-H 'ce-id: d70079f9-fddd-4b7f-aa76-1193f28b0611' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/event' \
-H 'ce-subject: DrsVmPoweredOnEvent' \
-H 'ce-type: com.vmware.vsphere.DrsVmPoweredOnEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
2 changes: 1 addition & 1 deletion examples/knative/powercli/kn-pcli-telegram/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
broker: default
filter:
attributes:
subject: VmMigratedEvent
subject: com.vmware.vsphere.VmMigratedEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "41289fef-0727-46f7-b1a9-b8145972c734";
"ce-source" = "https://vcenter.local/sdk";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = "VmMigratedEvent";
"ce-type" = "com.vmware.vsphere.VmMigratedEvent.v0";
}

$body = Get-Content -Raw -Path "./test-payload.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ curl -i -vvv [email protected] \
-H 'ce-specversion: 1.0' \
-H 'ce-id: 41289fef-0727-46f7-b1a9-b8145972c734' \
-H 'ce-source: https://vcenter.local/sdk' \
-H 'ce-type: com.vmware.event.router/event' \
-H 'ce-subject: VmMigratedEvent' \
-H 'ce-type: com.vmware.vsphere.VmMigratedEvent.v0' \
-X POST localhost:8080

echo "See docker container console for output"
5 changes: 1 addition & 4 deletions examples/knative/powercli/kn-pcli-template/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ spec:
broker: default
filter:
attributes:
type: com.vmware.event.router/event
# Replace this subject with the event you need to trigger on
# Then, edit send-cloudevent-test.ps1 and send-cloudevent-test.sh in the /test folder
subject: DvsReconfiguredEvent
type: com.vmware.vsphere.DvsReconfiguredEvent.v0
subscriber:
ref:
apiVersion: serving.knative.dev/v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The ce-subject value should match the event router subject in function.yaml
$subject = "DvsReconfiguredEvent"
$payloadPath = "./test-payload.json"

if ( $args.Count -gt 0 ) {
Expand All @@ -21,8 +20,7 @@ $headers = @{
"ce-specversion" = "1.0";
"ce-id" = "id-123";
"ce-source" = "source-123";
"ce-type" = "com.vmware.event.router/event";
"ce-subject" = $($subject);
"ce-type" = "com.vmware.vsphere.DvsReconfiguredEvent.v0";
}
$body = Get-Content -Raw -Path $payloadPath

Expand Down
Loading

0 comments on commit 1cd0e39

Please sign in to comment.