Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
Signed-off-by: Kaan Karakaya <[email protected]>
  • Loading branch information
TheYkk committed Aug 24, 2020
0 parents commit ef59923
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.8-slim

RUN pip install kopf kubernetes

ADD . /src

CMD kopf run /src/handlers.py
60 changes: 60 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: synator
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: synator
rules:
- apiGroups: [""]
resources: ["secrets", "configmaps"]
verbs: ["*"]
- apiGroups: [events.k8s.io]
resources: [events]
verbs: [create]
- apiGroups: [""]
resources: [events]
verbs: [create]
- apiGroups: [""]
resources: ["namespaces", "pods", "replicasets"]
verbs: ["get"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["list", "watch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: synator
subjects:
- kind: ServiceAccount
name: synator
namespace: default
roleRef:
kind: ClusterRole
name: synator
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: synator
namespace: default
spec:
replicas: 1
selector:
matchLabels:
name: synator
template:
metadata:
labels:
name: synator
spec:
serviceAccountName: synator
containers:
- name: synator
image: theykk/synator:v0.10
44 changes: 44 additions & 0 deletions handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import kopf
import kubernetes


@kopf.on.create('', 'v1', 'secrets', labels={'synator/sync': 'yes'})
@kopf.on.update('', 'v1', 'secrets', labels={'synator/sync': 'yes'})
def updateSecret(body, meta, spec, status, old, new, diff, **kwargs):
print("SYNC SECRET ", meta.name)
api = kubernetes.client.CoreV1Api()
namespace_response = api.list_namespace()
namespaces = [nsa.metadata.name for nsa in namespace_response.items]
namespaces.remove('kube-public')
namespaces.remove('kube-node-lease')
namespaces.remove(meta.namespace)

secret = api.read_namespaced_secret(meta.name, meta.namespace)
secret.metadata.labels.pop('synator/sync')
secret.metadata.resource_version = None
for ns in namespaces:
secret.metadata.namespace = ns
api.create_namespaced_secret(
ns, secret
)


@kopf.on.create('', 'v1', 'configmaps', labels={'synator/sync': 'yes'})
@kopf.on.update('', 'v1', 'configmaps', labels={'synator/sync': 'yes'})
def updateConfigMap(body, meta, spec, status, old, new, diff, **kwargs):
print("SYNC CFG ", meta.name)
api = kubernetes.client.CoreV1Api()
namespace_response = api.list_namespace()
namespaces = [nsa.metadata.name for nsa in namespace_response.items]
namespaces.remove('kube-public')
namespaces.remove('kube-node-lease')
namespaces.remove(meta.namespace)

cfg = api.read_namespaced_config_map(meta.name, meta.namespace)
cfg.metadata.labels.pop('synator/sync')
cfg.metadata.resource_version = None
for ns in namespaces:
cfg.metadata.namespace = ns
api.create_namespaced_config_map(
ns, cfg
)

0 comments on commit ef59923

Please sign in to comment.