This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
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.
- Loading branch information
Matteo Baiguini
committed
Feb 2, 2020
1 parent
526f65f
commit 34c3ae4
Showing
5 changed files
with
74 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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,18 +1,44 @@ | ||
package reset | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bygui86/konf/commands" | ||
"github.com/bygui86/konf/commons" | ||
"github.com/bygui86/konf/kubeconfig" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/bygui86/konf/logger" | ||
) | ||
|
||
func reset(ctx *cli.Context) error { | ||
func resetLocal(ctx *cli.Context) error { | ||
logger.Logger.Debug("") | ||
logger.Logger.Debug("🐛 Executing RESET-CFG-LOCAL command") | ||
logger.Logger.Debug("") | ||
|
||
logger.Logger.Info(fmt.Sprintf("unset %s", commons.KubeConfigEnvVar)) | ||
return nil | ||
} | ||
|
||
func resetGlobal(ctx *cli.Context) error { | ||
logger.Logger.Info("") | ||
logger.Logger.Debug("🐛 Executing RESET command") | ||
logger.Logger.Debug("🐛 Executing RESET-CFG-GLOBAL command") | ||
logger.Logger.Debug("") | ||
|
||
logger.Logger.Warn("⚠️ Command not yet implemented ☢️") | ||
logger.Logger.Debug("🐛 Get Kubernetes configuration file path") | ||
kubeConfigFilePath := ctx.String(commons.CustomKubeConfigFlagName) | ||
logger.SugaredLogger.Infof("📖 Load Kubernetes configuration from '%s'", kubeConfigFilePath) | ||
kubeConfig := kubeconfig.Load(kubeConfigFilePath) | ||
// INFO: no need to check if kubeConfig is nil, because the inner method called will exit if it does not find the configuration file | ||
|
||
logger.SugaredLogger.Debugf("♻️ Reset Kubernetes configuration '%s'", kubeConfigFilePath) | ||
kubeConfig.CurrentContext = "" | ||
|
||
valWrErr := commands.ValidateAndWrite(kubeConfig, kubeConfigFilePath) | ||
if valWrErr != nil { | ||
return valWrErr | ||
} | ||
|
||
logger.SugaredLogger.Infof("✅ Completed! Kubernetes configuration reset") | ||
logger.Logger.Info("") | ||
return nil | ||
} |
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,16 +1,42 @@ | ||
package reset | ||
|
||
import ( | ||
"github.com/bygui86/konf/commons" | ||
"github.com/bygui86/konf/kubeconfig" | ||
"github.com/bygui86/konf/utils" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/bygui86/konf/logger" | ||
) | ||
|
||
func BuildCommand() *cli.Command { | ||
logger.Logger.Debug("🐛 Create RESET command") | ||
logger.Logger.Debug("🐛 Create RESET-CONFIG command") | ||
home := utils.GetHomeDirOrExit("reset-cfg") | ||
return &cli.Command{ | ||
Name: "reset", | ||
Usage: "", | ||
Action: reset, | ||
Name: "reset-cfg", | ||
Usage: "Reset local or global Kubernetes configuration", | ||
Subcommands: cli.Commands{ | ||
{ | ||
Name: "local", | ||
Usage: "Reset local Kubernetes configuration (current shell)", | ||
ArgsUsage: "<context>", | ||
Action: resetLocal, | ||
}, | ||
{ | ||
Name: "global", | ||
Usage: "Reset global Kubernetes configuration", | ||
ArgsUsage: "<context>", | ||
Action: resetGlobal, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: utils.GetUrfaveFlagName(commons.CustomKubeConfigFlagName, commons.CustomKubeConfigFlagShort), | ||
Usage: commons.CustomKubeConfigFlagDescription, | ||
EnvVar: commons.CustomKubeConfigPathEnvVar, | ||
Value: kubeconfig.GetCustomKubeConfigPathDefault(home), | ||
Required: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |