Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Make Flavor gen templates vcsim friendly #2771

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packaging/flavorgen/flavors/clusterclass_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package flavors

import (
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -128,10 +129,13 @@ func getCredSecretNameTemplate() *string {
func getControlPlaneEndpointTemplate() *string {
template := map[string]interface{}{
"host": "{{ .controlPlaneIpAddr }}",
"port": 6443,
"port": "{{ .controlPlanePort }}",
}
templateStr, _ := yaml.Marshal(template)
return ptr.To(string(templateStr))

fixTemplateStr := string(templateStr)
fixTemplateStr = strings.Replace(fixTemplateStr, "'{{ .controlPlanePort }}'", "{{ .controlPlanePort }}", -1)
return ptr.To(fixTemplateStr)
}

func getEnableSSHIntoNodesTemplate() *string {
Expand Down Expand Up @@ -183,6 +187,16 @@ func getClusterClassVariables() []clusterv1.ClusterClassVariable {
},
},
},
{
Name: "controlPlanePort",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
Description: "Port for the control plane endpoint.",
},
},
},
{
Name: "credsSecretName",
Required: true,
Expand Down
3 changes: 2 additions & 1 deletion packaging/flavorgen/flavors/env/envsubts_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const (
VSphereStoragePolicyVar = "${VSPHERE_STORAGE_POLICY}"
VSphereTemplateVar = "${VSPHERE_TEMPLATE}"
WorkerMachineCountVar = "${WORKER_MACHINE_COUNT}"
ControlPlaneEndpointVar = "${CONTROL_PLANE_ENDPOINT_IP}"
ControlPlaneEndpointHostVar = "${CONTROL_PLANE_ENDPOINT_IP}"
ControlPlaneEndpointPortVar = "${CONTROL_PLANE_ENDPOINT_PORT:=6443}"
// VipNetworkInterfaceVar defaults to an empty string to let kube-vip autodetect the interface.
VipNetworkInterfaceVar = "${VIP_NETWORK_INTERFACE:=\"\"}"
VSphereUsername = "${VSPHERE_USERNAME}"
Expand Down
16 changes: 13 additions & 3 deletions packaging/flavorgen/flavors/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ func clusterTopologyVariables() ([]clusterv1.ClusterVariable, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable VSphereSSHAuthorizedKeysVar: %q", env.VSphereSSHAuthorizedKeysVar)
}
controlPlaneIP, err := json.Marshal(env.ControlPlaneEndpointVar)
controlPlaneIP, err := json.Marshal(env.ControlPlaneEndpointHostVar)
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable ControlPlaneEndpointVar: %q", env.ControlPlaneEndpointVar)
return nil, errors.Wrapf(err, "failed to json-encode variable ControlPlaneEndpointHostVar: %q", env.ControlPlaneEndpointHostVar)
}
controlPlanePort, err := json.Marshal(env.ControlPlaneEndpointPortVar)
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable ControlPlaneEndpointPortVar: %q", env.ControlPlaneEndpointPortVar)
}
secretName, err := json.Marshal(env.ClusterNameVar)
if err != nil {
Expand Down Expand Up @@ -176,6 +180,12 @@ func clusterTopologyVariables() ([]clusterv1.ClusterVariable, error) {
Raw: controlPlaneIP,
},
},
{
Name: "controlPlanePort",
Value: apiextensionsv1.JSON{
Raw: controlPlanePort,
},
},
{
Name: "credsSecretName",
Value: apiextensionsv1.JSON{
Expand Down Expand Up @@ -215,7 +225,7 @@ func newVSphereCluster() infrav1.VSphereCluster {
Kind: infrav1.SecretKind,
},
ControlPlaneEndpoint: infrav1.APIEndpoint{
Host: env.ControlPlaneEndpointVar,
Host: env.ControlPlaneEndpointHostVar,
Port: 6443,
},
},
Expand Down
6 changes: 6 additions & 0 deletions packaging/flavorgen/flavors/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ var (
Value: map[string]interface{}{},
FieldPath: []string{"spec", "template", "spec"},
},
{
Kind: "VSphereCluster",
Name: "${CLUSTER_NAME}",
Value: env.ControlPlaneEndpointPortVar,
FieldPath: []string{"spec", "controlPlaneEndpoint", "port"},
},
}

stringVars = []string{
Expand Down
2 changes: 1 addition & 1 deletion templates/cluster-template-external-loadbalancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ metadata:
spec:
controlPlaneEndpoint:
host: ${CONTROL_PLANE_ENDPOINT_IP}
port: 6443
port: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
identityRef:
kind: Secret
name: '${CLUSTER_NAME}'
Expand Down
2 changes: 1 addition & 1 deletion templates/cluster-template-ignition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ metadata:
spec:
controlPlaneEndpoint:
host: ${CONTROL_PLANE_ENDPOINT_IP}
port: 6443
port: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
identityRef:
kind: Secret
name: '${CLUSTER_NAME}'
Expand Down
2 changes: 1 addition & 1 deletion templates/cluster-template-node-ipam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ metadata:
spec:
controlPlaneEndpoint:
host: ${CONTROL_PLANE_ENDPOINT_IP}
port: 6443
port: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
identityRef:
kind: Secret
name: '${CLUSTER_NAME}'
Expand Down
2 changes: 2 additions & 0 deletions templates/cluster-template-topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ spec:
status: {}
- name: controlPlaneIpAddr
value: ${CONTROL_PLANE_ENDPOINT_IP}
- name: controlPlanePort
value: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
- name: credsSecretName
value: '${CLUSTER_NAME}'
version: '${KUBERNETES_VERSION}'
Expand Down
2 changes: 1 addition & 1 deletion templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ metadata:
spec:
controlPlaneEndpoint:
host: ${CONTROL_PLANE_ENDPOINT_IP}
port: 6443
port: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
identityRef:
kind: Secret
name: '${CLUSTER_NAME}'
Expand Down
8 changes: 7 additions & 1 deletion templates/clusterclass-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ spec:
valueFrom:
template: |
host: '{{ .controlPlaneIpAddr }}'
port: 6443
port: {{ .controlPlanePort }}
- op: add
path: /spec/template/spec/identityRef
valueFrom:
Expand Down Expand Up @@ -223,6 +223,12 @@ spec:
openAPIV3Schema:
description: Floating VIP for the control plane.
type: string
- name: controlPlanePort
required: true
schema:
openAPIV3Schema:
description: Port for the control plane endpoint.
type: integer
- name: credsSecretName
required: true
schema:
Expand Down