create machine deployment instead of individual machines
@@ -7,7 +7,7 @@ import (
"github.com/kubermatic/kubeone/pkg/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apimachinery/pkg/util/rand"
+ clustercommon "sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)
@@ -19,23 +19,21 @@ type providerConfig struct {
}
func MachineConfigurations(cluster *config.Cluster) (string, error) {
- machines := make([]interface{}, 0)
+ deployments := make([]interface{}, 0)
for _, workerset := range cluster.Workers {
- for i := 0; i < workerset.Replicas; i++ {
- machine, err := createMachine(cluster, workerset, i)
+ deployment, err := createMachineDeployment(cluster, workerset)
if err != nil {
return "", err
}
- machines = append(machines, machine)
- }
+ deployments = append(deployments, deployment)
}
- return kubernetesToYAML(machines)
+ return kubernetesToYAML(deployments)
}
-func createMachine(cluster *config.Cluster, workerset config.WorkerConfig, index int) (*clusterv1alpha1.Machine, error) {
+func createMachineDeployment(cluster *config.Cluster, workerset config.WorkerConfig) (*clusterv1alpha1.MachineDeployment, error) {
provider := workerset.Provider
if len(provider) == 0 {
provider = cluster.Provider.Name
@@ -53,18 +51,33 @@ func createMachine(cluster *config.Cluster, workerset config.WorkerConfig, index
return nil, err
}
- prefix := fmt.Sprintf("%s-%d-", workerset.Name, index)
- name := fmt.Sprintf("%s%s", prefix, rand.String(10))
+ replicas := int32(workerset.Replicas)
- return &clusterv1alpha1.Machine{
+ return &clusterv1alpha1.MachineDeployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "cluster.k8s.io/v1alpha1",
- Kind: "Machine",
+ Kind: "MachineDeployment",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: metav1.NamespaceSystem,
+ Name: fmt.Sprintf("%s-deployment", workerset.Name),
+ },
+ Spec: clusterv1alpha1.MachineDeploymentSpec{
+ Replicas: &replicas,
+ Selector: metav1.LabelSelector{
+ MatchLabels: map[string]string{
+ "workerset": workerset.Name,
},
+ },
+ Strategy: &clusterv1alpha1.MachineDeploymentStrategy{
+ Type: clustercommon.RollingUpdateMachineDeploymentStrategyType,
+ },
+ Template: clusterv1alpha1.MachineTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceSystem,
- Name: name,
- GenerateName: prefix,
+ Labels: map[string]string{
+ "workerset": workerset.Name,
+ },
},
Spec: clusterv1alpha1.MachineSpec{
Versions: clusterv1alpha1.MachineVersionInfo{
@@ -74,5 +87,7 @@ func createMachine(cluster *config.Cluster, workerset config.WorkerConfig, index
Value: &runtime.RawExtension{Raw: encoded},
},
},
+ },
+ },
}, nil
}
