1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

pkg/asset: add OpenStack machines.Worker assets

The libvirt and AWS assets were added in commit
e2dc955003. This fills the gap for
OpenStack.
This commit is contained in:
Tomas Sedovic
2018-10-17 19:17:47 +02:00
parent 079fe51f8f
commit 2c25ddcd6c
3 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
// Package openstack generates Machine objects for openstack.
package openstack
import (
"text/template"
"github.com/openshift/installer/pkg/types"
)
// Config is used to generate the machine.
type Config struct {
ClusterName string
Replicas int64
Image string
Tags map[string]string
Region string
Machine types.OpenStackMachinePoolPlatform
}
// WorkerMachineSetTmpl is template for worker machineset.
var WorkerMachineSetTmpl = template.Must(template.New("openstack-worker-machineset").Parse(`
apiVersion: cluster.k8s.io/v1alpha1
kind: MachineSet
metadata:
name: {{.ClusterName}}-worker-0
namespace: openshift-cluster-api
labels:
sigs.k8s.io/cluster-api-cluster: {{.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
replicas: {{.Replicas}}
selector:
matchLabels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.ClusterName}}
template:
metadata:
labels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
providerConfig:
value:
apiVersion: openstack.cluster.k8s.io/v1alpha1
kind: OpenStackMachineProviderConfig
image:
id: {{.Image}}
flavor: {{.Machine.FlavorName}}
placement:
region: {{.Region}}
subnet:
filters:
- name: "tag:Name"
values:
- "{{.ClusterName}}-worker-*"
tags:
{{- range $key,$value := .Tags}}
- name: "{{$key}}"
value: "{{$value}}"
{{- end}}
securityGroups:
- filters:
- name: "tag:Name"
values:
- "{{.ClusterName}}_worker_sg"
userDataSecret:
name: worker-user-data
versions:
kubelet: ""
controlPlane: ""
`))

View File

@@ -14,6 +14,7 @@ import (
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/machines/aws"
"github.com/openshift/installer/pkg/asset/machines/libvirt"
"github.com/openshift/installer/pkg/asset/machines/openstack"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
)
@@ -24,6 +25,12 @@ func defaultAWSMachinePoolPlatform() types.AWSMachinePoolPlatform {
}
}
func defaultOpenStackMachinePoolPlatform() types.OpenStackMachinePoolPlatform {
return types.OpenStackMachinePoolPlatform{
FlavorName: "m1.medium",
}
}
// Worker generates the machinesets for `worker` machine pool.
type Worker struct {
MachineSetRaw []byte
@@ -103,6 +110,24 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
Platform: *ic.Platform.Libvirt,
}
w.MachineSetRaw = applyTemplateData(libvirt.WorkerMachineSetTmpl, config)
case "openstack":
config := openstack.Config{
ClusterName: ic.ObjectMeta.Name,
Replicas: numOfWorkers,
Image: ic.Platform.OpenStack.BaseImage,
Region: ic.Platform.OpenStack.Region,
Machine: defaultOpenStackMachinePoolPlatform(),
}
tags := map[string]string{
"tectonicClusterID": ic.ClusterID,
}
config.Tags = tags
config.Machine.Set(ic.Platform.OpenStack.DefaultMachinePlatform)
config.Machine.Set(pool.Platform.OpenStack)
w.MachineSetRaw = applyTemplateData(openstack.WorkerMachineSetTmpl, config)
default:
return fmt.Errorf("invalid Platform")
}

View File

@@ -137,6 +137,11 @@ type OpenStackPlatform struct {
// Region specifies the OpenStack region where the cluster will be created.
Region string `json:"region"`
// DefaultMachinePlatform is the default configuration used when
// installing on OpenStack for machine pools which do not define their own
// platform configuration.
DefaultMachinePlatform *OpenStackMachinePoolPlatform `json:"defaultMachinePlatform,omitempty"`
// VPCID specifies the vpc to associate with the cluster.
// If empty, new vpc will be created.
// +optional