Skip to content

Instantly share code, notes, and snippets.

@nikhita
Last active May 26, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhita/8b941379c22ea250abf325b47bd19a33 to your computer and use it in GitHub Desktop.
Save nikhita/8b941379c22ea250abf325b47bd19a33 to your computer and use it in GitHub Desktop.
Kubernetes TPR watch example

TPR watch example

For issue: kubernetes/kubernetes#25340

Also mentioned in #95 TPR issue: kubernetes/enhancements#95 (comment)

Create a ThirdPartyResource

$ cat databases-tpr.yaml
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
metadata:
  name: database.example.com
description: "A specification of a SQL database."
versions:
  - name: v1

Create a TPR object

$ cat wordpress-database.yaml
apiVersion: example.com/v1
kind: Database
metadata:
  name: wordpress
spec:
  user: wp
  password: secret
  encoding: unicode

Watching using curl:

$ curl -f "http://localhost:8080/apis/example.com/v1/namespaces/default/databases?watch=true"
{"type":"ADDED","object":{"apiVersion":"example.com/v1","kind":"Database","metadata":{"name":"wordpress","namespace":"default","selfLink":"/apis/example.com/v1/namespaces/default/databases/wordpress","uid":"12e71529-1ea7-11e7-9e11-f0761cb232d1","resourceVersion":"13662","creationTimestamp":"2017-04-11T11:07:38Z"},"spec":{"encoding":"unicode","password":"secret","user":"wp"}}}
{"type":"DELETED","object":{"apiVersion":"example.com/v1","kind":"Database","metadata":{"name":"wordpress","namespace":"default","selfLink":"/apis/example.com/v1/namespaces/default/databases/wordpress","uid":"12e71529-1ea7-11e7-9e11-f0761cb232d1","resourceVersion":"13921","creationTimestamp":"2017-04-11T11:07:38Z"},"spec":{"encoding":"unicode","password":"secret","user":"wp"}}}

Also works in the browser at http://localhost:8080/apis/example.com/v1/namespaces/default/databases?watch=true.

Watch using -w flag

$ kubectl get database -w
NAME        KIND
wordpress   Database.v1.example.com
wordpress   Database.v1.example.com

kubectl version

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"7+", GitVersion:"v1.7.0-alpha.1.183+6d7e6c74c933c7-dirty", GitCommit:"6d7e6c74c933c7b7475c9d7f902c468825505a00", GitTreeState:"dirty", BuildDate:"2017-04-11T07:24:17Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"7+", GitVersion:"v1.7.0-alpha.1.183+6d7e6c74c933c7-dirty", GitCommit:"6d7e6c74c933c7b7475c9d7f902c468825505a00", GitTreeState:"dirty", BuildDate:"2017-04-11T07:24:17Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"linux/amd64"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment