Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Multistep bootstrap - WIP #2802

Closed
wants to merge 5 commits into from
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
5 changes: 5 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ alias(
actual = "//installer/cmd/installer:installer",
)

alias(
name = "cli",
actual = "//installer/cmd/tectonic:tectonic",
)

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

# We use a genrule here to combine the tarballs rather than a pkg_tar
Expand Down
28 changes: 0 additions & 28 deletions config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ variable "tectonic_etcd_count" {
description = <<EOF
The number of etcd nodes to be created.
If set to zero, the count of etcd nodes will be determined automatically.

Note: This is not supported on bare metal.
EOF
}
Expand All @@ -176,7 +175,6 @@ variable "tectonic_etcd_servers" {
Needs to be set if using an external etcd cluster.
Note: If this variable is defined, the installer will not create self-signed certs.
To provide a CA certificate to trust the etcd servers, set "tectonic_etcd_ca_cert_path".

Example: `["etcd1", "etcd2", "etcd3"]`
EOF

Expand All @@ -190,7 +188,6 @@ variable "tectonic_etcd_ca_cert_path" {

description = <<EOF
(optional) The path of the file containing the CA certificate for TLS communication with etcd.

Note: This works only when used in conjunction with an external etcd cluster.
If set, the variable `tectonic_etcd_servers` must also be set.
EOF
Expand All @@ -202,7 +199,6 @@ variable "tectonic_etcd_client_cert_path" {

description = <<EOF
(optional) The path of the file containing the client certificate for TLS communication with etcd.

Note: This works only when used in conjunction with an external etcd cluster.
If set, the variables `tectonic_etcd_servers`, `tectonic_etcd_ca_cert_path`, and `tectonic_etcd_client_key_path` must also be set.
EOF
Expand All @@ -214,7 +210,6 @@ variable "tectonic_etcd_client_key_path" {

description = <<EOF
(optional) The path of the file containing the client key for TLS communication with etcd.

Note: This works only when used in conjunction with an external etcd cluster.
If set, the variables `tectonic_etcd_servers`, `tectonic_etcd_ca_cert_path`, and `tectonic_etcd_client_cert_path` must also be set.
EOF
Expand All @@ -226,12 +221,9 @@ variable "tectonic_base_domain" {
description = <<EOF
The base DNS domain of the cluster. It must NOT contain a trailing period. Some
DNS providers will automatically add this if necessary.

Example: `openstack.dev.coreos.systems`.

Note: This field MUST be set manually prior to creating the cluster.
This applies only to cloud platforms.

[Azure-specific NOTE]
To use Azure-provided DNS, `tectonic_base_domain` should be set to `""`
If using DNS records, ensure that `tectonic_base_domain` is set to a properly configured external DNS zone.
Expand All @@ -245,7 +237,6 @@ variable "tectonic_cluster_name" {
description = <<EOF
The name of the cluster.
If used in a cloud-environment, this will be prepended to `tectonic_base_domain` resulting in the URL to the Tectonic console.

Note: This field MUST be set manually prior to creating the cluster.
Warning: Special characters in the name like '.' may cause errors on OpenStack platforms due to resource name constraints.
EOF
Expand All @@ -260,11 +251,8 @@ The path the pull secret file in JSON format.
This is known to be a "Docker pull secret" as produced by the docker login [1] command.
A sample JSON content is shown in [2].
You can download the pull secret from your Account overview page at [3].

[1] https://docs.docker.com/engine/reference/commandline/login/

[2] https://coreos.com/os/docs/latest/registry-authentication.html#manual-registry-auth-setup

[3] https://account.coreos.com/overview
EOF
}
Expand All @@ -276,7 +264,6 @@ variable "tectonic_license_path" {
description = <<EOF
The path to the tectonic licence file.
You can download the Tectonic license file from your Account overview page at [1].

[1] https://account.coreos.com/overview
EOF
}
Expand All @@ -287,7 +274,6 @@ variable "tectonic_container_linux_channel" {

description = <<EOF
(optional) The Container Linux update channel.

Examples: `stable`, `beta`, `alpha`
EOF
}
Expand All @@ -298,7 +284,6 @@ variable "tectonic_container_linux_version" {

description = <<EOF
The Container Linux version to use. Set to `latest` to select the latest available version for the selected update channel.

Examples: `latest`, `1465.6.0`
EOF
}
Expand Down Expand Up @@ -328,7 +313,6 @@ variable "tectonic_admin_email" {
(internal) The e-mail address used to:
1. login as the admin user to the Tectonic Console.
2. generate DNS zones for some providers.

Note: This field MUST be in all lower-case e-mail address format and set manually prior to creating the cluster.
EOF
}
Expand All @@ -338,7 +322,6 @@ variable "tectonic_admin_password" {

description = <<EOF
(internal) The admin user password to login to the Tectonic Console.

Note: This field MUST be set manually prior to creating the cluster. Backslashes and double quotes must
also be escaped.
EOF
Expand Down Expand Up @@ -398,7 +381,6 @@ variable "tectonic_ddns_server" {

description = <<EOF
(optional) This only applies if you use the modules/dns/ddns module.

Specifies the RFC2136 Dynamic DNS server IP/host to register IP addresses to.
EOF
}
Expand All @@ -409,7 +391,6 @@ variable "tectonic_ddns_key_name" {

description = <<EOF
(optional) This only applies if you use the modules/dns/ddns module.

Specifies the RFC2136 Dynamic DNS server key name.
EOF
}
Expand All @@ -420,7 +401,6 @@ variable "tectonic_ddns_key_algorithm" {

description = <<EOF
(optional) This only applies if you use the modules/dns/ddns module.

Specifies the RFC2136 Dynamic DNS server key algorithm.
EOF
}
Expand All @@ -431,7 +411,6 @@ variable "tectonic_ddns_key_secret" {

description = <<EOF
(optional) This only applies if you use the modules/dns/ddns module.

Specifies the RFC2136 Dynamic DNS server key secret.
EOF
}
Expand All @@ -441,13 +420,9 @@ variable "tectonic_networking" {

description = <<EOF
(optional) Configures the network to be used in Tectonic. One of the following values can be used:

- "flannel": enables overlay networking only. This is implemented by flannel using VXLAN.

- "canal": enables overlay networking including network policy. Overlay is implemented by flannel using VXLAN. Network policy is implemented by Calico.

- "calico-ipip": [ALPHA] enables BGP based networking. Routing and network policy is implemented by Calico. Note this has been tested on baremetal installations only.

- "none": disables the installation of any Pod level networking layer provided by Tectonic. By setting this value, users are expected to deploy their own solution to enable network connectivity for Pods and Services.
EOF
}
Expand Down Expand Up @@ -486,7 +461,6 @@ variable "tectonic_http_proxy_address" {

description = <<EOF
(optional) HTTP proxy address.

Example: `http://myproxy.example.com`
EOF
}
Expand All @@ -497,7 +471,6 @@ variable "tectonic_https_proxy_address" {

description = <<EOF
(optional) HTTPS proxy address.

Example: `http://myproxy.example.com`
EOF
}
Expand All @@ -508,7 +481,6 @@ variable "tectonic_no_proxy" {

description = <<EOF
(optional) List of local endpoints that will not use HTTP proxy.

Example: `["127.0.0.1","localhost",".example.com","10.3.0.1"]`
EOF
}
47 changes: 47 additions & 0 deletions installer/cmd/tectonic/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = [
"main.go",
],
importpath = "github.com/coreos/tectonic-installer/installer/cmd/tectonic",
visibility = ["//visibility:private"],
deps = [
"//installer/pkg/workflow:go_default_library",
"//installer/pkg/tectonic:go_default_library",
"//installer/vendor/gopkg.in/alecthomas/kingpin.v2:go_default_library",
],
)

go_binary(
name = "tectonic",
embed = [":go_default_library"],
importpath = "github.com/coreos/tectonic-installer/installer/cmd/tectonic",
visibility = ["//visibility:public"],
# Use pure to build a pure-go binary.
# This has the nice side effect of making the binary statically linked.
pure = "on",
)

go_binary(
name = "tectonic_darwin",
embed = [":go_default_library"],
importpath = "github.com/coreos/tectonic-installer/installer/cmd/tectonic",
visibility = ["//visibility:public"],
# Use pure to build a pure-go binary.
# This has the nice side effect of making the binary statically linked.
pure = "on",
goos = "darwin",
)

go_binary(
name = "tectonic_linux",
embed = [":go_default_library"],
importpath = "github.com/coreos/tectonic-installer/installer/cmd/tectonic",
visibility = ["//visibility:public"],
# Use pure to build a pure-go binary.
# This has the nice side effect of making the binary statically linked.
pure = "on",
goos = "linux",
)
29 changes: 29 additions & 0 deletions installer/cmd/tectonic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"github.com/coreos/tectonic-installer/installer/pkg/workflow"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
dryRunFlag = kingpin.Flag("dry-run", "Just pretend, but don't do anything").Bool()
clusterInstallCommand = kingpin.Command("install", "Create a new Tectonic cluster")
clusterDeleteCommand = kingpin.Command("delete", "Delete an existing Tectonic cluster")
deleteClusterDir = clusterDeleteCommand.Arg("dir", "The name of the cluster to delete").String()
clusterConfigFlag = clusterInstallCommand.Flag("config", "Cluster specification file").Required().ExistingFile()
)

func main() {
switch kingpin.Parse() {
case clusterInstallCommand.FullCommand():
{
w := workflow.NewInstallWorkflow(*clusterConfigFlag)
w.Execute()
}
case clusterDeleteCommand.FullCommand():
{
w := workflow.NewDestroyWorkflow(*deleteClusterDir)
w.Execute()
}
}
}
1 change: 1 addition & 0 deletions installer/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ import:
- json/parser
- json/scanner
- json/token
- package: gopkg.in/alecthomas/kingpin.v2
10 changes: 10 additions & 0 deletions installer/pkg/tectonic/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"buildstate.go",
],
importpath = "github.com/coreos/tectonic-installer/installer/pkg/tectonic",
visibility = ["//installer:__subpackages__"],
)
40 changes: 40 additions & 0 deletions installer/pkg/tectonic/buildstate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tectonic

import (
"errors"
"log"
"os"
"path/filepath"
)

// ClusterNameFromConfig determines the name of the cluster form a
// configuration object specified by the user.
// TEMPORARY: This is a stub, until we wire in the cluster config object.
func ClusterNameFromConfig(varfile string) (string, error) {
// TODO @spangenberg: implement this based on parsed config object.
return "", errors.New("not found")
}

// NewBuildLocation creates a new directory on disk that will become
// the root location for all statefull artefacts of the current cluster build.
func NewBuildLocation(clusterName string) string {
var err error
pwd, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to get current directory because: %v", err)
}
buildPath := filepath.Join(pwd, clusterName)
err = os.MkdirAll(buildPath, os.ModeDir|0755)
if err != nil {
log.Fatalf("Failed to create build folder at %s", buildPath)
}
return buildPath
}

// FindTemplatesForType determines the location of top-level
// Terraform templates for a given type (platform) of build.
// TEMPORARY: implement actual detection of templates from released artefacts.
func FindTemplatesForType(buildType string) string {
pwd, _ := os.Getwd()
return filepath.Join(pwd, "platforms", buildType)
}
15 changes: 15 additions & 0 deletions installer/pkg/workflow/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"destroy.go",
"install.go",
"workflow.go",
],
importpath = "github.com/coreos/tectonic-installer/installer/pkg/workflow",
visibility = ["//visibility:public"],
deps = [
"//installer/pkg/tectonic:go_default_library",
],
)
49 changes: 49 additions & 0 deletions installer/pkg/workflow/destroy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package workflow

