Skip to content

Commit f41cc55

Browse files
committed
.*: generate and embed Openshift's InstallConfig from Tectonic's Config
embedding the Openshift's InstallConfig in clusters created by tectonic installer binary allows operators to start building on their config discovery logic.
1 parent d07ab5c commit f41cc55

File tree

4 files changed

+153
-2
lines changed

4 files changed

+153
-2
lines changed

installer/pkg/config-generator/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ go_library(
1313
"//installer/pkg/config:go_default_library",
1414
"//installer/pkg/copy:go_default_library",
1515
"//pkg/asset/tls:go_default_library",
16+
"//pkg/types:go_default_library",
1617
"//vendor/github.com/apparentlymart/go-cidr/cidr:go_default_library",
1718
"//vendor/github.com/coreos/ignition/config/v2_2:go_default_library",
1819
"//vendor/github.com/coreos/ignition/config/v2_2/types:go_default_library",

installer/pkg/config-generator/fixtures/kube-system.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
apiVersion: v1
22
data:
3+
install-config: |
4+
admin:
5+
6+
password: asd123
7+
baseDomain: cluster.com
8+
clusterID: ""
9+
machines:
10+
- name: master
11+
platformConfig:
12+
aws:
13+
iamRoleName: ""
14+
rootVolume:
15+
iops: 100
16+
size: 30
17+
type: gp2
18+
type: t2.medium
19+
replicas: 3
20+
- name: worker
21+
platformConfig:
22+
aws:
23+
iamRoleName: ""
24+
rootVolume:
25+
iops: 100
26+
size: 30
27+
type: gp2
28+
type: t2.medium
29+
replicas: 3
30+
metadata:
31+
creationTimestamp: null
32+
name: test
33+
networking:
34+
podCIDR:
35+
IP: 10.2.0.0
36+
Mask: //8AAA==
37+
serviceCIDR:
38+
IP: 10.3.0.0
39+
Mask: //8AAA==
40+
type: canal
41+
platform:
42+
aws:
43+
region: eu-west-1
44+
vpcCIDRBlock: 10.0.0.0/16
45+
vpcID: ""
46+
pullSecret: '{"auths": {}}'
347
kco-config: |
448
apiVersion: v1
549
authConfig:

installer/pkg/config-generator/generator.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

2121
"github.com/openshift/installer/installer/pkg/config"
22+
"github.com/openshift/installer/pkg/types"
2223
)
2324

2425
const (
@@ -71,11 +72,16 @@ func (c *ConfigGenerator) KubeSystem() (string, error) {
7172
if err != nil {
7273
return "", err
7374
}
75+
installConfig, err := c.installConfig()
76+
if err != nil {
77+
return "", err
78+
}
7479

7580
return configMap("kube-system", genericData{
7681
"kco-config": coreConfig,
7782
"network-config": c.networkConfig(),
7883
"tnco-config": tncoConfig,
84+
"install-config": installConfig,
7985
})
8086
}
8187

@@ -95,6 +101,106 @@ func (c *ConfigGenerator) TectonicSystem() (string, error) {
95101
})
96102
}
97103

