Skip to content

Commit

Permalink
add collector script (#142)
Browse files Browse the repository at this point in the history
* add collector script

Signed-off-by: adisos <adisos@il.ibm.com>

* add cluster context

Signed-off-by: adisos <adisos@il.ibm.com>

* Update collector/collect.py

Co-authored-by: Ziv Nevo <79099626+zivnevo@users.noreply.github.com>

* Update collector/collect.py

Co-authored-by: Ziv Nevo <79099626+zivnevo@users.noreply.github.com>

---------

Signed-off-by: adisos <adisos@il.ibm.com>
Co-authored-by: Ziv Nevo <79099626+zivnevo@users.noreply.github.com>
  • Loading branch information
adisos and zivnevo authored Dec 10, 2024
1 parent 72f4b3a commit 230fbc7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions collector/collect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import subprocess


get_ctx = 'kubectl config current-context'
print(get_ctx)
cmdline_process = subprocess.Popen(get_ctx.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ctx, err = cmdline_process.communicate()
ctx_cluster = ctx.decode("utf-8").replace('/', '-').strip()
print(ctx_cluster)

resources = ['pods', 'namespaces', 'services', 'networkpolicies', 'ingresses', 'ingressclasses', 'authorizationpolicies', 'destinationrules','gateways', 'serviceentries','sidecars','virtualservices' ]

for resource in resources:
cmd = 'kubectl get ' + resource + ' -A -o yaml'
cmdline_list = cmd.split(' ')
print(cmd)
log = open(ctx_cluster + '_' + resource + '.yaml', 'a')
cmdline_process = subprocess.Popen(cmdline_list, stdout=log, stderr=subprocess.PIPE)
out, err = cmdline_process.communicate()
if len(err) > 0:
print(err)

0 comments on commit 230fbc7

Please sign in to comment.