Skip to content
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
1 change: 1 addition & 0 deletions installer/pkg/config-generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//installer/pkg/config:go_default_library",
"//installer/pkg/copy:go_default_library",
"//pkg/asset/tls:go_default_library",
"//pkg/types:go_default_library",
"//vendor/github.com/apparentlymart/go-cidr/cidr:go_default_library",
"//vendor/github.com/coreos/ignition/config/v2_2:go_default_library",
"//vendor/github.com/coreos/ignition/config/v2_2/types:go_default_library",
Expand Down
44 changes: 44 additions & 0 deletions installer/pkg/config-generator/fixtures/kube-system.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
apiVersion: v1
data:
install-config: |
admin:
email: [email protected]
password: asd123
baseDomain: cluster.com
clusterID: ""
machines:
- name: master
platformConfig:
aws:
iamRoleName: ""
rootVolume:
iops: 100
size: 30
type: gp2
type: t2.medium
replicas: 3
- name: worker
platformConfig:
aws:
iamRoleName: ""
rootVolume:
iops: 100
size: 30
type: gp2
type: t2.medium
replicas: 3
metadata:
creationTimestamp: null
name: test
networking:
podCIDR:
IP: 10.2.0.0
Mask: //8AAA==
serviceCIDR:
IP: 10.3.0.0
Mask: //8AAA==
type: canal
platform:
aws:
region: eu-west-1
vpcCIDRBlock: 10.0.0.0/16
vpcID: ""
pullSecret: '{"auths": {}}'
kco-config: |
apiVersion: v1
authConfig:
Expand Down
106 changes: 106 additions & 0 deletions installer/pkg/config-generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

const (
Expand Down Expand Up @@ -71,11 +72,16 @@ func (c *ConfigGenerator) KubeSystem() (string, error) {
if err != nil {
return "", err
}
installConfig, err := c.installConfig()
if err != nil {
return "", err
}

return configMap("kube-system", genericData{
"kco-config": coreConfig,
"network-config": c.networkConfig(),
"tnco-config": tncoConfig,
"install-config": installConfig,
})
}

Expand All @@ -95,6 +101,106 @@ func (c *ConfigGenerator) TectonicSystem() (string, error) {
})
}

// InstallConfig returns a YAML-rendered Kubernetes object with the user-supplied cluster configuration.
func (c *ConfigGenerator) InstallConfig() (string, error) {
ic, err := c.installConfig()
if err != nil {
return "", err
}
return marshalYAML(ic)
}

func (c *ConfigGenerator) installConfig() (*types.InstallConfig, error) {
_, podCIDR, err := net.ParseCIDR(c.Networking.PodCIDR)
if err != nil {
return nil, err
}
_, serviceCIDR, err := net.ParseCIDR(c.Networking.ServiceCIDR)
if err != nil {
return nil, err
}

var (
platform types.Platform
masterPlatformConfig types.MachinePoolPlatformConfig
workerPlatformConfig types.MachinePoolPlatformConfig
)
switch c.Platform {
case config.PlatformAWS:
platform.AWS = &types.AWSPlatform{
Region: c.Region,
VPCID: c.VPCID,
VPCCIDRBlock: c.VPCCIDRBlock,
}
masterPlatformConfig.AWS = &types.AWSMachinePoolPlatformConfig{
InstanceType: c.AWS.Master.EC2Type,
IAMRoleName: c.AWS.Master.IAMRoleName,
EC2RootVolume: types.EC2RootVolume{
IOPS: c.AWS.Master.MasterRootVolume.IOPS,
Size: c.AWS.Master.MasterRootVolume.Size,
Type: c.AWS.Master.MasterRootVolume.Type,
},
}
workerPlatformConfig.AWS = &types.AWSMachinePoolPlatformConfig{
InstanceType: c.AWS.Worker.EC2Type,
IAMRoleName: c.AWS.Worker.IAMRoleName,
EC2RootVolume: types.EC2RootVolume{
IOPS: c.AWS.Worker.WorkerRootVolume.IOPS,
Size: c.AWS.Worker.WorkerRootVolume.Size,
Type: c.AWS.Worker.WorkerRootVolume.Type,
},
}
case config.PlatformLibvirt:
platform.Libvirt = &types.LibvirtPlatform{
URI: c.URI,
Network: types.LibvirtNetwork{
Name: c.Network.Name,
IfName: c.Network.IfName,
IPRange: c.Network.IPRange,
},
}
masterPlatformConfig.Libvirt = &types.LibvirtMachinePoolPlatformConfig{
QCOWImagePath: c.Libvirt.QCOWImagePath,
}
workerPlatformConfig.Libvirt = &types.LibvirtMachinePoolPlatformConfig{
QCOWImagePath: c.Libvirt.QCOWImagePath,
}
default:
return nil, fmt.Errorf("installconfig: invalid platform %s", c.Platform)
}
masterCount := int64(c.NodeCount(c.Master.NodePools))
workerCount := int64(c.NodeCount(c.Worker.NodePools))

return &types.InstallConfig{
ObjectMeta: metav1.ObjectMeta{
Name: c.Name,
},
ClusterID: c.ClusterID,
Admin: types.Admin{
Email: c.Admin.Email,
Password: c.Admin.Password,
SSHKey: c.Admin.SSHKey,
},
BaseDomain: c.BaseDomain,
PullSecret: c.PullSecret,
Networking: types.Networking{
Type: types.NetworkType(string(c.Networking.Type)),
ServiceCIDR: *serviceCIDR,
PodCIDR: *podCIDR,
},
Platform: platform,
Machines: []types.MachinePool{{
Name: "master",
Replicas: &masterCount,
PlatformConfig: masterPlatformConfig,
}, {
Name: "worker",
Replicas: &workerCount,
PlatformConfig: workerPlatformConfig,
}},
}, nil
}

// CoreConfig returns, if successful, a yaml string for the on-disk kco-config.
func (c *ConfigGenerator) CoreConfig() (string, error) {
coreConfig, err := c.coreConfig()
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package types
// MachinePool is a pool of machines to be installed.
type MachinePool struct {
// Name is the name of the machine pool.
Name string
Name string `json:"name"`

// Replicas is the count of machines for this machine pool.
// Default is 1.
Replicas *int64 `json:"replicas"`

// PlatformConfig is configuration for machine pool specfic to the platfrom.
// PlatformConfig is configuration for machine pool specific to the platfrom.
PlatformConfig MachinePoolPlatformConfig `json:"platformConfig"`
}

Expand Down