Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor init code into setup package #1161

Merged
merged 13 commits into from
Dec 13, 2019
Merged
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/dustinkirkland/golang-petname v0.0.0-20170921220637-d3c2ba80e75e
github.com/ghodss/yaml v1.0.0 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/google/btree v1.0.0 // indirect
Expand Down
38 changes: 7 additions & 31 deletions pkg/kudoctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"io"
"strings"

"github.com/kudobuilder/kudo/pkg/kudoctl/kudoinit"
"github.com/kudobuilder/kudo/pkg/kudoctl/kudoinit/setup"

"github.com/spf13/afero"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
cmdInit "github.com/kudobuilder/kudo/pkg/kudoctl/cmd/init"
"github.com/kudobuilder/kudo/pkg/kudoctl/kube"
"github.com/kudobuilder/kudo/pkg/kudoctl/kudohome"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/repo"
Expand Down Expand Up @@ -133,7 +135,7 @@ func (initCmd *initCmd) validate(flags *flag.FlagSet) error {

// run initializes local config and installs KUDO manager to Kubernetes cluster.
func (initCmd *initCmd) run() error {
opts := cmdInit.NewOptions(initCmd.version, initCmd.ns, initCmd.serviceAccount, webhooksArray(initCmd.webhooks))
opts := kudoinit.NewOptions(initCmd.version, initCmd.ns, initCmd.serviceAccount, webhooksArray(initCmd.webhooks))
// if image provided switch to it.
if initCmd.image != "" {
opts.Image = initCmd.image
Expand All @@ -142,36 +144,10 @@ func (initCmd *initCmd) run() error {
//TODO: implement output=yaml|json (define a type for output to constrain)
//define an Encoder to replace YAMLWriter
if strings.ToLower(initCmd.output) == "yaml" {

var manifests []string

crd, err := cmdInit.CRDs().AsYaml()
manifests, err := setup.AsYamlManifests(opts, initCmd.crdOnly)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍 much cleaner

if err != nil {
return err
}
manifests = append(manifests, crd...)

if !initCmd.crdOnly {
prereq, err := cmdInit.PrereqManifests(opts)
if err != nil {
return err
}
manifests = append(manifests, prereq...)

if len(opts.Webhooks) != 0 { // right now there's only 0 or 1 webhook, so this is good enough
webhooks, err := cmdInit.WebhookManifests(opts.Namespace)
if err != nil {
return err
}
manifests = append(manifests, webhooks...)
}

deploy, err := cmdInit.ManagerManifests(opts)
if err != nil {
return err
}
manifests = append(manifests, deploy...)
}
if err := initCmd.YAMLWriter(initCmd.out, manifests); err != nil {
return err
}
Expand All @@ -198,13 +174,13 @@ func (initCmd *initCmd) run() error {
initCmd.client = client
}

if err := cmdInit.Install(initCmd.client, opts, initCmd.crdOnly); err != nil {
if err := setup.Install(initCmd.client, opts, initCmd.crdOnly); err != nil {
return clog.Errorf("error installing: %s", err)
}

if initCmd.wait {
clog.Printf("⌛Waiting for KUDO controller to be ready in your cluster...")
finished := cmdInit.WatchKUDOUntilReady(initCmd.client.KubeClient, opts, initCmd.timeout)
finished := setup.WatchKUDOUntilReady(initCmd.client.KubeClient, opts, initCmd.timeout)
if !finished {
return errors.New("watch timed out, readiness uncertain")
}
Expand Down
264 changes: 0 additions & 264 deletions pkg/kudoctl/cmd/init/manager.go

This file was deleted.

Loading