Skip to content

Commit

Permalink
flavorgen for supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Mar 4, 2024
1 parent 24051f5 commit cc777ca
Show file tree
Hide file tree
Showing 9 changed files with 3,433 additions and 64 deletions.
38 changes: 32 additions & 6 deletions packaging/flavorgen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ const outputDirFlag = "output-dir"

var (
flavorMappings = map[string]string{
flavors.VIP: "cluster-template.yaml",
flavors.ExternalLoadBalancer: "cluster-template-external-loadbalancer.yaml",
flavors.ClusterClass: "clusterclass-template.yaml",
flavors.ClusterTopology: "cluster-template-topology.yaml",
flavors.Ignition: "cluster-template-ignition.yaml",
flavors.NodeIPAM: "cluster-template-node-ipam.yaml",
flavors.VIP: "cluster-template.yaml",
flavors.ExternalLoadBalancer: "cluster-template-external-loadbalancer.yaml",
flavors.ClusterClass: "clusterclass-template.yaml",
flavors.ClusterTopology: "cluster-template-topology.yaml",
flavors.Ignition: "cluster-template-ignition.yaml",
flavors.NodeIPAM: "cluster-template-node-ipam.yaml",
flavors.Supervisor: "cluster-template-supervisor.yaml",
flavors.ClusterClassSupervisor: "clusterclass-template-supervisor.yaml",
flavors.ClusterTopologySupervisor: "cluster-template-topology-supervisor.yaml",
}

allFlavors = []string{
Expand All @@ -51,6 +54,9 @@ var (
flavors.Ignition,
flavors.NodeIPAM,
flavors.ClusterTopology,
flavors.Supervisor,
flavors.ClusterClassSupervisor,
flavors.ClusterTopologySupervisor,
}
)

Expand Down Expand Up @@ -164,6 +170,26 @@ func generateSingle(flavor string) (string, error) {
if err != nil {
return "", err
}
case flavors.Supervisor:
var err error
objs, err = flavors.MultiNodeTemplateSupervisor()
if err != nil {
return "", err
}
case flavors.ClusterClassSupervisor:
objs = flavors.ClusterClassTemplateSupervisor()
case flavors.ClusterTopologySupervisor:
var err error
objs, err = flavors.ClusterTopologyTemplateSupervisor()
if err != nil {
return "", err
}
replacements = append(replacements, util.Replacement{
Kind: "Cluster",
Name: "${CLUSTER_NAME}",
Value: env.ControlPlaneMachineCountVar,
FieldPath: []string{"spec", "topology", "controlPlane", "replicas"},
})
default:
return "", errors.Errorf("invalid flavor")
}
Expand Down
104 changes: 104 additions & 0 deletions packaging/flavorgen/flavors/clusterclass_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/yaml"

infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors/env"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors/kubevip"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors/util"
Expand Down Expand Up @@ -59,6 +60,33 @@ func newClusterClass() clusterv1.ClusterClass {
},
}
}

func newVMWareClusterClass() clusterv1.ClusterClass {
return clusterv1.ClusterClass{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: util.TypeToKind(&clusterv1.ClusterClass{}),
},
ObjectMeta: metav1.ObjectMeta{
Name: env.ClusterClassNameVar,
},
Spec: clusterv1.ClusterClassSpec{
Infrastructure: clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
APIVersion: vmwarev1.GroupVersion.String(),
Kind: util.TypeToKind(&vmwarev1.VSphereClusterTemplate{}),
Namespace: env.NamespaceVar,
Name: env.ClusterClassNameVar,
},
},
ControlPlane: getVMWareControlPlaneClass(),
Workers: getVMWareWorkersClass(),
Variables: getClusterClassVariables(),
Patches: getVMWareClusterClassPatches(),
},
}
}

func getControlPlaneClass() clusterv1.ControlPlaneClass {
return clusterv1.ControlPlaneClass{
LocalObjectTemplate: clusterv1.LocalObjectTemplate{
Expand All @@ -80,6 +108,27 @@ func getControlPlaneClass() clusterv1.ControlPlaneClass {
}
}

func getVMWareControlPlaneClass() clusterv1.ControlPlaneClass {
return clusterv1.ControlPlaneClass{
LocalObjectTemplate: clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
Kind: util.TypeToKind(&controlplanev1.KubeadmControlPlaneTemplate{}),
Namespace: env.NamespaceVar,
Name: fmt.Sprintf("%s-controlplane", env.ClusterClassNameVar),
APIVersion: controlplanev1.GroupVersion.String(),
},
},
MachineInfrastructure: &clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
APIVersion: vmwarev1.GroupVersion.String(),
Kind: util.TypeToKind(&vmwarev1.VSphereMachineTemplate{}),
Namespace: env.NamespaceVar,
Name: fmt.Sprintf("%s-template", env.ClusterClassNameVar),
},
},
}
}

