Skip to content

Commit

Permalink
Refactor init code into setup package (#1161)
Browse files Browse the repository at this point in the history
* Refactor init code into setup package
* Generic handling for prerequisites that are K8s resources
* Generalized generation of YAML for --dry-run --output yaml
  • Loading branch information
ANeumann82 committed Dec 13, 2019
1 parent 3778b5c commit bbbdd4a
Show file tree
Hide file tree
Showing 15 changed files with 852 additions and 666 deletions.
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)
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

0 comments on commit bbbdd4a

Please sign in to comment.