Skip to content

Commit

Permalink
feat: load binaries from configmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampouille committed Sep 20, 2023
1 parent 0574712 commit 7dce44f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,30 @@ def __init__(self, ns):
self.appsv1 = client.AppsV1Api()
self.CRApi = client.CustomObjectsApi()
self.binaries = BufferedDictSet()
# Populate binaries from configmap
self._loadBinariesFromCM()
self.lock = Lock()
self.orphanPod = set()

def _loadBinariesFromCM(self):
try:
print("Loading binaries from ConfigMap %s/tetragon-binaries" % self.ns)
api_response = self.v1.read_namespaced_config_map("tetragon-binaries", self.ns, pretty=True)
self.binaries.written = { wl: set(json.loads(bins)) for (wl, bins) in api_response.data.items()}
print("%s/tetragon-binaries ConfigMap found" % self.ns)
print(self.binaries)
except ApiException as e:
if e.reason == 'Not Found':
print("%s/tetragon-binaries ConfigMap not found" % self.ns)
else:
raise e

def getWorkload(self, pod):
if pod in self.pod_to_workload:
return self.pod_to_workload[pod]
else:
if pod in self.orphanPod:
raise PodNotfound(pod)
owner = self.getPodOwner(pod)
if owner[0] == 'ReplicaSet':
rs_owner = self.getRSOwner(owner[1])
Expand All @@ -159,7 +177,10 @@ def getPodOwner(self, pod):
return (owner.kind, owner.name)
except ApiException as e:
if e.reason == 'Not Found':
self.orphanPod.add(pod)
raise PodNotfound(pod)
else:
raise e

def getRSOwner(self, rs):
try:
Expand All @@ -174,6 +195,8 @@ def getRSOwner(self, rs):
except ApiException as e:
if e.reason == 'Not Found':
raise ReplicasetNotfound(rs)
else:
raise e

def getDeploymentSelector(self, deploy):
try:
Expand All @@ -184,6 +207,8 @@ def getDeploymentSelector(self, deploy):
except ApiException as e:
if e.reason == 'Not Found':
raise DeploymentNotfound(deploy)
else:
raise e

def getDaemonSetSelector(self, ds):
try:
Expand All @@ -194,6 +219,8 @@ def getDaemonSetSelector(self, ds):
except ApiException as e:
if e.reason == 'Not Found':
raise DaemonSetNotfound(ds)
else:
raise e

def getStatefulSetSelector(self, sts):
try:
Expand All @@ -204,6 +231,8 @@ def getStatefulSetSelector(self, sts):
except ApiException as e:
if e.reason == 'Not Found':
raise StatefulSetNotfound(sts)
else:
raise e

def process(self, event):
try:
Expand Down

0 comments on commit 7dce44f

Please sign in to comment.