/
machinesets.go
85 lines (78 loc) · 2.78 KB
/
machinesets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Package openstack generates Machine objects for openstack.
package openstack
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/pkg/errors"
)
// MachineSets returns a list of machinesets for a machinepool.
func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]*clusterapi.MachineSet, error) {
if configPlatform := config.Platform.Name(); configPlatform != openstack.Name {
return nil, fmt.Errorf("non-OpenStack configuration: %q", configPlatform)
}
if poolPlatform := pool.Platform.Name(); poolPlatform != openstack.Name {
return nil, fmt.Errorf("non-OpenStack machine-pool: %q", poolPlatform)
}
platform := config.Platform.OpenStack
mpool := pool.Platform.OpenStack
total := int32(0)
if pool.Replicas != nil {
total = int32(*pool.Replicas)
}
// TODO(flaper87): Add support for availability zones
var machinesets []*clusterapi.MachineSet
az := ""
provider, err := provider(clusterID, platform, mpool, osImage, az, role, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}
// TODO(flaper87): Implement AZ support sometime soon
//name := fmt.Sprintf("%s-%s-%s", clustername, pool.Name, az)
name := fmt.Sprintf("%s-%s", clusterID, pool.Name)
mset := &clusterapi.MachineSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "machine.openshift.io/v1beta1",
Kind: "MachineSet",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-machine-api",
Name: name,
Labels: map[string]string{
"sigs.k8s.io/cluster-api-cluster": clusterID,
"sigs.k8s.io/cluster-api-machine-role": role,
"sigs.k8s.io/cluster-api-machine-type": role,
},
},
Spec: clusterapi.MachineSetSpec{
Replicas: &total,
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"sigs.k8s.io/cluster-api-machineset": name,
"sigs.k8s.io/cluster-api-cluster": clusterID,
},
},
Template: clusterapi.MachineTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"sigs.k8s.io/cluster-api-machineset": name,
"sigs.k8s.io/cluster-api-cluster": clusterID,
"sigs.k8s.io/cluster-api-machine-role": role,
"sigs.k8s.io/cluster-api-machine-type": role,
},
},
Spec: clusterapi.MachineSpec{
ProviderSpec: clusterapi.ProviderSpec{
Value: &runtime.RawExtension{Object: provider},
},
// we don't need to set Versions, because we control those via cluster operators.
},
},
},
}
machinesets = append(machinesets, mset)
return machinesets, nil
}