Skip to content

Instantly share code, notes, and snippets.

@krogebry
Created January 29, 2020 19:20
Show Gist options
  • Select an option

  • Save krogebry/a31444aeb486ffe5a720ef982be28cab to your computer and use it in GitHub Desktop.

Select an option

Save krogebry/a31444aeb486ffe5a720ef982be28cab to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from colorama import Fore, Back, Style
# from kubernetes import client, config
import kubernetes
import json
import yaml
import subprocess
project_name = "default"
class ClusterValidation:
def __init__(self, project_name):
self.namespaces = []
self.helm_charts = {}
self.config = self.load_config()
self.project_name = project_name
kubernetes.config.load_kube_config()
self.kube_client = kubernetes.client.CoreV1Api()
def load_config(self):
return yaml.safe_load(open('etc/insight-cluster.yml').read())
def get_namespaces(self):
for ns in self.kube_client.list_namespace().items:
self.namespaces.append(ns.metadata.name)
def namespace_exists(self, namespace):
if namespace in self.namespaces:
return True
else:
return False
def get_helm_charts(self):
helmout = subprocess.getoutput("helm list --output json")
self.helm_charts = json.loads(helmout)
def helm_chart_exists(self, chart_name):
search = [i for i in self.helm_charts["Releases"] if i["Name"] == chart_name]
if len(search) == 0:
return False
else:
return True
def validate(self):
self.get_namespaces()
self.get_helm_charts()
if self.namespace_exists(project_name):
print(Fore.GREEN + "Project namespace is good")
else:
print(Fore.RED + "Project namespace is missing")
for helm_chart in self.config['helm_charts']:
if self.helm_chart_exists(helm_chart):
print(f"{Fore.GREEN}Helm chart {helm_chart} is installed.")
else:
print(f"{Fore.RED}Helm chart {helm_chart} is missing")
for ingress in self.config['ingress']:
print(f"Checking ingress {ingress}")
if __name__ == "__main__":
cv = ClusterValidation(project_name)
cv.validate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment