Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ These instructions can be used for AWS:
export PATH=$(pwd)/installer:$PATH
```

4. Edit Tectonic configuration file including the $CLUSTER_NAME
4. Edit Tectonic configuration file including
```shell
$EDITOR examples/tectonic.aws.yaml
```

5. Init Tectonic CLI
```shell
tectonic init --config=examples/tectonic.aws.yaml
tectonic init --config=examples/tectonic.aws.yaml --workspace=example
```

6. Install Tectonic cluster
```shell
tectonic install --dir=$CLUSTER_NAME
tectonic install --workspace=example
```

7. Teardown Tectonic cluster
```shell
tectonic destroy --dir=$CLUSTER_NAME
tectonic destroy --workspace=example
```

#### Tests
Expand Down
56 changes: 36 additions & 20 deletions installer/cmd/tectonic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -30,33 +31,48 @@ var (
)

func main() {
var w workflow.Workflow
var c *workflow.Cluster
var err error

newCluster := func(clusterInstallDirFlag string) *workflow.Cluster {
Copy link
Contributor

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 main func? there is no need to do this inline.

Copy link
Contributor

Choose a reason for hiding this comment

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

clusterInstallDirFlag is a funny name for this parameter. the function should not care if it is a flag or an argument or how the string was provided to the function. Could simply be named dir.

l, err := log.ParseLevel(*logLevel)
Copy link
Contributor

@squat squat May 9, 2018

Choose a reason for hiding this comment

The 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 convert command since that command does not execute this newCluster func. I think parsing the log level should be done outside of this func.

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)
}
Expand Down
66 changes: 66 additions & 0 deletions installer/pkg/config-generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"errors"
"fmt"
"net"
"os"
"path/filepath"
"strings"

"github.com/apparentlymart/go-cidr/cidr"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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, ",")
Expand Down
8 changes: 2 additions & 6 deletions installer/pkg/workflow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ go_test(
name = "go_default_test",
size = "small",
srcs = [
"init_test.go",
"workflow_test.go",
"cluster_test.go",
],
data = glob(["fixtures/**"]),
embed = [":go_default_library"],
Expand All @@ -16,13 +15,10 @@ go_library(
name = "go_default_library",
srcs = [
"convert.go",
"destroy.go",
"executor.go",
"init.go",
"install.go",
"terraform.go",
"utils.go",
"workflow.go",
"cluster.go",
],
importpath = "github.com/coreos/tectonic-installer/installer/pkg/workflow",
visibility = ["//visibility:public"],
Expand Down
Loading