Skip to content

Commit

Permalink
Merge pull request openshift#205 from abhinavdahiya/installconfig_in_old
Browse files Browse the repository at this point in the history
.*: generate and embed Openshift's InstallConfig from Tectonic's Config
  • Loading branch information
openshift-merge-robot committed Sep 6, 2018
2 parents 44bedfe + f41cc55 commit b4f7a04
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 2 deletions.
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: test@coreos.com
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

0 comments on commit b4f7a04

Please sign in to comment.