Skip to content

Commit

Permalink
*: Pass the master and worker ignition content to the terraform.
Browse files Browse the repository at this point in the history
Previously, the installer binary generates the ignitions for master
and worker nodes, and pass the filename to the terraform.

However, in the new installer binary, we will instead pass the content
of the ignition files to terraform.
  • Loading branch information
Yifan Gu authored and crawford committed Sep 23, 2018
1 parent 4cfda6f commit 927e18c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
8 changes: 4 additions & 4 deletions config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,21 @@ 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
}

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)
}
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
29 changes: 28 additions & 1 deletion installer/pkg/workflow/install.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package workflow

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

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

// InstallWorkflow creates new instances of the 'install' workflow,
Expand Down Expand Up @@ -46,7 +49,31 @@ func runInstallStep(m *metadata, step string, extraArgs ...string) error {

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
2 changes: 1 addition & 1 deletion modules/aws/master/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ resource "aws_instance" "master" {
iam_instance_profile = "${aws_iam_instance_profile.master.name}"
instance_type = "${var.ec2_type}"
subnet_id = "${element(var.subnet_ids, count.index)}"
user_data = "${file(format("%s/%s", path.cwd, var.user_data_igns[count.index]))}"
user_data = "${var.user_data_igns[count.index]}"

vpc_security_group_ids = ["${var.master_sg_ids}"]
associate_public_ip_address = "${var.public_endpoints}"
Expand Down
24 changes: 4 additions & 20 deletions pkg/types/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
)

const (
// IgnitionPathMaster is the relative path to the ign master cfg from the tf working directory
// This is a format string so that the index can be populated later
IgnitionPathMaster = "master-%d.ign"
// IgnitionPathWorker is the relative path to the ign worker cfg from the tf working directory
IgnitionPathWorker = "worker.ign"
// PlatformAWS is the platform for a cluster launched on AWS.
PlatformAWS Platform = "aws"
// PlatformLibvirt is the platform for a cluster launched on libvirt.
Expand Down Expand Up @@ -75,14 +70,9 @@ type Cluster struct {
BaseDomain string `json:"tectonic_base_domain,omitempty" yaml:"baseDomain,omitempty"`
CA `json:",inline" yaml:"CA,omitempty"`

// Deprecated, will be removed soon.
IgnitionMasterPaths []string `json:"tectonic_ignition_masters,omitempty" yaml:"-"`
// Deprecated, will be removed soon.
IgnitionWorkerPath string `json:"tectonic_ignition_worker,omitempty" yaml:"-"`

IgnitionBootstrap string `json:"openshift_ignition_bootstrap,omitempty" yaml:"-"`
IgnitionMasters []string `json:"openshift_ignition_master,omitempty" yaml:"-"`
IgnitionWorker string `json:"openshift_ignition_worker,omitempty" yaml:"-"`
IgnitionBootstrap string `json:"ignition_bootstrap,omitempty" yaml:"-"`
IgnitionMasters []string `json:"ignition_masters,omitempty" yaml:"-"`
IgnitionWorker string `json:"ignition_worker,omitempty" yaml:"-"`

Internal `json:",inline" yaml:"-"`
libvirt.Libvirt `json:",inline" yaml:"libvirt,omitempty"`
Expand Down Expand Up @@ -116,13 +106,7 @@ func (c *Cluster) TFVars() (string, error) {
c.Master.Count = c.NodeCount(c.Master.NodePools)
c.Worker.Count = c.NodeCount(c.Worker.NodePools)

for i := 0; i < c.Master.Count; i++ {
c.IgnitionMasterPaths = append(c.IgnitionMasterPaths, fmt.Sprintf(IgnitionPathMaster, i))
}

c.IgnitionWorkerPath = IgnitionPathWorker

// fill in master ips
// Fill in master ips
if c.Platform == PlatformLibvirt {
if err := c.Libvirt.TFVars(c.Master.Count, c.Worker.Count); err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion steps/assets/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ module assets_base {
tectonic_service_cidr = "${var.tectonic_service_cidr}"
tectonic_update_channel = "${var.tectonic_update_channel}"
tectonic_versions = "${var.tectonic_versions}"
aws_worker_ign_config = "${file("worker.ign")}"
aws_worker_ign_config = "${var.ignition_worker}"
}
2 changes: 1 addition & 1 deletion steps/infra/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module "masters" {
root_volume_type = "${var.tectonic_aws_master_root_volume_type}"
subnet_ids = "${module.vpc.master_subnet_ids}"
ec2_ami = "${var.tectonic_aws_ec2_ami_override}"
user_data_igns = "${var.tectonic_ignition_masters}"
user_data_igns = ["${var.ignition_masters}"]
}

module "iam" {
Expand Down
4 changes: 2 additions & 2 deletions steps/infra/libvirt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ resource "libvirt_volume" "master" {
resource "libvirt_ignition" "master" {
count = "${var.tectonic_master_count}"
name = "master-${count.index}.ign"
content = "${file(format("%s/%s", path.cwd, var.tectonic_ignition_masters[count.index]))}"
content = "${var.ignition_masters[count.index]}"
}

resource "libvirt_ignition" "worker" {
name = "worker.ign"
content = "${file("${path.cwd}/${var.tectonic_ignition_worker}")}"
content = "${var.ignition_worker}"
}

resource "libvirt_network" "tectonic_net" {
Expand Down

1 comment on commit 927e18c

@wking
Copy link
Member

@wking wking commented on 927e18c Sep 25, 2018

Choose a reason for hiding this comment

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

This commit broke libvirt deletion (and possibly AWS deletion, although I haven't checked). With this commit, we get:

$ installer/tectonic destroy --dir=trking-0ef0f
...
Error: libvirt_ignition.master: 1 error(s) occurred:

* libvirt_ignition.master: At column 23, line 1: list "var.ignition_masters" does not have any elements so cannot determine type. in:

${var.ignition_masters[count.index]}
...

and no libvirt resources are removed.

The generated tectonic-dev/trking-0ef0f/terraform.tfvars lacks the ignition files (which makes sense for the old installer, where they were read from the disk). Is there a way we can support both the old and new installer during this transition period? Or is this the nail in the coffin on the old installer? Do you know how installation via the old installer works at all with this commit?

Please sign in to comment.