func getWorkersClass() clusterv1.WorkersClass {
return clusterv1.WorkersClass{
MachineDeployments: []clusterv1.MachineDeploymentClass{
Expand Down Expand Up @@ -108,6 +157,34 @@ func getWorkersClass() clusterv1.WorkersClass {
}
}

func getVMWareWorkersClass() clusterv1.WorkersClass {
return clusterv1.WorkersClass{
MachineDeployments: []clusterv1.MachineDeploymentClass{
{
Class: fmt.Sprintf("%s-worker", env.ClusterClassNameVar),
Template: clusterv1.MachineDeploymentClassTemplate{
Bootstrap: clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
APIVersion: bootstrapv1.GroupVersion.String(),
Kind: util.TypeToKind(&bootstrapv1.KubeadmConfigTemplate{}),
Namespace: env.NamespaceVar,
Name: fmt.Sprintf("%s-worker-bootstrap-template", env.ClusterClassNameVar),
},
},
Infrastructure: clusterv1.LocalObjectTemplate{
Ref: &corev1.ObjectReference{
Kind: util.TypeToKind(&vmwarev1.VSphereMachineTemplate{}),
Namespace: env.NamespaceVar,
Name: fmt.Sprintf("%s-worker-machinetemplate", env.ClusterClassNameVar),
APIVersion: vmwarev1.GroupVersion.String(),
},
},
},
},
},
}
}

