Skip to content

Commit

Permalink
Fix bugs and add sample deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarkey committed May 12, 2019
1 parent 4cd9782 commit fc96761
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 9 deletions.
29 changes: 29 additions & 0 deletions deploy/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: extensions/v1beta1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: kube-lookout
labels:
app: kube-lookout
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: kube-lookout
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: kube-lookout
spec:
serviceAccount: kube-lookout
containers:
- name: kube-lookout
image: davidjmarkey/kube-lookout:latest
imagePullPolicy: Never
env:
- name: SLACK_TOKEN
value: "insert_token_here"
37 changes: 37 additions & 0 deletions deploy/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kube-lookout
name: kube-lookout
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kube-lookout
labels:
k8s-app: kube-lookout
rules:
- apiGroups:
- extensions
resources:
- deployments
verbs:
- list
- get
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kube-lookout
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kube-lookout
subjects:
- kind: ServiceAccount
name: kube-lookout
namespace: kube-system
16 changes: 7 additions & 9 deletions lookout.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def _handle_deployment_change(self, deployment):
metadata = deployment.metadata
deployment_key = f"{metadata.namespace}/{metadata.name}"

ready_replicas = 0
if deployment.status.ready_replicas is not None:
ready_replicas = deployment.status.ready_replicas

if deployment_key not in self.rollouts and \
deployment.status.updated_replicas is None:
blocks = self._generate_deployment_rollout_block(deployment)
Expand All @@ -88,7 +92,7 @@ def _handle_deployment_change(self, deployment):
rollout_complete = (
deployment.status.updated_replicas ==
deployment.status.replicas ==
deployment.status.ready_replicas)
ready_replicas)
blocks = self._generate_deployment_rollout_block(deployment,
rollout_complete)
self.rollouts[deployment_key] = self._send_slack_block(
Expand All @@ -97,14 +101,13 @@ def _handle_deployment_change(self, deployment):

if rollout_complete:
self.rollouts.pop(deployment_key)
elif deployment.status.ready_replicas < deployment.spec.replicas:
elif ready_replicas < deployment.spec.replicas:
blocks = self._generate_deployment_degraded_block(deployment)
self._send_slack_block(blocks, self.slack_channel)
self.degraded.add(deployment_key)

elif (deployment_key in self.degraded and
deployment.status.ready_replicas
>= deployment.spec.replicas):
ready_replicas >= deployment.spec.replicas):
self.degraded.remove(deployment_key)
blocks = self._generate_deployment_not_degraded_block(deployment)
self._send_slack_block(blocks, self.slack_channel)
Expand All @@ -124,11 +127,6 @@ def main_loop(self):
print("Waiting for deployment events to come in..")
for event in stream:
deployment = event['object']
obj = event["object"]
code = obj.get("code")
if code == 410:
print("Received HTTP 410, restarting..")
break
self._handle_event(deployment)

def _generate_deployment_rollout_block(self, deployment,
Expand Down

0 comments on commit fc96761

Please sign in to comment.