Skip to content

Instantly share code, notes, and snippets.

@lcharkiewicz
Last active April 6, 2017 08:43
Show Gist options
  • Save lcharkiewicz/9d48633fec47dc9ccef297e1202d8cd4 to your computer and use it in GitHub Desktop.
Save lcharkiewicz/9d48633fec47dc9ccef297e1202d8cd4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# usage:
# python kube_config_merge.py ~/.kube/config1 ~/.kube/config2
import sys
import yaml # PyYAML
configs = []
for config in sys.argv[1:]:
print(config)
configs.append(yaml.load(open(config, 'r')))
# load first config
merged = configs[0]
# merge next configs with the first one
for config in configs[1:]:
for cluster in config['clusters']:
merged['clusters'].append(cluster)
for context in config['contexts']:
merged['contexts'].append(context)
for user in config['users']:
merged['users'].append(user)
print(yaml.dump(merged, default_flow_style=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment