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

Add cluster asset to launch an openshift cluster #289

Merged
merged 13 commits into from
Sep 23, 2018
Merged
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
12 changes: 10 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,22 @@ pkg_tar(
strip_prefix = ".",
deps = [
":cli_bin",
":old_cli_bin",
":tf_bin",
],
)

pkg_tar(
name = "cli_bin",
name = "old_cli_bin",
srcs = ["//installer/cmd/tectonic"],
mode = "0777",
mode = "0555",
package_dir = "installer",
)

pkg_tar(
name = "cli_bin",
srcs = ["//cmd/openshift-install"],
mode = "0555",
package_dir = "installer",
)

Expand Down
4 changes: 4 additions & 0 deletions cmd/openshift-install/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ go_library(

go_binary(
name = "openshift-install",
out = "openshift-install",
embed = [":go_default_library"],
# Use pure to build a pure-go binary.
# This has the nice side effect of making the binary statically linked.
pure = "on",
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions cmd/openshift-install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
installConfigCommand = kingpin.Command("install-config", "Generate the Install Config asset")
ignitionConfigsCommand = kingpin.Command("ignition-configs", "Generate the Ignition Config assets")
manifestsCommand = kingpin.Command("manifests", "Generate the Kubernetes manifests")
clusterCommand = kingpin.Command("cluster", "Create an OpenShift cluster")

dirFlag = kingpin.Flag("dir", "assets directory").Default(".").String()
logLevel = kingpin.Flag("log-level", "log level (e.g. \"debug\")").Default("warn").Enum("debug", "info", "warn", "error", "fatal", "panic")
Expand All @@ -39,6 +40,12 @@ func main() {
assetStock.Manifests(),
assetStock.Tectonic(),
}
case clusterCommand.FullCommand():
targetAssets = []asset.Asset{
assetStock.TFVars(),
assetStock.KubeconfigAdmin(),
assetStock.Cluster(),
}
}

l, err := log.ParseLevel(*logLevel)
Expand Down
17 changes: 13 additions & 4 deletions config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,30 @@ variable "tectonic_kubelet_debug_config" {
description = "(internal) debug flags for the kubelet (used in CI only)"
}

variable "tectonic_ignition_masters" {
variable "ignition_masters" {
type = "list"
default = []

description = <<EOF
(internal) Ignition config file paths. This is automatically generated by the installer.
(internal) Ignition config file contents. This is automatically generated by the installer.
EOF
}

variable "tectonic_ignition_worker" {
variable "ignition_worker" {
type = "string"
default = ""

description = <<EOF
(internal) Ignition config file path. This is automatically generated by the installer.
(internal) Ignition config file contents. This is automatically generated by the installer.
EOF
}

variable "ignition_bootstrap" {
type = "string"
default = ""

description = <<EOF
(internal) Ignition config file contents. This is automatically generated by the installer.
EOF
}

Expand Down
34 changes: 15 additions & 19 deletions installer/pkg/config-generator/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const (
)

// GenerateIgnConfig generates Ignition configs for the workers and masters.
func (c *ConfigGenerator) GenerateIgnConfig(clusterDir string) error {
// It returns the content of the ignition files.
func (c *ConfigGenerator) GenerateIgnConfig(clusterDir string) (masterIgns []string, workerIgn string, err error) {
var masters config.NodePool
var workers config.NodePool
for _, pool := range c.NodePools {
Expand All @@ -28,18 +29,18 @@ func (c *ConfigGenerator) GenerateIgnConfig(clusterDir string) error {
case "worker":
workers = pool
default:
return fmt.Errorf("unrecognized role: %s", pool.Name)
return nil, "", fmt.Errorf("unrecognized role: %s", pool.Name)
}
}

ca, err := ioutil.ReadFile(filepath.Join(clusterDir, caPath))
if err != nil {
return err
return nil, "", err
}

workerCfg, err := parseIgnFile(workers.IgnitionFile)
if err != nil {
return fmt.Errorf("failed to parse Ignition config for workers: %v", err)
return nil, "", fmt.Errorf("failed to parse Ignition config for workers: %v", err)
}

// XXX(crawford): The SSH key should only be added to the bootstrap
Expand All @@ -49,13 +50,15 @@ func (c *ConfigGenerator) GenerateIgnConfig(clusterDir string) error {
c.appendCertificateAuthority(&workerCfg, ca)
c.embedAppendBlock(&workerCfg, "worker", "")

if err = ignCfgToFile(workerCfg, filepath.Join(clusterDir, config.IgnitionPathWorker)); err != nil {
return err
ign, err := json.Marshal(&workerCfg)
if err != nil {
return nil, "", fmt.Errorf("failed to marshal worker ignition: %v", err)
}
workerIgn = string(ign)

masterCfg, err := parseIgnFile(masters.IgnitionFile)
if err != nil {
return fmt.Errorf("failed to parse Ignition config for masters: %v", err)
return nil, "", fmt.Errorf("failed to parse Ignition config for masters: %v", err)
}

for i := 0; i < masters.Count; i++ {
Expand All @@ -68,12 +71,14 @@ func (c *ConfigGenerator) GenerateIgnConfig(clusterDir string) error {
c.appendCertificateAuthority(&ignCfg, ca)
c.embedAppendBlock(&ignCfg, "master", fmt.Sprintf("etcd_index=%d", i))

if err = ignCfgToFile(ignCfg, filepath.Join(clusterDir, fmt.Sprintf(config.IgnitionPathMaster, i))); err != nil {
return err
masterIgn, err := json.Marshal(&ignCfg)
if err != nil {
return nil, "", fmt.Errorf("failed to marshal master ignition: %v", err)
}
masterIgns = append(masterIgns, string(masterIgn))
}

return nil
return masterIgns, workerIgn, nil
}

func parseIgnFile(filePath string) (ignconfigtypes.Config, error) {
Expand Down Expand Up @@ -139,12 +144,3 @@ func (c *ConfigGenerator) getMCSURL(role string, query string) string {
}
return u
}

func ignCfgToFile(ignCfg ignconfigtypes.Config, filePath string) error {
data, err := json.MarshalIndent(&ignCfg, "", " ")
if err != nil {
return err
}

return ioutil.WriteFile(filePath, data, 0666)
}
3 changes: 1 addition & 2 deletions installer/pkg/workflow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ go_library(
srcs = [
"convert.go",
"destroy.go",
"executor.go",
"init.go",
"install.go",
"terraform.go",
"utils.go",
"workflow.go",
],
importpath = "github.com/openshift/installer/installer/pkg/workflow",
visibility = ["//visibility:public"],
deps = [
"//installer/pkg/config-generator:go_default_library",
"//pkg/terraform:go_default_library",
"//pkg/types/config:go_default_library",
"//vendor/github.com/Sirupsen/logrus:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
Expand Down
17 changes: 12 additions & 5 deletions installer/pkg/workflow/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/openshift/installer/pkg/terraform"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -39,11 +40,11 @@ func DestroyWorkflow(clusterDir string, contOnErr bool) Workflow {
}

func destroyAssetsStep(m *metadata) error {
return runDestroyStep(m, assetsStep)
return runDestroyStep(m, terraform.AssetsStep)
}

func destroyInfraStep(m *metadata) error {
return runDestroyStep(m, infraStep)
return runDestroyStep(m, terraform.InfraStep)
}

func destroyWorkersStep(m *metadata) error {
Expand Down Expand Up @@ -127,16 +128,22 @@ func deleteWorkerMachineSet(client *clientset.Clientset) error {
}

func runDestroyStep(m *metadata, step string, extraArgs ...string) error {
if !hasStateFile(m.clusterDir, step) {
if !terraform.HasStateFile(m.clusterDir, step) {
// there is no statefile, therefore nothing to destroy for this step
return nil
}
templateDir, err := findStepTemplates(step, m.cluster.Platform)

dir, err := terraform.BaseLocation()
if err != nil {
return err
}

templateDir, err := terraform.FindStepTemplates(dir, step, m.cluster.Platform)
if err != nil {
return err
}

return tfDestroy(m.clusterDir, step, templateDir, extraArgs...)
return terraform.Destroy(m.clusterDir, step, templateDir, extraArgs...)
}

func buildClusterClient(kubeconfig string) (*clientset.Clientset, error) {
Expand Down
5 changes: 0 additions & 5 deletions installer/pkg/workflow/fixtures/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
"tectonic_aws_worker_root_volume_size": 30,
"tectonic_aws_worker_root_volume_type": "gp2",
"tectonic_base_domain": "tectonic-ci.de",
"tectonic_ignition_masters": [
"master-0.ign",
"master-1.ign"
],
"tectonic_ignition_worker": "worker.ign",
"tectonic_libvirt_network_if": "osbr0",
"tectonic_master_count": 2,
"tectonic_cluster_name": "aws-basic",
Expand Down
2 changes: 0 additions & 2 deletions installer/pkg/workflow/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ func InitWorkflow(configFilePath string) Workflow {
metadata: metadata{configFilePath: configFilePath},
steps: []step{
prepareWorspaceStep,
readClusterConfigStep,
generateTerraformVariablesStep,
},
}
}
Expand Down
45 changes: 39 additions & 6 deletions installer/pkg/workflow/install.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package workflow

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/openshift/installer/installer/pkg/config-generator"
"github.com/openshift/installer/pkg/terraform"
"github.com/openshift/installer/pkg/types/config"
)

// InstallWorkflow creates new instances of the 'install' workflow,
Expand All @@ -26,27 +30,56 @@ func InstallWorkflow(clusterDir string) Workflow {
}

func installAssetsStep(m *metadata) error {
return runInstallStep(m, assetsStep)
return runInstallStep(m, terraform.AssetsStep)
}

func installInfraStep(m *metadata) error {
return runInstallStep(m, infraStep)
return runInstallStep(m, terraform.InfraStep)
}

func runInstallStep(m *metadata, step string, extraArgs ...string) error {
templateDir, err := findStepTemplates(step, m.cluster.Platform)
dir, err := terraform.BaseLocation()
if err != nil {
return err
}
if err := tfInit(m.clusterDir, templateDir); err != nil {
templateDir, err := terraform.FindStepTemplates(dir, step, m.cluster.Platform)
if err != nil {
return err
}
if err := terraform.Init(m.clusterDir, templateDir); err != nil {
return err
}
return tfApply(m.clusterDir, step, templateDir, extraArgs...)
_, err = terraform.Apply(m.clusterDir, step, templateDir, extraArgs...)
return err
}

func generateIgnConfigStep(m *metadata) error {
c := configgenerator.New(m.cluster)
return c.GenerateIgnConfig(m.clusterDir)
masterIgns, workerIgn, err := c.GenerateIgnConfig(m.clusterDir)
if err != nil {
return fmt.Errorf("failed to generate ignition configs: %v", err)
}

terraformVariablesFilePath := filepath.Join(m.clusterDir, terraformVariablesFileName)
data, err := ioutil.ReadFile(terraformVariablesFilePath)
if err != nil {
return fmt.Errorf("failed to read terraform.tfvars: %v", err)
}

var cluster config.Cluster
if err := json.Unmarshal(data, &cluster); err != nil {
return fmt.Errorf("failed to unmarshal terraform.tfvars: %v", err)
}

cluster.IgnitionMasters = masterIgns
cluster.IgnitionWorker = workerIgn

data, err = json.MarshalIndent(&cluster, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal terraform.tfvars: %v", err)
}

return ioutil.WriteFile(terraformVariablesFilePath, data, 0666)
}

func generateTLSConfigStep(m *metadata) error {
Expand Down
53 changes: 0 additions & 53 deletions installer/pkg/workflow/terraform.go

This file was deleted.

Loading