forked from kubeflow/kubeflow
-
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.
* kfdef-converter init * add root cmd * change naming * add flag --out * load kfdef into kfconfig * use configconverters to convert KfDef * comment * simple README * add example cmd
- Loading branch information
1 parent
27da9c8
commit fedf5d9
Showing
5 changed files
with
161 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
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,30 @@ | ||
# KfDef version converter | ||
|
||
## Overview | ||
|
||
This is a simple helper CLI that converts KfDef between versions. | ||
|
||
## Usage | ||
|
||
``` | ||
A simple CLI to convert KfDef from v1alpha1 to v1beta1 | ||
Usage: | ||
kfdef-converter [command] | ||
Available Commands: | ||
help Help about any command | ||
tov1beta1 Convert a KfDef config in v1alpha1 into v1beta1 format. | ||
Flags: | ||
-h, --help help for kfdef-converter | ||
Use "kfdef-converter [command] --help" for more information about a command. | ||
``` | ||
|
||
### Example conversion | ||
|
||
Converting to `v1beta1`: | ||
```bash | ||
kfdef-converter tov1beta1 foo/kfdef.yaml -o path/to/output.yaml | ||
``` |
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,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "kfdef-converter", | ||
Short: "A simple CLI to convert KfDef from v1alpha1 to v1beta1.", | ||
Long: "A simple CLI to convert KfDef from v1alpha1 to v1beta1", | ||
} | ||
|
||
var ( | ||
// VERSION is set during build. | ||
VERSION string | ||
) | ||
|
||
func Execute(version string) { | ||
VERSION = version | ||
|
||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
} | ||
|
||
func initConfig() { | ||
} |
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,67 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/kubeflow/kubeflow/bootstrap/v3/pkg/apis/apps/configconverters" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var tov1beta1Cfg = viper.New() | ||
|
||
var ( | ||
OutPathFlag = "out" | ||
) | ||
|
||
var tov1beta1Cmd = &cobra.Command{ | ||
Use: "tov1beta1 <kfdef-v1alpha1-filename>", | ||
Short: "Convert a KfDef config in v1alpha1 into v1beta1 format.", | ||
Long: "Convert a KfDef config in v1alpha1 into v1beta1 format.", | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
log.SetLevel(log.InfoLevel) | ||
|
||
if len(args) > 1 { | ||
return fmt.Errorf("Unknown args: %v", args[1:]) | ||
} else if len(args) < 1 { | ||
return fmt.Errorf("Filename to converting KfDef is required.") | ||
} | ||
|
||
config, err := configconverters.LoadConfigFromURI(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("Error when loading KfDef: %v", err) | ||
} | ||
|
||
log.Infof("KfDef loaded for %v, converting.", args[0]) | ||
outPath := tov1beta1Cfg.GetString(OutPathFlag) | ||
if outPath == "" { | ||
outPath = args[0] | ||
} | ||
|
||
// A hack to force converter to output KfDef in v1beta1. | ||
apiVersion := strings.Split(config.APIVersion, "/") | ||
if len(apiVersion) != 2 { | ||
return fmt.Errorf("Unknown format of API version: %v", config.APIVersion) | ||
} | ||
apiVersion[1] = "v1beta1" | ||
config.APIVersion = strings.Join(apiVersion, "/") | ||
return configconverters.WriteConfigToFile(*config, outPath) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(tov1beta1Cmd) | ||
|
||
tov1beta1Cfg.SetConfigName("conversion") | ||
tov1beta1Cfg.SetConfigType("yaml") | ||
|
||
tov1beta1Cmd.Flags().StringP(OutPathFlag, "o", "", | ||
"Path to write converted KfDef. If not set, the original file will be overriden.") | ||
if err := tov1beta1Cfg.BindPFlag(OutPathFlag, tov1beta1Cmd.Flags().Lookup(OutPathFlag)); err != nil { | ||
log.Errorf("couldn't set flag --%v: %v", OutPathFlag, err) | ||
return | ||
} | ||
} |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kubeflow/kubeflow/bootstrap/v3/cmd/kfdefConverter/cmd" | ||
"github.com/onrik/logrus/filename" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
VERSION = "0.0.1" | ||
) | ||
|
||
func init() { | ||
// Add filename as one of the fields of the structured log message. | ||
filenameHook := filename.NewHook() | ||
filenameHook.Field = "filename" | ||
log.AddHook(filenameHook) | ||
} | ||
|
||
func main() { | ||
cmd.Execute(VERSION) | ||
} |