func getClusterClassPatches() []clusterv1.ClusterClassPatch {
return []clusterv1.ClusterClassPatch{
createEmptyArraysPatch(),
Expand All @@ -117,6 +194,15 @@ func getClusterClassPatches() []clusterv1.ClusterClassPatch {
}
}

func getVMWareClusterClassPatches() []clusterv1.ClusterClassPatch {
return []clusterv1.ClusterClassPatch{
createEmptyArraysPatch(),
enableSSHPatch(),
vmWareInfraClusterPatch(),
kubevip.TopologyPatch(),
}
}

func getCredSecretNameTemplate() *string {
template := map[string]interface{}{
"name": "{{ .credsSecretName }}",
Expand Down Expand Up @@ -238,6 +324,24 @@ func newVSphereClusterTemplate() infrav1.VSphereClusterTemplate {
}
}

func newVMWareClusterTemplate() vmwarev1.VSphereClusterTemplate {
return vmwarev1.VSphereClusterTemplate{
TypeMeta: metav1.TypeMeta{
APIVersion: vmwarev1.GroupVersion.String(),
Kind: util.TypeToKind(&vmwarev1.VSphereClusterTemplate{}),
},
ObjectMeta: metav1.ObjectMeta{
Name: env.ClusterClassNameVar,
Namespace: env.NamespaceVar,
},
Spec: vmwarev1.VSphereClusterTemplateSpec{
Template: vmwarev1.VSphereClusterTemplateResource{
Spec: vmwarev1.VSphereClusterSpec{},
},
},
}
}

func newKubeadmControlPlaneTemplate(templateName string) controlplanev1.KubeadmControlPlaneTemplate {
return controlplanev1.KubeadmControlPlaneTemplate{
TypeMeta: metav1.TypeMeta{
Expand Down
62 changes: 33 additions & 29 deletions packaging/flavorgen/flavors/env/envsubts_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,39 @@ limitations under the License.
package env

const (
ClusterNameVar = "${CLUSTER_NAME}"
ClusterClassNameVar = "${CLUSTER_CLASS_NAME}"
ControlPlaneMachineCountVar = "${CONTROL_PLANE_MACHINE_COUNT}"
DefaultCloudProviderImage = "gcr.io/cloud-provider-vsphere/cpi/release/manager:v1.2.1"
DefaultClusterCIDR = "192.168.0.0/16"
DefaultDiskGiB = 25
DefaultMemoryMiB = 8192
DefaultNumCPUs = 2
KubernetesVersionVar = "${KUBERNETES_VERSION}"
CPIImageKubernetesVersionVar = "${CPI_IMAGE_K8S_VERSION}"
MachineDeploymentNameSuffix = "-md-0"
Nameserver = "${NAMESERVER}"
NamespaceVar = "${NAMESPACE}"
NodeIPAMPoolAPIGroup = "${NODE_IPAM_POOL_API_GROUP}"
NodeIPAMPoolKind = "${NODE_IPAM_POOL_KIND}"
NodeIPAMPoolName = "${NODE_IPAM_POOL_NAME}"
VSphereDataCenterVar = "${VSPHERE_DATACENTER}"
VSphereThumbprint = "${VSPHERE_TLS_THUMBPRINT}"
VSphereDatastoreVar = "${VSPHERE_DATASTORE}"
VSphereFolderVar = "${VSPHERE_FOLDER}"
VSphereNetworkVar = "${VSPHERE_NETWORK}"
VSphereResourcePoolVar = "${VSPHERE_RESOURCE_POOL}"
VSphereServerVar = "${VSPHERE_SERVER}"
VSphereSSHAuthorizedKeysVar = "${VSPHERE_SSH_AUTHORIZED_KEY}"
VSphereStoragePolicyVar = "${VSPHERE_STORAGE_POLICY}"
VSphereTemplateVar = "${VSPHERE_TEMPLATE}"
WorkerMachineCountVar = "${WORKER_MACHINE_COUNT}"
ControlPlaneEndpointHostVar = "${CONTROL_PLANE_ENDPOINT_IP}"
ControlPlaneEndpointPortVar = "${CONTROL_PLANE_ENDPOINT_PORT:=6443}"
ClusterNameVar = "${CLUSTER_NAME}"
ClusterClassNameVar = "${CLUSTER_CLASS_NAME}"
ControlPlaneMachineCountVar = "${CONTROL_PLANE_MACHINE_COUNT}"
DefaultCloudProviderImage = "gcr.io/cloud-provider-vsphere/cpi/release/manager:v1.2.1"
DefaultClusterCIDR = "192.168.0.0/16"
DefaultDiskGiB = 25
DefaultMemoryMiB = 8192
DefaultNumCPUs = 2
KubernetesVersionVar = "${KUBERNETES_VERSION}"
CPIImageKubernetesVersionVar = "${CPI_IMAGE_K8S_VERSION}"
MachineDeploymentNameSuffix = "-md-0"
Nameserver = "${NAMESERVER}"
NamespaceVar = "${NAMESPACE}"
NodeIPAMPoolAPIGroup = "${NODE_IPAM_POOL_API_GROUP}"
NodeIPAMPoolKind = "${NODE_IPAM_POOL_KIND}"
NodeIPAMPoolName = "${NODE_IPAM_POOL_NAME}"
VSphereDataCenterVar = "${VSPHERE_DATACENTER}"
VSphereThumbprint = "${VSPHERE_TLS_THUMBPRINT}"
VSphereDatastoreVar = "${VSPHERE_DATASTORE}"
VSphereFolderVar = "${VSPHERE_FOLDER}"
VSphereNetworkVar = "${VSPHERE_NETWORK}"
VSphereResourcePoolVar = "${VSPHERE_RESOURCE_POOL}"
VSphereServerVar = "${VSPHERE_SERVER}"
VSphereSSHAuthorizedKeysVar = "${VSPHERE_SSH_AUTHORIZED_KEY}"
VSphereStoragePolicyVar = "${VSPHERE_STORAGE_POLICY}"
VSphereTemplateVar = "${VSPHERE_TEMPLATE}"
WorkerMachineCountVar = "${WORKER_MACHINE_COUNT}"
ControlPlaneEndpointHostVar = "${CONTROL_PLANE_ENDPOINT_IP}"
ControlPlaneEndpointPortVar = "${CONTROL_PLANE_ENDPOINT_PORT:=6443}"
VSphereMachineClassImageVar = "${VSPHERE_IMAGE_NAME}"
VSphereMachineClassVar = "${VSPHERE_MACHINE_CLASS_NAME}"
VSphereMachineStorageClassVar = "${VSPHERE_STORAGE_CLASS}"
VSphereMachinePowerOffModeVar = "${VSPHERE_POWER_OFF_MODE}"
// VipNetworkInterfaceVar defaults to an empty string to let kube-vip autodetect the interface.
VipNetworkInterfaceVar = "${VIP_NETWORK_INTERFACE:=\"\"}"
VSphereUsername = "${VSPHERE_USERNAME}"
Expand Down
Loading

0 comments on commit cc777ca

Please sign in to comment.