-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include collector in network-config-analyzer package (#145)
Signed-off-by: Ziv Nevo <[email protected]>
- Loading branch information
Showing
3 changed files
with
28 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters