A command-line tool for merging multiple Kubernetes configuration files while handling naming conflicts interactively.
k8s_config_merge is a utility that allows you to combine multiple Kubernetes configuration files (kubeconfig
) into a single configuration file. It automatically handles naming conflicts for clusters, users, and contexts by prompting for new names when conflicts are detected.
- Merge multiple kubeconfig files into a single configuration
- Interactive conflict resolution for duplicate names
- Support for reading configuration from stdin
- Optional custom naming for imported configurations
- Automatic backup of existing configuration (destination file)
- Preserves existing configurations while adding new ones
go get github.com/yourusername/k8s_config_merge
k8s_config_merge [-d destination_file] [-n new_config_name] -s source_file1 [-s source_file2 ...]
-d string
: Destination file where the merged config will be saved (default: "~/.kube/config")-n string
: Optional name to use for the imported configuration (applies to cluster, context, and user names)-s string
: Source configuration file(s) to merge. Use "-" to read from stdin. Can be specified multiple times.
- Merge a single config file:
k8s_config_merge -s new-cluster.yaml
- Merge multiple config files:
k8s_config_merge -s cluster1.yaml -s cluster2.yaml
- Read config from stdin:
cat cluster-config.yaml | k8s_config_merge -s -
- Specify custom name for imported config:
k8s_config_merge -s new-cluster.yaml -n production-cluster
- Specify custom destination file:
k8s_config_merge -d ./custom-config -s new-cluster.yaml
- The tool reads the destination config file (defaults to ~/.kube/config)
- For each source config file:
- Loads and validates the configuration
- Checks for naming conflicts with existing configurations
- Prompts for new names when conflicts are found
- Merges the configuration into the destination
- Saves the merged configuration back to the destination file
When naming conflicts are detected, the tool will:
- Prompt for a new name
- Validate the input (must contain only alphanumeric characters)
- Update all related references in the configuration
- Continue with the merge process
MIT License (Copyright (C) 2021 rmelo)
Ricardo Melo (rmelo@ludia.com)