import (
"log"
"os"
"os/exec"

"github.com/coreos/tectonic-installer/installer/pkg/tectonic"
)

// NewDestroyWorkflow creates new instances of the 'destroy' workflow,
// responsible for running the actions required to remove resources
// of an existing cluster and clean up any remaining artefacts.
func NewDestroyWorkflow(buildPath string) Workflow {
pathStat, err := os.Stat(buildPath)
// TODO: add deeper checking of the path for having cluster state
if os.IsNotExist(err) || !pathStat.IsDir() {
log.Fatalf("Provided path %s is not valid cluster state location.", buildPath)
} else if err != nil {
log.Fatalf("%v encountered while validating build location.", err)
}
return simpleWorkflow{
metadata: metadata{
statePath: buildPath,
},
steps: []Step{
terraformPrepareStep,
terraformInitStep,
terraformDestroyStep,
},
}
}

func terraformDestroyStep(m *metadata) error {
if m.statePath == "" {
log.Fatalf("Invalid build location - cannot destroy.")
}
log.Printf("Destroying cluster from %s...", m.statePath)
tfDestroy := exec.Command("terraform", "destroy", "-force", tectonic.FindTemplatesForType("aws")) // TODO: get from cluster config
tfDestroy.Dir = m.statePath
tfDestroy.Stdin = os.Stdin
tfDestroy.Stdout = os.Stdout
tfDestroy.Stderr = os.Stderr
err := tfDestroy.Run()
if err != nil {
return err
}
return nil
}
Loading