104+
// InstallConfig returns a YAML-rendered Kubernetes object with the user-supplied cluster configuration.
105+
func (c *ConfigGenerator) InstallConfig() (string, error) {
106+
ic, err := c.installConfig()
107+
if err != nil {
108+
return "", err
109+
}
110+
return marshalYAML(ic)
111+
}
112+
113+
func (c *ConfigGenerator) installConfig() (*types.InstallConfig, error) {
114+
_, podCIDR, err := net.ParseCIDR(c.Networking.PodCIDR)
115+
if err != nil {
116+
return nil, err
117+
}
118+
_, serviceCIDR, err := net.ParseCIDR(c.Networking.ServiceCIDR)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
var (
124+
platform types.Platform
125+
masterPlatformConfig types.MachinePoolPlatformConfig
126+
workerPlatformConfig types.MachinePoolPlatformConfig
127+
)
128+
switch c.Platform {
129+
case config.PlatformAWS:
130+
platform.AWS = &types.AWSPlatform{
131+
Region: c.Region,
132+
VPCID: c.VPCID,
133+
VPCCIDRBlock: c.VPCCIDRBlock,
134+
}
135+
masterPlatformConfig.AWS = &types.AWSMachinePoolPlatformConfig{
136+
InstanceType: c.AWS.Master.EC2Type,
137+
IAMRoleName: c.AWS.Master.IAMRoleName,
138+
EC2RootVolume: types.EC2RootVolume{
139+
IOPS: c.AWS.Master.MasterRootVolume.IOPS,
140+
Size: c.AWS.Master.MasterRootVolume.Size,
141+
Type: c.AWS.Master.MasterRootVolume.Type,
142+
},
143+
}
144+
workerPlatformConfig.AWS = &types.AWSMachinePoolPlatformConfig{
145+
InstanceType: c.AWS.Worker.EC2Type,
146+
IAMRoleName: c.AWS.Worker.IAMRoleName,
147+
EC2RootVolume: types.EC2RootVolume{
148+
IOPS: c.AWS.Worker.WorkerRootVolume.IOPS,
149+
Size: c.AWS.Worker.WorkerRootVolume.Size,
150+
Type: c.AWS.Worker.WorkerRootVolume.Type,
151+
},
152+
}
153+
case config.PlatformLibvirt:
154+
platform.Libvirt = &types.LibvirtPlatform{
155+
URI: c.URI,
156+
Network: types.LibvirtNetwork{
157+
Name: c.Network.Name,
158+
IfName: c.Network.IfName,
159+
IPRange: c.Network.IPRange,
160+
},
161+
}
162+
masterPlatformConfig.Libvirt = &types.LibvirtMachinePoolPlatformConfig{
163+
QCOWImagePath: c.Libvirt.QCOWImagePath,
164+
}
165+
workerPlatformConfig.Libvirt = &types.LibvirtMachinePoolPlatformConfig{
166+
QCOWImagePath: c.Libvirt.QCOWImagePath,
167+
}
168+
default:
169+
return nil, fmt.Errorf("installconfig: invalid platform %s", c.Platform)
170+
}
171+
masterCount := int64(c.NodeCount(c.Master.NodePools))
172+
workerCount := int64(c.NodeCount(c.Worker.NodePools))
173+
174+
return &types.InstallConfig{
175+
ObjectMeta: metav1.ObjectMeta{
176+
Name: c.Name,
177+
},
178+
ClusterID: c.ClusterID,
179+
Admin: types.Admin{
180+
Email: c.Admin.Email,
181+
Password: c.Admin.Password,
182+
SSHKey: c.Admin.SSHKey,
183+
},
184+
BaseDomain: c.BaseDomain,
185+
PullSecret: c.PullSecret,
186+
Networking: types.Networking{
187+
Type: types.NetworkType(string(c.Networking.Type)),
188+
ServiceCIDR: *serviceCIDR,
189+
PodCIDR: *podCIDR,
190+
},
191+
Platform: platform,
192+
Machines: []types.MachinePool{{
193+
Name: "master",
194+
Replicas: &masterCount,
195+
PlatformConfig: masterPlatformConfig,
196+
}, {
197+
Name: "worker",
198+
Replicas: &workerCount,
199+
PlatformConfig: workerPlatformConfig,
200+
}},
201+
}, nil
202+
}
203+
98204
// CoreConfig returns, if successful, a yaml string for the on-disk kco-config.
99205
func (c *ConfigGenerator) CoreConfig() (string, error) {
100206
coreConfig, err := c.coreConfig()

pkg/types/machinepools.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package types
33
// MachinePool is a pool of machines to be installed.
44
type MachinePool struct {
55
// Name is the name of the machine pool.
6-
Name string
6+
Name string `json:"name"`
77

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

12-
// PlatformConfig is configuration for machine pool specfic to the platfrom.
12+
// PlatformConfig is configuration for machine pool specific to the platfrom.
1313
PlatformConfig MachinePoolPlatformConfig `json:"platformConfig"`
1414
}
1515

0 commit comments

Comments
 (0)