-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(save-load): support save and load kubeconfigs
- Loading branch information
Showing
5 changed files
with
188 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var loadOpt saveOption | ||
|
||
type loadOption struct { | ||
filePath string | ||
} | ||
|
||
// loadCmd represents the load command | ||
var loadCmd = &cobra.Command{ | ||
Use: "load", | ||
Short: "load kubeconfigs from saved file", | ||
Long: `load kubeconfigs from saved file`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
m, err := newManagerInterface() | ||
if err != nil { | ||
log.Fatalf("fatal: %v", err) | ||
} | ||
err = m.Load(loadOpt.filePath) | ||
if err != nil { | ||
log.Fatalf("load failed: %v", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(loadCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// loadCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
loadCmd.Flags().StringVarP(&loadOpt.filePath, "file-path", "f", "", "load all kubeconfigs from file path") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var saveOpt saveOption | ||
|
||
type saveOption struct { | ||
filePath string | ||
} | ||
|
||
// saveCmd represents the save command | ||
var saveCmd = &cobra.Command{ | ||
Use: "save", | ||
Short: "save all kubeconfigs into a single file", | ||
Long: `you can use save command to export all kubeconfigs into a single file. And also you can use load command to import all of these kubeconfigs`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
m, err := newManagerInterface() | ||
if err != nil { | ||
log.Fatalf("fatal: %v", err) | ||
} | ||
err = m.Save(saveOpt.filePath) | ||
if err != nil { | ||
log.Fatalf("save failed: %v", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(saveCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// saveCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
saveCmd.Flags().StringVarP(&saveOpt.filePath, "file-path", "f", "", "saved file path for all kubeconfigs") | ||
} |
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package types | ||
|
||
// SavedConfig ... | ||
type SavedConfig struct { | ||
Current string `json:"current" yaml:"current"` | ||
Items []SavedConfigItem `json:"items" yaml:"items"` | ||
} | ||
|
||
// SavedConfigItem ... | ||
type SavedConfigItem struct { | ||
Name string `json:"name" yaml:"name"` | ||
Content string `json:"content" yaml:"content"` | ||
} |