

#!/bin/bashif [[ $1 == "--config" ]] ; thencat <<EOF{"onKubernetesEvent": [{"kind": "namespace","event": [ "add" ]}]}EOFfi
#!/bin/bashif [[ $1 == "--config" ]] ; then# configurationcat <<EOF{"onKubernetesEvent": [{"kind": "namespace","event": [ "add" ]}]}EOFelse# response:# find out what namespace has emergedcreatedNamespace=$(jq -r '.[0].resourceName' $BINDING_CONTEXT_PATH)# create the appropriate secret in itkubectl create -n ${createdNamespace} -f - <<EOFapiVersion: v1kind: Secretmetadata:...data:...EOFfi
$ cat DockerfileFROM flant/shell-operator:v1.0.0-beta.1-alpine3.9ADD namespace-hook.sh /hooks$ docker build -t registry.example.com/my-operator:v1 .$ docker push registry.example.com/my-operator:v1
-
它訂閱了 namespace的建立事件;
-
它在不與它所執行的名稱空間相同的空間建立一個secret。
---apiVersion: v1kind: ServiceAccountmetadata:name: monitor-namespaces-acc---apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRolemetadata:name: monitor-namespacesrules:- apiGroups: [""]resources: ["namespaces"]verbs: ["get", "watch", "list"]- apiGroups: [""]resources: ["secrets"]verbs: ["get", "list", "create", "patch"]---apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRoleBindingmetadata:name: monitor-namespacesroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: monitor-namespacessubjects:- kind: ServiceAccountname: monitor-namespaces-accnamespace: example-monitor-namespaces
apiVersion: extensions/v1beta1kind: Deploymentmetadata:name: my-operatorspec:template:spec:containers:- name: my-operatorimage: registry.example.com/my-operator:v1serviceAccountName: monitor-namespaces-acc
$ kubectl create ns example-monitor-namespaces$ kubectl -n example-monitor-namespaces apply -f rbac.yaml$ kubectl -n example-monitor-namespaces apply -f deployment.yaml


cat <<EOF{"onKubernetesEvent": [{"kind": "deployment","event":["update"],"jqFilter": ".metadata.labels"}]}EOF

{"onKubernetesEvent": [{"name": "OnCreatePod","kind": "pod","event": ["add"]},{"name": "OnModifiedNamespace","kind": "namespace","event": ["update"],"jqFilter": ".metadata.labels"}],"schedule": [{"name": "every 10 min","crontab": "0 */10 * * * *"},{"name": "on Mondays at 12:10","crontab": "0 10 12 * * 1"}]}
[{ "binding": "every 10 min" }]
[{ "binding": "every 10 min" }, { "binding": "on Mondays at 12:10" }]
[{"binding": "onCreatePod","resourceEvent": "add","resourceKind": "pod","resourceName": "foo","resourceNamespace": "bar"}]
jq -r '.[0].resourceName' $BINDING_CONTEXT_PATH
-
https://github.com/flant/shell-operator
-
https://flant.com/
-
https://github.com/flant/shell-operator/blob/master/HOOKS.md
-
https://github.com/flant/shell-operator/blob/master/HOOKS.md#binding-context
-
https://github.com/flant/shell-operator/tree/master/examples
-
https://github.com/flant/shell-operator/blob/master/METRICS.md
-
https://github.com/flant/shell-operator
知識星球

朋友會在“發現-看一看”看到你“在看”的內容