diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 2b5ceb8..b13ce2b 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -3,25 +3,33 @@ package main import ( "context" "fmt" + "io/ioutil" "os" - "os/exec" + "path/filepath" "strings" "text/tabwriter" + homedir "github.com/mitchellh/go-homedir" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/vishal-biyani/kbrew/pkg/apps" + "github.com/vishal-biyani/kbrew/pkg/apps/helm" "github.com/vishal-biyani/kbrew/pkg/apps/raw" + "github.com/vishal-biyani/kbrew/pkg/config" ) type method string const ( - create method = "create" - delete method = "delete" + install method = "create" + uninstall method = "uninstall" ) var ( + configFile string + namespace string + rootCmd = &cobra.Command{ Use: "kbrew", Short: "Homebrew for your Kubernetes applications", @@ -31,16 +39,18 @@ var ( installCmd = &cobra.Command{ Use: "install [NAME]", Short: "Install application", + Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return manageApp(create, args) + return manageApp(install, args) }, } removeCmd = &cobra.Command{ Use: "remove [NAME]", Short: "Remove application", + Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return manageApp(delete, args) + return manageApp(uninstall, args) }, } @@ -54,6 +64,10 @@ var ( ) func init() { + cobra.OnInitialize(initConfig) + rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is $HOME/.kbrew.yaml)") + rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "default", "namespace") + rootCmd.AddCommand(installCmd) rootCmd.AddCommand(removeCmd) rootCmd.AddCommand(searchCmd) @@ -68,64 +82,85 @@ func Execute() error { return rootCmd.Execute() } +func checkArgs(args []string) error { + if len(args) == 0 { + errors.New("No app name provided.") + } + return nil +} + func manageApp(m method, args []string) error { - var app apps.App - var err error + ctx := context.Background() + c, err := config.New(configFile) + if err != nil { + return nil + } + for _, a := range args { - app, err = raw.New(a) - if err != nil { - // TODO: Check other app types - return err + var app apps.App + // Check if entry exists in config + if c.App.Name != strings.ToLower(a) { + continue } - data, err := app.Manifest(context.Background(), nil) - if err != nil { - return err + + switch c.App.Type { + case config.Helm: + app = helm.New(c.App, namespace) + case config.Raw: + app = raw.New(c.App, namespace) + default: + return errors.New(fmt.Sprintf("Unsupported app type %s", c.App.Type)) } - //fmt.Printf("Data:: \n%s\n", data) - if err := executeCommand(m, data); err != nil { - return err + + switch m { + case install: + return app.Install(ctx, nil) + case uninstall: + return app.Uninstall(ctx) + default: + return errors.New(fmt.Sprintf("Unsupported method %s", m)) } + } return nil } func search(args []string) error { - ctx := context.Background() - // List raw apps - rawApps, err := raw.List(ctx) + // List from config + c, err := config.New(configFile) if err != nil { return err } - //TODO: Support for other app types - if len(args) == 0 { - printList(rawApps) + + if len(args) == 0 || strings.HasPrefix(c.App.Name, args[0]) { + printList(c.App) return nil } - result := []string{} - for _, a := range rawApps { - if strings.HasPrefix(a, args[0]) { - result = append(result, a) - } - } - printList(result) return nil } -func printList(list []string) { +func printList(app config.App) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent) - fmt.Fprintln(w, "NAME\tVERSION") - for _, l := range list { - fmt.Fprintln(w, fmt.Sprintf("%s\t%s", l, "NA")) - } + fmt.Fprintln(w, "NAME\tVERSION\tTYPE") + fmt.Fprintln(w, fmt.Sprintf("%s\t%s\t%s", app.Name, app.Version, app.Type)) w.Flush() } -func executeCommand(m method, data []byte) error { - // Generate code - c := exec.Command("kubectl", string(m), "-f", "-") - c.Stdin = strings.NewReader(string(data)) - c.Stdout = os.Stdout - c.Stderr = os.Stderr - return c.Run() +func initConfig() { + if configFile != "" { + return + } + // Find home directory. + home, err := homedir.Dir() + cobra.CheckErr(err) + + // Generate default config file path + configFile = filepath.Join(home, ".kbrew.yaml") + if _, err := os.Stat(configFile); os.IsNotExist(err) { + // Create file with default config + c := []byte("apiVersion: v1\nkind: kbrew\napps:\n") + err := ioutil.WriteFile(configFile, c, 0644) + cobra.CheckErr(err) + } } diff --git a/go.mod b/go.mod index 52af0e3..4565609 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/vishal-biyani/kbrew go 1.15 require ( + github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 - github.com/spf13/cobra v1.1.1 - github.com/urfave/cli v1.22.5 - github.com/urfave/cli/v2 v2.3.0 + github.com/spf13/cobra v1.1.3 + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 57b95fa..2b384af 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -91,6 +89,7 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -101,8 +100,10 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -111,6 +112,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -153,8 +155,8 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= -github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -166,10 +168,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= -github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= -github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -281,16 +279,16 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/apps/apps.go b/pkg/apps/apps.go index 417538a..ef93aca 100644 --- a/pkg/apps/apps.go +++ b/pkg/apps/apps.go @@ -5,5 +5,14 @@ import ( ) type App interface { - Manifest(ctx context.Context, opt map[string]string) ([]byte, error) + Install(ctx context.Context, opt map[string]string) error + Uninstall(ctx context.Context) error +} + +type BaseApp struct { + URL string + Name string + Namespace string + Digest string + Version string } diff --git a/pkg/apps/helm/helm.go b/pkg/apps/helm/helm.go new file mode 100644 index 0000000..08f38a2 --- /dev/null +++ b/pkg/apps/helm/helm.go @@ -0,0 +1,63 @@ +package helm + +import ( + "context" + "os" + "os/exec" + + "github.com/vishal-biyani/kbrew/pkg/apps" + "github.com/vishal-biyani/kbrew/pkg/config" +) + +type method string + +const ( + install method = "install" + uninstall method = "delete" + upgrade method = "upgrade" +) + +type HelmApp struct { + apps.BaseApp +} + +func New(c config.App, namespace string) *HelmApp { + return &HelmApp{ + apps.BaseApp{ + Name: c.Name, + Namespace: namespace, + Version: c.Version, + URL: c.URL, + Digest: c.SHA256, + }, + } +} + +func (ha *HelmApp) Install(ctx context.Context, options map[string]string) error { + //TODO: Resolve Deps + // Validate and install chart + // TODO(@prasad): Use go sdks + return helmCommand(install, ha.Name, ha.Namespace, ha.URL) +} + +func (ha *HelmApp) Uninstall(ctx context.Context) error { + //TODO: Resolve Deps + // Validate and install chart + // TODO(@prasad): Use go sdks + return helmCommand(uninstall, ha.Name, ha.Namespace, "") +} + +func (ha *HelmApp) Manifest(ctx context.Context, opt map[string]string) ([]byte, error) { + return nil, nil +} + +func helmCommand(m method, name, namespace, url string) error { + // Needs helm3 + c := exec.Command("helm", string(m), name, "--namespace", namespace, url) + if url == "" { + c = exec.Command("helm", string(m), name, "--namespace", namespace) + } + c.Stdout = os.Stdout + c.Stderr = os.Stderr + return c.Run() +} diff --git a/pkg/apps/raw/raw.go b/pkg/apps/raw/raw.go index fa00a27..9bae7c7 100644 --- a/pkg/apps/raw/raw.go +++ b/pkg/apps/raw/raw.go @@ -2,65 +2,50 @@ package raw import ( "context" - "fmt" - "github.com/pkg/errors" - "io/ioutil" "os" - "path/filepath" + "os/exec" + + "github.com/vishal-biyani/kbrew/pkg/apps" + "github.com/vishal-biyani/kbrew/pkg/config" ) -// TODO: relative path -const dataDir = "./data/raw" +type method string + +const ( + install method = "create" + uninstall method = "delete" + upgrade method = "apply" +) -type Raw struct { - app string - options map[string]string +type RawApp struct { + apps.BaseApp } -func New(name string) (*Raw, error) { - if _, err := os.Stat(fmt.Sprintf("%s/%s", dataDir, name)); os.IsNotExist(err) { - return nil, errors.New("Unsupported application") +func New(c config.App, namespace string) *RawApp { + return &RawApp{ + apps.BaseApp{ + Name: c.Name, + Namespace: namespace, + Version: c.Version, + URL: c.URL, + Digest: c.SHA256, + }, } - return &Raw{ - app: name, - }, nil } -func (r *Raw) Manifest(ctx context.Context, opt map[string]string) ([]byte, error) { - return ParseRaw(fmt.Sprintf("./data/raw/%s", r.app)) +func (r *RawApp) Install(ctx context.Context, options map[string]string) error { + // TODO(@prasad): Use go sdks + return kubectlCommand(install, r.Name, r.Namespace, r.URL) } -func List(ctx context.Context) ([]string, error) { - appList := []string{} - files, err := ioutil.ReadDir(dataDir) - if err != nil { - return appList, err - } - - for _, file := range files { - appList = append(appList, file.Name()) - } - return appList, nil +func (r *RawApp) Uninstall(ctx context.Context) error { + // TODO(@prasad): Use go sdks + return kubectlCommand(uninstall, r.Name, r.Namespace, r.URL) } -// TODO: Move to utils -func ParseRaw(path string) ([]byte, error) { - resp := []byte{} - yamlFiles, err := filepath.Glob(path + "/*.yaml") - if err != nil { - return nil, err - } - for _, f := range yamlFiles { - file, err := os.Open(f) // For read access. - if err != nil { - return nil, err - } - b, err := ioutil.ReadAll(file) - if err != nil { - return nil, err - } - resp = append(resp, []byte("---\n")...) - resp = append(resp, b...) - } - return resp, nil +func kubectlCommand(m method, name, namespace, url string) error { + c := exec.Command("kubectl", string(m), "-f", url, "--namespace", namespace) + c.Stdout = os.Stdout + c.Stderr = os.Stderr + return c.Run() } diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 0000000..4c45d69 --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,48 @@ +package config + +import ( + "io/ioutil" + "os" + + "gopkg.in/yaml.v2" +) + +const ( + Raw AppType = "raw" + Helm AppType = "helm" +) + +type AppType string + +type AppConfig struct { + APIVersion string `yaml:"apiVersion"` + Kind string `yaml:"kind"` + App App `yaml:"app"` +} + +type App struct { + Name string `yaml:"name"` + Type AppType `yaml:"type"` + URL string `yaml:"url"` + SHA256 string `yaml:"sha256"` + Version string `yaml:"version"` +} + +func New(path string) (*AppConfig, error) { + c := &AppConfig{} + configFile, err := os.Open(path) + defer configFile.Close() + if err != nil { + return nil, err + } + + b, err := ioutil.ReadAll(configFile) + if err != nil { + return nil, err + } + + if len(b) != 0 { + yaml.Unmarshal(b, c) + } + return c, nil +} diff --git a/testdata/fission-config.yaml b/testdata/fission-config.yaml new file mode 100644 index 0000000..f1300be --- /dev/null +++ b/testdata/fission-config.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: kbrew +app: + name: fission + type: raw + url: https://github.com/fission/fission/releases/download/1.12.0/fission-all-1.12.0.yaml + sha256: + version: 1.12.0 diff --git a/testdata/mysql-config.yaml b/testdata/mysql-config.yaml new file mode 100644 index 0000000..785e9fc --- /dev/null +++ b/testdata/mysql-config.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: kbrew +app: + name: mysql + type: helm + url: https://charts.bitnami.com/bitnami/mysql-8.3.1.tgz + sha256: + version: 8.3.1