diff --git a/pkg/asset/machines/openstack/openstack.go b/pkg/asset/machines/openstack/openstack.go new file mode 100644 index 0000000000..132d224b15 --- /dev/null +++ b/pkg/asset/machines/openstack/openstack.go @@ -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: "" +`)) diff --git a/pkg/asset/machines/worker.go b/pkg/asset/machines/worker.go index 8a18e5cd10..0a51c6605e 100644 --- a/pkg/asset/machines/worker.go +++ b/pkg/asset/machines/worker.go @@ -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") } diff --git a/pkg/types/installconfig.go b/pkg/types/installconfig.go index 7daa719ea6..6c1f6f7e94 100644 --- a/pkg/types/installconfig.go +++ b/pkg/types/installconfig.go @@ -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