Skip to content

Commit

Permalink
Include collector in network-config-analyzer package (#145)
Browse files Browse the repository at this point in the history
Signed-off-by: Ziv Nevo <[email protected]>
  • Loading branch information
zivnevo authored Dec 11, 2024
1 parent e63f376 commit 0288da5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Empty file added collector/__init__.py
Empty file.
40 changes: 24 additions & 16 deletions collector/collect.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
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)
def collect():
"""
A small utility to collect all the network-related resources in the current cluster context
"""
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' ]
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)
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)

if __name__ == "__main__":
collect()
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ install_requires =
python_requires = >=3.9

[options.packages.find]
include = nca*
include =
nca*
collector*

[options.package_data]
* = VERSION.txt

[options.entry_points]
console_scripts =
nca = nca.nca_cli:nca_main
nca_collect = collector.collect:collect

0 comments on commit 0288da5

Please sign in to comment.