diff --git a/cmd/completion/command.go b/cmd/completion/command.go index 1c9f750..a9de146 100644 --- a/cmd/completion/command.go +++ b/cmd/completion/command.go @@ -1,14 +1,11 @@ package completion import ( - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create COMPLETION command") return &cli.Command{ Name: "completion", diff --git a/cmd/delete/action.go b/cmd/delete/action.go index 184806f..302b003 100644 --- a/cmd/delete/action.go +++ b/cmd/delete/action.go @@ -26,29 +26,29 @@ func deleteCtx(ctx *cli.Context) error { zap.S().Debugf("🐛 Kubernetes configuration file path: '%s'", kCfgFilePath) zap.L().Debug("🐛 Get single Kubernetes konfigurations path") - singleKonfigsPath := ctx.String(commons.SingleKonfigsFlagName) - zap.S().Debugf("🐛 Single Kubernetes konfigurations path: '%s'", singleKonfigsPath) + singleKfgsPath := ctx.String(commons.SingleKonfigsFlagName) + zap.S().Debugf("🐛 Single Kubernetes konfigurations path: '%s'", singleKfgsPath) zap.L().Debug("🐛 Get contexts to delete") - contextSlice, ctxErr := getContextList(ctx) + contexts, ctxErr := getContextList(ctx) if ctxErr != nil { return ctxErr } - zap.S().Infof("📋 Contexts to delete: '%s'", strings.Join(contextSlice, ", ")) + zap.S().Infof("📋 Contexts to delete: '%s'", strings.Join(contexts, ", ")) zap.L().Debug("🐛 Ask for user confirmation to delete contexts") if userDeletionConfirm() { - kCfgErr := deleteFromKubeConfig(kCfgFilePath, contextSlice) + kCfgErr := deleteFromKubeConfig(kCfgFilePath, contexts) if kCfgErr != nil { return kCfgErr } - kfgsErr := deleteFromKubeKonfigs(singleKonfigsPath, contextSlice) + kfgsErr := deleteFromKubeKonfigs(singleKfgsPath, contexts) if kfgsErr != nil { return kfgsErr } - zap.S().Infof("✅ Removing contexts '%s' completed", strings.Join(contextSlice, ", ")) + zap.S().Infof("✅ Removing contexts '%s' completed", strings.Join(contexts, ", ")) zap.L().Info("") diff --git a/cmd/delete/command.go b/cmd/delete/command.go index 9c51153..7d6918e 100644 --- a/cmd/delete/command.go +++ b/cmd/delete/command.go @@ -3,14 +3,11 @@ package delete import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create DELETE command") home := commons.GetHomeDirOrExit("delete") return &cli.Command{ diff --git a/cmd/list/command.go b/cmd/list/command.go index 39773e5..acfc5e5 100644 --- a/cmd/list/command.go +++ b/cmd/list/command.go @@ -3,14 +3,11 @@ package list import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create LIST command") home := commons.GetHomeDirOrExit("list") return &cli.Command{ diff --git a/cmd/rename/command.go b/cmd/rename/command.go index 00be6ed..91793bb 100644 --- a/cmd/rename/command.go +++ b/cmd/rename/command.go @@ -3,14 +3,11 @@ package rename import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create RENAME command") home := commons.GetHomeDirOrExit("rename") return &cli.Command{ diff --git a/cmd/reset/command.go b/cmd/reset/command.go index 4d6b1f7..bda8267 100644 --- a/cmd/reset/command.go +++ b/cmd/reset/command.go @@ -3,14 +3,11 @@ package reset import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create RESET command") home := commons.GetHomeDirOrExit("reset") return &cli.Command{ diff --git a/cmd/set/command.go b/cmd/set/command.go index 06b3b5b..d91d160 100644 --- a/cmd/set/command.go +++ b/cmd/set/command.go @@ -3,14 +3,11 @@ package set import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create SET-CONFIG command") home := commons.GetHomeDirOrExit("set") return &cli.Command{ diff --git a/cmd/split/command.go b/cmd/split/command.go index bbbb8b5..b912bcf 100644 --- a/cmd/split/command.go +++ b/cmd/split/command.go @@ -3,14 +3,11 @@ package split import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create SPLIT command") home := commons.GetHomeDirOrExit("split") return &cli.Command{ diff --git a/cmd/view/command.go b/cmd/view/command.go index 79a67bc..4d0e4ff 100644 --- a/cmd/view/command.go +++ b/cmd/view/command.go @@ -3,14 +3,11 @@ package view import ( "github.com/bygui86/konf-sh/pkg/commons" "github.com/bygui86/konf-sh/pkg/kubeconfig" - "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) func BuildCommand() *cli.Command { - logging.InitLogger() - zap.L().Debug("🐛 Create VIEW command") home := commons.GetHomeDirOrExit("view") return &cli.Command{ diff --git a/docs/autocompletion.md b/docs/autocompletion.md index 0ec3576..0a3dc8f 100644 --- a/docs/autocompletion.md +++ b/docs/autocompletion.md @@ -1,5 +1,5 @@ -# konf - Autocompletion +# konf-sh - Autocompletion Current supported shells: zsh, bash diff --git a/docs/emoji.md b/docs/emoji.md index 8c99294..0ef715d 100644 --- a/docs/emoji.md +++ b/docs/emoji.md @@ -1,5 +1,5 @@ -# konf - Emoji in cli +# konf-sh - Emoji in cli ## Working diff --git a/docs/links.md b/docs/links.md index 428fad3..c4eef1d 100644 --- a/docs/links.md +++ b/docs/links.md @@ -1,5 +1,5 @@ -# konf - Links +# konf-sh - Links ## Inspirations - https://github.com/ahmetb/kubectx diff --git a/docs/makefile.md b/docs/makefile.md index 2069437..833fcc7 100644 --- a/docs/makefile.md +++ b/docs/makefile.md @@ -1,13 +1,13 @@ -# konf - Makefile targets +# konf-sh - Makefile targets -### Build binary +## Build binary ```sh make build ``` -### Run +## Run ```sh # from source @@ -17,67 +17,67 @@ make run make run-bin ``` -### Clean binary +## Clean binary ```sh make clean-bin ``` -### Split a sample Kubernetes configuration file +## Split a sample Kubernetes configuration file ```sh make split ``` -### List a set of sample Kubernetes konfigurations +## List a set of sample Kubernetes konfigurations ```sh make list ``` -### Set local Kubernetes context (current bash) +## Set local Kubernetes context (current bash) ```sh make set-local ``` -### Set global Kubernetes context +## Set global Kubernetes context ```sh make set-global ``` -### View local and global Kubernetes contexts +## View local and global Kubernetes contexts ```sh make view ``` -### View local Kubernetes context (current bash) +## View local Kubernetes context (current bash) ```sh make view-local ``` -### View global Kubernetes context +## View global Kubernetes context ```sh make view-global ``` -### Clean Kubernetes contexts +## Clean Kubernetes contexts ```sh make delete ``` -### Rename Kubernetes context +## Rename Kubernetes context ```sh make rename ``` -### Release +## Release `WARN`: Be careful, this command triggers the `release` GitHub Action that results in a new release on GitHub repo diff --git a/docs/release.md b/docs/release.md index 6fd6a5b..2fe813a 100644 --- a/docs/release.md +++ b/docs/release.md @@ -1,19 +1,19 @@ -# konf - Release +# konf-sh - Release -`NEXT VERSION:` v0.5 +`NEXT VERSION:` v0.5.0 -### Automatic +## Automatic ```sh make release NEW_VERSION=... ``` -### Manual +## Manual 1. Choose a new version ```sh - NEW_VERSION="v0.5" + NEW_VERSION="v0.5.0" ``` 2. Create a new tag with choosen version ```sh @@ -24,33 +24,33 @@ make release NEW_VERSION=... git push origin $NEW_VERSION ``` -### Simulate +## Simulate ```sh goreleaser --snapshot --skip-publish --rm-dist ``` -### Available mechanisms +## Available mechanisms - goreleaser - GitHub Actions - GitHub Package Registry - PackagePublishing -### GitHub Actions +## GitHub Actions -| Action | Triggered by | Steps | -| --- | --- | --- | -| build | push to master, push to branch features/\*\*, PR to master, PR to branch features/\*\* | setup go, checkout, get dependencies, build, test | -| release | new tag creation | setup go, checkout, unshallow, run goreleaser | +| Action | Triggered by | Steps | +|---------|----------------------------------------------------------------------------------------|---------------------------------------------------| +| build | push to master, push to branch features/\*\*, PR to master, PR to branch features/\*\* | setup go, checkout, get dependencies, build, test | +| release | new tag creation | setup go, checkout, unshallow, run goreleaser | -### goreleaser +## goreleaser `WARN`: The first three steps will trigger the `release` GitHub Action, performing the last step (goreleaser), so be careful if you want to release manually. 1. version ```sh - NEW_VERSION="v0.5" + NEW_VERSION="v0.5.0" ``` 2. tag ```sh @@ -64,3 +64,7 @@ goreleaser --snapshot --skip-publish --rm-dist ```sh goreleaser release --rm-dist ``` + +## In code + +Version is specified only in `pkg/app/utils.go` diff --git a/docs/roadmap.md b/docs/roadmap.md index 10c4969..674fd81 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -1,13 +1,13 @@ -# konf - Roadmap +# konf-sh - Roadmap -### v1.0.0 🗓 +## v1.0.0 🗓 - [ ] create go install - [ ] `TBD` create homebrew-tap (see https://goreleaser.com/customization/#Homebrew) - [ ] have a look at [this library](https://github.com/gkarthiks/k8s-discovery) -### v0.8.0 🗓 +## v0.8.0 🗓 - [ ] additional documentation - [ ] `TBD` go-doc @@ -18,7 +18,7 @@ - [ ] code-coverage check - [ ] `TBD` add code-coverage badge (see https://codecov.io/gh/etherlabsio/healthcheck) -### v0.7.0 🗓 +## v0.7.0 🗓 - [ ] implement namespaces commands - [ ] view current namespace @@ -26,7 +26,7 @@ - [ ] set local (current shell only) namespace - [ ] set global namespace -### v0.6.0 🗓 +## v0.6.0 🗓 - [ ] implement "--silent" flag - [ ] shellwrapper @@ -36,7 +36,7 @@ - [ ] prompting - [ ] make it interactive with https://github.com/manifoldco/promptui -### v0.5.0 🏗 +## v0.5.0 🏗 - [x] improve README and overall documentation - [x] update codebase @@ -66,30 +66,31 @@ - [x] fix "completion zsh" (replace "PROG" with "konf") - [ ] improve "set" command - [ ] add "-" to set "last konf used" in new shell -- [ ] review logging +- [x] review logging - [x] refactor logger embracing better and more standard approach with zap library - - [ ] review logs in all commands - - [ ] completion - - [ ] clean/delete - - [ ] list - - [ ] rename - - [ ] reset - - [ ] set - - [ ] split - - [ ] view - -### v0.4.0 ✅ + - [x] review logs in all commands + - [x] app + - [x] completion + - [x] clean/delete + - [x] list + - [x] rename + - [x] reset + - [x] set + - [x] split + - [x] view + +## v0.4.0 ✅ - [x] fix GitHub Action release - [x] fix Makefile bug in release target - [x] improve release mechanism -### v0.3.0 ✅ +## v0.3.0 ✅ - [x] add logo - [x] align version everywhere -### v0.2.0 ✅ +## v0.2.0 ✅ - [x] add arguments usage - [x] new commands skeleton @@ -101,7 +102,7 @@ - [x] improved logging - [x] rename commands -### v0.1.0 ✅ +## v0.1.0 ✅ - [x] implement first set of commands - [x] implement properly logging flags diff --git a/pkg/app/konf.go b/pkg/app/konf.go index 7b1e80e..427acde 100644 --- a/pkg/app/konf.go +++ b/pkg/app/konf.go @@ -2,77 +2,34 @@ package app import ( "os" - "sort" - "github.com/bygui86/konf-sh/cmd/completion" - "github.com/bygui86/konf-sh/cmd/delete" - "github.com/bygui86/konf-sh/cmd/list" - "github.com/bygui86/konf-sh/cmd/rename" - "github.com/bygui86/konf-sh/cmd/reset" - "github.com/bygui86/konf-sh/cmd/set" - "github.com/bygui86/konf-sh/cmd/split" - "github.com/bygui86/konf-sh/cmd/view" + "github.com/bygui86/konf-sh/pkg/logging" "github.com/urfave/cli/v2" "go.uber.org/zap" ) -const ( - appName = "konf-sh" - appUsage = "The KubeConfig manager for your shell" - appVersion = "v0.5" -) - -type KubeConfiguratorApp struct { +type kubeConfiguratorApp struct { app *cli.App } -func Create() *KubeConfiguratorApp { +func Create() *kubeConfiguratorApp { + logging.InitLogger() + zap.L().Debug("🐛 Creating application") app := cli.NewApp() setGlobalConfig(app) addCommands(app) setLastConfig(app) - return &KubeConfiguratorApp{ + return &kubeConfiguratorApp{ app: app, } } -func setGlobalConfig(app *cli.App) { - zap.L().Debug("🐛 Setting global configurations") - app.Name = appName - app.Usage = appUsage - app.Version = appVersion - app.UseShortOptionHandling = true - app.EnableBashCompletion = true -} - -func addCommands(app *cli.App) { - zap.L().Debug("🐛 Adding commands") - app.Commands = []*cli.Command{ - split.BuildCommand(), - list.BuildCommand(), - view.BuildCommand(), - set.BuildCommand(), - delete.BuildCommand(), - rename.BuildCommand(), - reset.BuildCommand(), - completion.BuildCommand(), - } -} - -func setLastConfig(app *cli.App) { - zap.L().Debug("🐛 Setting last configurations") - // sort flags in help section - sort.Sort(cli.FlagsByName(app.Flags)) - // sort commands in help section - sort.Sort(cli.CommandsByName(app.Commands)) -} - -func (k *KubeConfiguratorApp) Start() { +func (k *kubeConfiguratorApp) Start() { zap.L().Debug("🐛 Starting application") err := k.app.Run(os.Args) if err != nil { - zap.S().Errorf("❌ Error starting application: %s", err.Error()) + zap.S().Errorf("❌ Error starting application: %s", err.Error()) os.Exit(2) } } diff --git a/pkg/app/utils.go b/pkg/app/utils.go new file mode 100644 index 0000000..991fd73 --- /dev/null +++ b/pkg/app/utils.go @@ -0,0 +1,47 @@ +package app + +import ( + "sort" + + "github.com/bygui86/konf-sh/cmd/completion" + deleteCmd "github.com/bygui86/konf-sh/cmd/delete" + "github.com/bygui86/konf-sh/cmd/list" + "github.com/bygui86/konf-sh/cmd/rename" + "github.com/bygui86/konf-sh/cmd/reset" + "github.com/bygui86/konf-sh/cmd/set" + "github.com/bygui86/konf-sh/cmd/split" + "github.com/bygui86/konf-sh/cmd/view" + "github.com/urfave/cli/v2" + "go.uber.org/zap" +) + +func setGlobalConfig(app *cli.App) { + zap.L().Debug("🐛 Setting global configurations") + app.Name = "konf-sh" + app.Usage = "The KubeConfig manager for your shell" + app.Version = "v0.5.0" + app.UseShortOptionHandling = true + app.EnableBashCompletion = true +} + +func addCommands(app *cli.App) { + zap.L().Debug("🐛 Adding commands") + app.Commands = []*cli.Command{ + split.BuildCommand(), + list.BuildCommand(), + view.BuildCommand(), + set.BuildCommand(), + deleteCmd.BuildCommand(), + rename.BuildCommand(), + reset.BuildCommand(), + completion.BuildCommand(), + } +} + +func setLastConfig(app *cli.App) { + zap.L().Debug("🐛 Setting last configurations") + // sort flags in help section + sort.Sort(cli.FlagsByName(app.Flags)) + // sort commands in help section + sort.Sort(cli.CommandsByName(app.Commands)) +} diff --git a/pkg/commons/os.go b/pkg/commons/os.go index 4d87d4a..15cb455 100644 --- a/pkg/commons/os.go +++ b/pkg/commons/os.go @@ -37,16 +37,17 @@ func CheckIfFileExist(filepath string) error { func GetHomeDirOrExit(methodCaller string) string { zap.L().Debug("🐛 Get HOME path") - home, homeErr := GetHomeDir() + home, homeErr := getHomeDir() if homeErr != nil { - zap.S().Errorf("❌ Error creating '%s' methodCaller - Error getting HOME environment variable: '%s'", methodCaller, homeErr.Error()) + zap.S().Errorf("❌ Error creating '%s' methodCaller - Error getting HOME environment variable: '%s'", + methodCaller, homeErr.Error()) os.Exit(3) } zap.S().Debugf("🐛 HOME path: '%s'", home) return home } -func GetHomeDir() (string, error) { +func getHomeDir() (string, error) { userHome, err := getCurrentUserHomeDir() if err != nil { return "", err diff --git a/pkg/kubeconfig/kubeconfig.go b/pkg/kubeconfig/kubeconfig.go index 8e5a6bd..937bb03 100644 --- a/pkg/kubeconfig/kubeconfig.go +++ b/pkg/kubeconfig/kubeconfig.go @@ -6,25 +6,25 @@ import ( "go.uber.org/zap" "k8s.io/client-go/tools/clientcmd" - clientcmdapi "k8s.io/client-go/tools/clientcmd/api" + clientcmdApi "k8s.io/client-go/tools/clientcmd/api" ) -func Load(kubeConfigFilePath string) *clientcmdapi.Config { +func Load(kubeConfigFilePath string) *clientcmdApi.Config { zap.S().Debugf("🐛 Load Kubernetes configuration from file '%s'", kubeConfigFilePath) return clientcmd.GetConfigFromFileOrDie(kubeConfigFilePath) } -func Split(kubeConfig *clientcmdapi.Config, kubeConfigFilePath string) map[string]*clientcmdapi.Config { +func Split(kubeConfig *clientcmdApi.Config, kubeConfigFilePath string) map[string]*clientcmdApi.Config { zap.S().Debugf("🐛 Split Kubernetes configuration from %s", kubeConfigFilePath) - singleConfigs := make(map[string]*clientcmdapi.Config, len(kubeConfig.Contexts)) + singleConfigs := make(map[string]*clientcmdApi.Config, len(kubeConfig.Contexts)) for ctxKey, ctxValue := range kubeConfig.Contexts { - contexts := make(map[string]*clientcmdapi.Context, 1) + contexts := make(map[string]*clientcmdApi.Context, 1) contexts[ctxKey] = ctxValue - clusters := make(map[string]*clientcmdapi.Cluster, 1) + clusters := make(map[string]*clientcmdApi.Cluster, 1) clusters[ctxValue.Cluster] = kubeConfig.Clusters[ctxValue.Cluster] - authInfos := make(map[string]*clientcmdapi.AuthInfo, 1) + authInfos := make(map[string]*clientcmdApi.AuthInfo, 1) authInfos[ctxValue.AuthInfo] = kubeConfig.AuthInfos[ctxValue.AuthInfo] - singleConfigs[ctxKey] = &clientcmdapi.Config{ + singleConfigs[ctxKey] = &clientcmdApi.Config{ APIVersion: kubeConfig.APIVersion, Kind: kubeConfig.Kind, CurrentContext: ctxKey, @@ -36,7 +36,7 @@ func Split(kubeConfig *clientcmdapi.Config, kubeConfigFilePath string) map[strin return singleConfigs } -func Validate(kubeConfig *clientcmdapi.Config) error { +func Validate(kubeConfig *clientcmdApi.Config) error { zap.S().Debugf("🐛 Validate Kubernetes configuration") err := clientcmd.Validate(*kubeConfig) if clientcmd.IsConfigurationInvalid(err) { @@ -45,12 +45,12 @@ func Validate(kubeConfig *clientcmdapi.Config) error { return nil } -func Write(kubeConfig *clientcmdapi.Config, filepath string) error { +func Write(kubeConfig *clientcmdApi.Config, filepath string) error { zap.S().Debugf("🐛 Write Kubernetes configuration to file '%s'", filepath) return clientcmd.WriteToFile(*kubeConfig, filepath) } -func CheckIfContextExist(kubeConfig *clientcmdapi.Config, context string) error { +func CheckIfContextExist(kubeConfig *clientcmdApi.Config, context string) error { zap.S().Debugf("🐛 Check context '%s' existence in Kubernetes configuration '%s'", context, kubeConfig.CurrentContext) ctxValue := kubeConfig.Contexts[context] if ctxValue == nil { @@ -61,7 +61,7 @@ func CheckIfContextExist(kubeConfig *clientcmdapi.Config, context string) error return nil } -func CheckIfClusterExist(kubeConfig *clientcmdapi.Config, cluster string) error { +func CheckIfClusterExist(kubeConfig *clientcmdApi.Config, cluster string) error { zap.S().Debugf("🐛 Check cluster '%s' existence in Kubernetes configuration '%s'", cluster, kubeConfig.CurrentContext) clValue := kubeConfig.Clusters[cluster] if clValue == nil { @@ -72,7 +72,7 @@ func CheckIfClusterExist(kubeConfig *clientcmdapi.Config, cluster string) error return nil } -func CheckIfAuthInfoExist(kubeConfig *clientcmdapi.Config, authInfo string) error { +func CheckIfAuthInfoExist(kubeConfig *clientcmdApi.Config, authInfo string) error { zap.S().Debugf("🐛 Check user '%s' existence in Kubernetes configuration '%s'", authInfo, kubeConfig.CurrentContext) authValue := kubeConfig.AuthInfos[authInfo] if authValue == nil { @@ -83,14 +83,14 @@ func CheckIfAuthInfoExist(kubeConfig *clientcmdapi.Config, authInfo string) erro return nil } -func RemoveContext(ctxMap map[string]*clientcmdapi.Context, context string) (map[string]*clientcmdapi.Context, error) { +func RemoveContext(ctxMap map[string]*clientcmdApi.Context, context string) (map[string]*clientcmdApi.Context, error) { ctxValue := ctxMap[context] if ctxValue == nil { zap.S().Debugf("🐛 Context '%s' not found", context) return nil, errors.New("context not found") } - newCtxMap := make(map[string]*clientcmdapi.Context) + newCtxMap := make(map[string]*clientcmdApi.Context) for ctxK, ctxV := range ctxMap { if ctxK != context { newCtxMap[ctxK] = ctxV @@ -99,14 +99,14 @@ func RemoveContext(ctxMap map[string]*clientcmdapi.Context, context string) (map return newCtxMap, nil } -func RemoveCluster(clMap map[string]*clientcmdapi.Cluster, cluster string) (map[string]*clientcmdapi.Cluster, error) { +func RemoveCluster(clMap map[string]*clientcmdApi.Cluster, cluster string) (map[string]*clientcmdApi.Cluster, error) { clValue := clMap[cluster] if clValue == nil { zap.S().Debugf("🐛 Cluster '%s' not found", cluster) return nil, errors.New("cluster not found") } - newClMap := make(map[string]*clientcmdapi.Cluster) + newClMap := make(map[string]*clientcmdApi.Cluster) for clK, clV := range clMap { if clK != cluster { newClMap[clK] = clV @@ -115,14 +115,14 @@ func RemoveCluster(clMap map[string]*clientcmdapi.Cluster, cluster string) (map[ return newClMap, nil } -func RemoveAuthInfo(authMap map[string]*clientcmdapi.AuthInfo, authInfo string) (map[string]*clientcmdapi.AuthInfo, error) { +func RemoveAuthInfo(authMap map[string]*clientcmdApi.AuthInfo, authInfo string) (map[string]*clientcmdApi.AuthInfo, error) { clValue := authMap[authInfo] if clValue == nil { zap.S().Debugf("🐛 User '%s' not found", authInfo) return nil, errors.New("user not found") } - newAuthMap := make(map[string]*clientcmdapi.AuthInfo) + newAuthMap := make(map[string]*clientcmdApi.AuthInfo) for authK, authV := range authMap { if authK != authInfo { newAuthMap[authK] = authV @@ -131,7 +131,7 @@ func RemoveAuthInfo(authMap map[string]*clientcmdapi.AuthInfo, authInfo string) return newAuthMap, nil } -func GetContextsKeys(contexts map[string]*clientcmdapi.Context) []string { +func GetContextsKeys(contexts map[string]*clientcmdApi.Context) []string { keys := make([]string, 0, len(contexts)) for k := range contexts { keys = append(keys, k) @@ -139,7 +139,7 @@ func GetContextsKeys(contexts map[string]*clientcmdapi.Context) []string { return keys } -func GetClustersKeys(clusters map[string]*clientcmdapi.Cluster) []string { +func GetClustersKeys(clusters map[string]*clientcmdApi.Cluster) []string { keys := make([]string, 0, len(clusters)) for k := range clusters { keys = append(keys, k) @@ -147,7 +147,7 @@ func GetClustersKeys(clusters map[string]*clientcmdapi.Cluster) []string { return keys } -func GetAuthInfosKeys(auths map[string]*clientcmdapi.AuthInfo) []string { +func GetAuthInfosKeys(auths map[string]*clientcmdApi.AuthInfo) []string { keys := make([]string, 0, len(auths)) for k := range auths { keys = append(keys, k) @@ -155,20 +155,21 @@ func GetAuthInfosKeys(auths map[string]*clientcmdapi.AuthInfo) []string { return keys } -func PrintOnLogs(kubeConfig *clientcmdapi.Config, isDebug bool) { +// PrintOnLogs is for development and debugging purposes only +func PrintOnLogs(kCfg *clientcmdApi.Config, isDebug bool) { if isDebug { - // logger.SugaredLogger.Debugf("Api version: %s", kubeConfig.APIVersion) - // logger.SugaredLogger.Debugf("Kind: %s", kubeConfig.Kind) - zap.S().Debugf("Current context: %s", kubeConfig.CurrentContext) - zap.S().Debugf("Contexts: %s", strings.Join(GetContextsKeys(kubeConfig.Contexts), ", ")) - zap.S().Debugf("Clusters: %s", strings.Join(GetClustersKeys(kubeConfig.Clusters), ", ")) - zap.S().Debugf("Users: %s", strings.Join(GetAuthInfosKeys(kubeConfig.AuthInfos), ", ")) + // zap.S().Debugf("Api version: %s", kCfg.APIVersion) + // zap.S().Debugf("Kind: %s", kCfg.Kind) + zap.S().Debugf("Current context: %s", kCfg.CurrentContext) + zap.S().Debugf("Contexts: %s", strings.Join(GetContextsKeys(kCfg.Contexts), ", ")) + zap.S().Debugf("Clusters: %s", strings.Join(GetClustersKeys(kCfg.Clusters), ", ")) + zap.S().Debugf("Users: %s", strings.Join(GetAuthInfosKeys(kCfg.AuthInfos), ", ")) } else { - // logger.SugaredLogger.Infof("Api version: %s", kubeConfig.APIVersion) - // logger.SugaredLogger.Infof("Kind: %s", kubeConfig.Kind) - zap.S().Infof("Current context: %s", kubeConfig.CurrentContext) - zap.S().Infof("Contexts: %s", strings.Join(GetContextsKeys(kubeConfig.Contexts), ", ")) - zap.S().Infof("Clusters: %s", strings.Join(GetClustersKeys(kubeConfig.Clusters), ", ")) - zap.S().Infof("Users: %s", strings.Join(GetAuthInfosKeys(kubeConfig.AuthInfos), ", ")) + // logger.SugaredLogger.Infof("Api version: %s", kCfg.APIVersion) + // logger.SugaredLogger.Infof("Kind: %s", kCfg.Kind) + zap.S().Infof("Current context: %s", kCfg.CurrentContext) + zap.S().Infof("Contexts: %s", strings.Join(GetContextsKeys(kCfg.Contexts), ", ")) + zap.S().Infof("Clusters: %s", strings.Join(GetClustersKeys(kCfg.Clusters), ", ")) + zap.S().Infof("Users: %s", strings.Join(GetAuthInfosKeys(kCfg.AuthInfos), ", ")) } }