VMware Event Broker Appliance – Part X – Building a New PowerCLI Function – Function Deployment

In the previous post, I walked line-by-line through the code that comprises the kn-pcli-pg-check example function. In this post, we finish the function.

Once the function works during testing, you need to deploy it to VEBA. The deployment steps are the same steps that everyone who wants to use your function will follow.

Step 1 – Push Image

You should be following “Step 3 – Deploy” in the README file. You should be copying and pasting the commands into your terminal window. If the commands don’t work for you, they won’t work for anybody else trying to use your function. Correct the README if there are any

docker push ${IMAGE}

Step 2 – Update JSON

In Part VIII, we configured environment variables in ‘test/docker-test-env-variable’. The same variables need to be configured in ‘pg_check_secret.json’. You should also take a moment now to ensure all of your environment variables are documented in the README.

  "VCENTER_SERVER": "vc02.ad.patrickkremer.com",
  "VCENTER_USERNAME" : "administrator@vsphere.local",
  "SLACK_WEBHOOK_URL" : "https://hooks.slack.com/services/FILL-ME-IN",
  "SLACK_MESSAGE_PRETEXT":"Virtual Machine - Portgroup Alert"

Step 3 – Create Kubernetes Secret

Create the Kubernetes secret from the JSON file

kubectl -n vmware-functions create secret generic pg-check-secret --from-file=PG_CHECK_SECRET=pg_check_secret.json

Step 4 – Configure function.yaml

Ensure the following properties are configured in function.yaml

  • Service name
  • Trigger name
  • Container image – point to the Docker image you pushed in Step 1
  • secretRef – point to the secret file you created in Step 2
  • Filter subject – The event name you figured out with the Sockeye service in Part VIII
apiVersion: serving.knative.dev/v1
kind: Service
  name: kn-pcli-pg-check
    app: veba-ui
        autoscaling.knative.dev/maxScale: "1"
        autoscaling.knative.dev/minScale: "1"
        - image: kremerpatrick/kn-pcli-pg-check:1.0
            - secretRef:
                name: pg-check-secret
            - name: FUNCTION_DEBUG
              value: "true"
apiVersion: eventing.knative.dev/v1
kind: Trigger
  name: veba-pcli-pg-check-trigger
    app: veba-ui
  broker: default
      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
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: kn-pcli-pg-check

Step 5 – Deploy Function

Deploy the function to your VEBA appliance

kubectl -n vmware-functions apply -f function.yaml

You can check on the function status with:

kubectl get pods -A

You will initially see the container being created.

It should eventually move to Running

Step 6 – Test

It is a good idea to monitor the container logfile while doing testing. List out the pods

kubectl get pods -A

Find your function name

Follow the container log

kubectl logs -n vmware-functions kn-pcli-pg-check-00001-deployment-7f595cc7b5-7bvgs user-container --follow

The function is up, waiting for input.

Now, make a change to a VM in vCenter. I first edited a VM but made no changes. The function triggered, but correctly detected that nothing changed.

Now I put a VM on a PCI port group.

Now I put the VM on a non-PCI portgroup. It is detected correctly, and the log shows that a Slack message was sent.

The message appears in Slack.

Step 7 – Clean up

Delete the function and the secret

kubectl -n vmware-functions delete -f function.yaml
kubectl -n vmware-functions delete secret pg-check-secret

Step 8 – Contribute

Open source thrives on community contributions. Please contribute your function back to the repo! Follow these steps to let others use your code.

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *