Skip to content

Commit

Permalink
Update README and main.go for improved CLI tool description and argum…
Browse files Browse the repository at this point in the history
…ent handling
  • Loading branch information
btungut committed Feb 18, 2025
1 parent f9851e4 commit b646d5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
![build](https://img.shields.io/github/actions/workflow/status/btungut/kubeconfig-merge/ci.yml?branch=master)
![go](https://img.shields.io/github/go-mod/go-version/btungut/kubeconfig-merge)

## Why is it developed?
If you are someone who works with a significant number of Kubernetes clusters, dealing with `kubecontext` in a manual way can be **boring** and also **result in problems**.
In addition to that, I am currently working with more than 20 customers, which results in an average of five clusters per customer.
# 🌟 kubeconfig-merge

## Install
`kubeconfig-merge` is a lightweight and efficient CLI tool designed to **merge multiple Kubernetes `kubeconfig` files** into a single, well-structured configuration. It ensures that the resulting configuration is clean, free of conflicts, and compatible with `kubectl` and other Kubernetes clients.

## 🚀 Features

**Merge multiple `kubeconfig` files** into one unified configuration
**Preserve existing contexts, clusters, and users** without conflicts
**Ensure a clean and well-structured config file**
**Works seamlessly with `kubectl` and Kubernetes clients**
**Lightweight, fast, and easy to use**

## 📌 Installation

### Install on Linux

Expand All @@ -25,7 +33,6 @@ The following instruction list covers all of the Linux distributions (Ubuntu, De
FILENAME="kubeconfig-merge_${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/btungut/kubeconfig-merge/releases/latest/download/${FILENAME}" &&
sudo rm -rf "$EXEC_PATH" && sudo cp "${FILENAME}" "$EXEC_PATH" && sudo chmod +x "$EXEC_PATH"
)
```
### Install on Windows
Expand All @@ -34,26 +41,16 @@ TBD
## Arguments
| Argument | Description | Default |
|--------------|----------------------------------------------------------------------------|------------------------------------------------|
| file | The additional kubeconfig file | *Required* |
| kubeconfig | The kubeconfig file which to be append into | `KUBECONFIG` env variable, or `~/.kube/config` |
| name | Context, cluster and user name of new entries | File name of `--file`|
| Argument | Type | Description | Default |
| ---------- | ------- | ----------------------------------------------- | ---------------------------------------------- |
| kubeconfig | string | The kubeconfig file which to be append into | `KUBECONFIG` env variable, or `~/.kube/config` |
| file | string | To be appended kubeconfig file | **Required** |
| override | boolean | Use file name for the cluster, context and user | Optional |
## Examples
---
### `./kubeconfig-merge --file valid-default-cluster.yaml`

![kubeconfig-merge without name](.assets/kubeconfig-merge-01.png)
## Examples
<br/>
---

### `./kubeconfig-merge --file valid-default-cluster.yaml --name foo`
![kubeconfig-merge with name](.assets/kubeconfig-merge-02.png)
### `./kubeconfig-merge --file valid-default-cluster.yaml`
## Contributors
[Ohki Nozomu](https://github.com/ohkinozomu)

![kubeconfig-merge without name](.assets/kubeconfig-merge-01.png)
9 changes: 3 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ func getKubeConfigPath(passedValue string) string {
func main() {
kubeConfigPtr := flag.String("kubeconfig", "", fmt.Sprintf("path to the kubeconfig file (defaults '%s' or '%s')", KUBECONFIG_ENV_KEY, KUBECONFIG_DEFAULT_PATH))
filePtr := flag.String("file", "", "path to the yaml file that to be append into kubeconfig")
namePtr := flag.String("name", "", "Replaces the name of context, user and cluster (default file name of --file argument)")
overridePtr := flag.Bool("override", false, "Override the existing context, user and cluster with the same name")
overridePtr := flag.Bool("override", false, "Override the existing context, user and cluster with the file name, or the fields in the file will be used")
flag.Parse()

var kubeConfigPath = getKubeConfigPath(*kubeConfigPtr)
Expand All @@ -226,10 +225,8 @@ func main() {

var fileName = filepath.Base(*filePtr)
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
if len(*namePtr) > 0 {
fileName = *namePtr
}
result, err := Merge(*kubeConfig, *toBeAppend, *namePtr, *overridePtr)
fileName = strings.ToLower(fileName)
result, err := Merge(*kubeConfig, *toBeAppend, fileName, *overridePtr)
if err != nil {
log.Panic(err)
}
Expand Down

0 comments on commit b646d5c

Please sign in to comment.