-
Notifications
You must be signed in to change notification settings - Fork 262
Refactor workflow #3197
Refactor workflow #3197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,18 +10,19 @@ import ( | |
| ) | ||
|
|
||
| var ( | ||
| clusterInitCommand = kingpin.Command("init", "Initialize a new Tectonic cluster") | ||
| clusterInitConfigFlag = clusterInitCommand.Flag("config", "Cluster specification file").Required().ExistingFile() | ||
| clusterInitCommand = kingpin.Command("init", "Initialize a new Tectonic cluster") | ||
| clusterInitConfigFlag = clusterInitCommand.Flag("config", "Cluster specification file").Required().ExistingFile() | ||
| clusterInitWorkspaceNameFlag = clusterInitCommand.Flag("workspace", "Workspace folder name").Required().String() | ||
|
|
||
| clusterInstallCommand = kingpin.Command("install", "Create a new Tectonic cluster") | ||
| clusterInstallAssetsCommand = clusterInstallCommand.Command("assets", "Generate Tectonic assets.") | ||
| clusterInstallBootstrapCommand = clusterInstallCommand.Command("bootstrap", "Create a single bootstrap node Tectonic cluster.") | ||
| clusterInstallFullCommand = clusterInstallCommand.Command("full", "Create a new Tectonic cluster").Default() | ||
| clusterInstallJoinCommand = clusterInstallCommand.Command("join", "Create master and worker nodes to join an exisiting Tectonic cluster.") | ||
| clusterInstallDirFlag = clusterInstallCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir() | ||
| clusterInstallWorkspaceFlag = clusterInstallCommand.Flag("workspace", "Workspace directory").Default(".").ExistingDir() | ||
|
|
||
| clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster") | ||
| clusterDestroyDirFlag = clusterDestroyCommand.Flag("dir", "Cluster directory").Default(".").ExistingDir() | ||
| clusterDestroyCommand = kingpin.Command("destroy", "Destroy an existing Tectonic cluster") | ||
| clusterDestroyWorkspaceFlag = clusterDestroyCommand.Flag("workspace", "Workspace directory").Default(".").ExistingDir() | ||
|
|
||
| convertCommand = kingpin.Command("convert", "Convert a tfvars.json to a Tectonic config.yaml") | ||
| convertConfigFlag = convertCommand.Flag("config", "tfvars.json file").Required().ExistingFile() | ||
|
|
@@ -30,33 +31,48 @@ var ( | |
| ) | ||
|
|
||
| func main() { | ||
| var w workflow.Workflow | ||
| var c *workflow.Cluster | ||
| var err error | ||
|
|
||
| newCluster := func(clusterInstallDirFlag string) *workflow.Cluster { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| l, err := log.ParseLevel(*logLevel) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creating a cluster should be separate from parsing the log level. In fact, this change introduces a new behavior where log levels are not parsed for the |
||
| if err != nil { | ||
| // By definition we should never enter this condition since kingpin should be guarding against incorrect values. | ||
| log.Fatalf("invalid log-level: %v", err) | ||
| } | ||
| log.SetLevel(l) | ||
|
|
||
| c, err = workflow.NewCluster(clusterInstallDirFlag) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| os.Exit(1) | ||
| } | ||
| return c | ||
| } | ||
|
|
||
| switch kingpin.Parse() { | ||
| case clusterInitCommand.FullCommand(): | ||
| w = workflow.NewInitWorkflow(*clusterInitConfigFlag) | ||
| err = workflow.InitWorkspace(*clusterInitConfigFlag, *clusterInitWorkspaceNameFlag) | ||
| case clusterInstallFullCommand.FullCommand(): | ||
| w = workflow.NewInstallFullWorkflow(*clusterInstallDirFlag) | ||
| c = newCluster(*clusterInstallWorkspaceFlag) | ||
| err = c.Install() | ||
| case clusterInstallAssetsCommand.FullCommand(): | ||
| w = workflow.NewInstallAssetsWorkflow(*clusterInstallDirFlag) | ||
| c = newCluster(*clusterInstallWorkspaceFlag) | ||
| err = c.Assets() | ||
| case clusterInstallBootstrapCommand.FullCommand(): | ||
| w = workflow.NewInstallBootstrapWorkflow(*clusterInstallDirFlag) | ||
| c = newCluster(*clusterInstallWorkspaceFlag) | ||
| err = c.Bootstrap() | ||
| case clusterInstallJoinCommand.FullCommand(): | ||
| w = workflow.NewInstallJoinWorkflow(*clusterInstallDirFlag) | ||
| c = newCluster(*clusterInstallWorkspaceFlag) | ||
| err = c.Scale() | ||
| case clusterDestroyCommand.FullCommand(): | ||
| w = workflow.NewDestroyWorkflow(*clusterDestroyDirFlag) | ||
| c = newCluster(*clusterInstallWorkspaceFlag) | ||
| err = c.Destroy() | ||
| case convertCommand.FullCommand(): | ||
| w = workflow.NewConvertWorkflow(*convertConfigFlag) | ||
| err = workflow.TF2YAML(*convertConfigFlag) | ||
| } | ||
|
|
||
| l, err := log.ParseLevel(*logLevel) | ||
| if err != nil { | ||
| // By definition we should never enter this condition since kingpin should be guarding against incorrect values. | ||
| log.Fatalf("invalid log-level: %v", err) | ||
| } | ||
| log.SetLevel(l) | ||
|
|
||
| if err := w.Execute(); err != nil { | ||
| log.Fatal(err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/apparentlymart/go-cidr/cidr" | ||
|
|
@@ -33,6 +35,14 @@ const ( | |
| ingressConfigIngressKind = "NodePort" | ||
| certificatesStrategy = "userProvidedCA" | ||
| identityAPIService = "tectonic-identity-api.tectonic-system.svc.cluster.local" | ||
|
|
||
| generatedPath = "generated" | ||
| kcoConfigFileName = "kco-config.yaml" | ||
| tncoConfigFileName = "tnco-config.yaml" | ||
| kubeSystemPath = "generated/manifests" | ||
| kubeSystemFileName = "cluster-config.yaml" | ||
| tectonicSystemPath = "generated/tectonic" | ||
| tectonicSystemFileName = "cluster-config.yaml" | ||
| ) | ||
|
|
||
| // ConfigGenerator defines the cluster config generation for a cluster. | ||
|
|
@@ -290,6 +300,62 @@ func marshalYAML(obj interface{}) (string, error) { | |
| return string(data), nil | ||
| } | ||
|
|
||
| // GenerateClusterConfigMaps returns, if successful, the cluster kubernetes configMaps | ||
| func (c ConfigGenerator) GenerateClusterConfigMaps(workspace string) error { | ||
| clusterGeneratedPath := filepath.Join(workspace, generatedPath) | ||
| if err := os.MkdirAll(clusterGeneratedPath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create cluster generated directory at %s", clusterGeneratedPath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We typically make errors lower-case so they can be wrapped. |
||
| } | ||
|
|
||
| kcoConfig, err := c.CoreConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| kcoConfigFilePath := filepath.Join(clusterGeneratedPath, kcoConfigFileName) | ||
| if err := writeFile(kcoConfigFilePath, kcoConfig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tncoConfig, err := c.TncoConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tncoConfigFilePath := filepath.Join(clusterGeneratedPath, tncoConfigFileName) | ||
| if err := writeFile(tncoConfigFilePath, tncoConfig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| kubeSystem, err := c.KubeSystem() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| kubePath := filepath.Join(workspace, kubeSystemPath) | ||
| if err := os.MkdirAll(kubePath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create manifests directory at %s", kubePath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| } | ||
|
|
||
| kubeSystemConfigFilePath := filepath.Join(kubePath, kubeSystemFileName) | ||
| if err := writeFile(kubeSystemConfigFilePath, kubeSystem); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tectonicSystem, err := c.TectonicSystem() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tectonicPath := filepath.Join(workspace, tectonicSystemPath) | ||
| if err := os.MkdirAll(tectonicPath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create tectonic directory at %s", tectonicPath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| } | ||
|
|
||
| tectonicSystemConfigFilePath := filepath.Join(tectonicPath, tectonicSystemFileName) | ||
| return writeFile(tectonicSystemConfigFilePath, tectonicSystem) | ||
| } | ||
|
|
||
| func (c ConfigGenerator) getEtcdServersURLs() string { | ||
| if len(c.Cluster.Etcd.External.Servers) > 0 { | ||
| return strings.Join(c.Cluster.Etcd.External.Servers, ",") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pull this function definition out of the
mainfunc? there is no need to do this inline.