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

*: Pass the master, worker and bootstrap ignition content to the terraform. #301

Closed
wants to merge 2 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
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)
}
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 @@ -33,8 +33,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/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data "terraform_remote_state" "assets" {
}

locals {
ignition_bootstrap = "${data.terraform_remote_state.assets.ignition_bootstrap}"
ignition_bootstrap = "${var.ignition_bootstrap != "" ? var.ignition_bootstrap : data.terraform_remote_state.assets.ignition_bootstrap}"
}
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
6 changes: 5 additions & 1 deletion steps/infra/libvirt/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ data "terraform_remote_state" "assets" {
config {
path = "${path.cwd}/assets.tfstate"
}

defaults {
ignition_bootstrap = ""
}
}

locals {
ignition_bootstrap = "${data.terraform_remote_state.assets.ignition_bootstrap}"
ignition_bootstrap = "${var.ignition_bootstrap != "" ? var.ignition_bootstrap : data.terraform_remote_state.assets.ignition_bootstrap}"
}
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