Skip to content

Commit

Permalink
Merge pull request #2862 from zhanggbj/remove_unused_var
Browse files Browse the repository at this point in the history
🌱 Remove infraServer and credsSecretName from supervisor ClusterClass
  • Loading branch information
k8s-ci-robot authored Apr 3, 2024
2 parents dbedef4 + 7b5f0ed commit f4a53e8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 97 deletions.
63 changes: 36 additions & 27 deletions packaging/flavorgen/flavors/clusterclass_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newClusterClass() clusterv1.ClusterClass {
},
ControlPlane: getControlPlaneClass(),
Workers: getWorkersClass(),
Variables: getClusterClassVariables(),
Variables: getClusterClassVariables(false),
Patches: getClusterClassPatches(),
},
}
Expand All @@ -81,7 +81,7 @@ func newVMWareClusterClass() clusterv1.ClusterClass {
},
ControlPlane: getVMWareControlPlaneClass(),
Workers: getVMWareWorkersClass(),
Variables: getClusterClassVariables(),
Variables: getClusterClassVariables(true),
Patches: getVMWareClusterClassPatches(),
},
}
Expand Down Expand Up @@ -238,8 +238,8 @@ func getEnableSSHIntoNodesTemplate() *string {
return ptr.To(string(templateStr))
}

func getClusterClassVariables() []clusterv1.ClusterClassVariable {
return []clusterv1.ClusterClassVariable{
func getClusterClassVariables(supervisorMode bool) []clusterv1.ClusterClassVariable {
variables := []clusterv1.ClusterClassVariable{
{
Name: "sshKey",
Required: false,
Expand All @@ -250,19 +250,6 @@ func getClusterClassVariables() []clusterv1.ClusterClassVariable {
},
},
},
{
Name: "infraServer",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"url": {Type: "string"},
"thumbprint": {Type: "string"},
},
},
},
},
{
Name: "controlPlaneIpAddr",
Required: true,
Expand All @@ -283,16 +270,6 @@ func getClusterClassVariables() []clusterv1.ClusterClassVariable {
},
},
},
{
Name: "credsSecretName",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "Secret containing the credentials for the infra cluster.",
},
},
},
{
Name: "kubeVipPodManifest",
Required: true,
Expand All @@ -304,6 +281,38 @@ func getClusterClassVariables() []clusterv1.ClusterClassVariable {
},
},
}

if !supervisorMode {
varForNoneSupervisorMode := []clusterv1.ClusterClassVariable{
{
Name: "infraServer",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"url": {Type: "string"},
"thumbprint": {Type: "string"},
},
},
},
},
{
Name: "credsSecretName",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "Secret containing the credentials for the infra cluster.",
},
},
},
}

variables = append(variables, varForNoneSupervisorMode...)
}

return variables
}

func newVSphereClusterTemplate() infrav1.VSphereClusterTemplate {
Expand Down
4 changes: 2 additions & 2 deletions packaging/flavorgen/flavors/flavors.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func ClusterClassTemplateSupervisor() []runtime.Object {
}

func ClusterTopologyTemplateKubeVIP() ([]runtime.Object, error) {
cluster, err := newClusterTopologyCluster()
cluster, err := newClusterTopologyCluster(false)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +104,7 @@ func ClusterTopologyTemplateKubeVIP() ([]runtime.Object, error) {
}

func ClusterTopologyTemplateSupervisor() ([]runtime.Object, error) {
cluster, err := newClusterTopologyCluster()
cluster, err := newClusterTopologyCluster(true)
if err != nil {
return nil, err
}
Expand Down
59 changes: 34 additions & 25 deletions packaging/flavorgen/flavors/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ systemd:
EnvironmentFile=/run/metadata/*`
)

func newClusterTopologyCluster() (clusterv1.Cluster, error) {
variables, err := clusterTopologyVariables()
func newClusterTopologyCluster(supervisorMode bool) (clusterv1.Cluster, error) {
variables, err := clusterTopologyVariables(supervisorMode)
if err != nil {
return clusterv1.Cluster{}, errors.Wrap(err, "failed to create ClusterTopologyCluster template")
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func newClusterTopologyCluster() (clusterv1.Cluster, error) {
}, nil
}

func clusterTopologyVariables() ([]clusterv1.ClusterVariable, error) {
func clusterTopologyVariables(supervisorMode bool) ([]clusterv1.ClusterVariable, error) {
sshKey, err := json.Marshal(env.VSphereSSHAuthorizedKeysVar)
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable VSphereSSHAuthorizedKeysVar: %q", env.VSphereSSHAuthorizedKeysVar)
Expand All @@ -149,32 +149,18 @@ func clusterTopologyVariables() ([]clusterv1.ClusterVariable, error) {
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 {
return nil, errors.Wrapf(err, "failed to json-encode variable ClusterNameVar: %q", env.ClusterNameVar)
}

kubeVipVariable, err := kubevip.TopologyVariable()
if err != nil {
return nil, err
}
infraServerValue, err := getInfraServerValue()
if err != nil {
return nil, err
}
return []clusterv1.ClusterVariable{

variables := []clusterv1.ClusterVariable{
{
Name: "sshKey",
Value: apiextensionsv1.JSON{
Raw: sshKey,
},
},
{
Name: "infraServer",
Value: apiextensionsv1.JSON{
Raw: infraServerValue,
},
},
*kubeVipVariable,
{
Name: "controlPlaneIpAddr",
Expand All @@ -188,13 +174,36 @@ func clusterTopologyVariables() ([]clusterv1.ClusterVariable, error) {
Raw: controlPlanePort,
},
},
{
Name: "credsSecretName",
Value: apiextensionsv1.JSON{
Raw: secretName,
}

if !supervisorMode {
infraServerValue, err := getInfraServerValue()
if err != nil {
return nil, err
}
secretName, err := json.Marshal(env.ClusterNameVar)
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable ClusterNameVar: %q", env.ClusterNameVar)
}

varForNoneSupervisorMode := []clusterv1.ClusterVariable{
{
Name: "infraServer",
Value: apiextensionsv1.JSON{
Raw: infraServerValue,
},
},
},
}, nil
{
Name: "credsSecretName",
Value: apiextensionsv1.JSON{
Raw: secretName,
},
},
}

variables = append(variables, varForNoneSupervisorMode...)
}
return variables, nil
}

func getInfraServerValue() ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions templates/cluster-template-topology-supervisor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ spec:
variables:
- name: sshKey
value: '${VSPHERE_SSH_AUTHORIZED_KEY}'
- name: infraServer
value:
thumbprint: '${VSPHERE_TLS_THUMBPRINT}'
url: '${VSPHERE_SERVER}'
- name: kubeVipPodManifest
value: |
apiVersion: v1
Expand Down Expand Up @@ -93,8 +89,6 @@ spec:
value: ${CONTROL_PLANE_ENDPOINT_IP}
- name: controlPlanePort
value: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
- name: credsSecretName
value: '${CLUSTER_NAME}'
version: '${KUBERNETES_VERSION}'
workers:
machineDeployments:
Expand Down
8 changes: 4 additions & 4 deletions templates/cluster-template-topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ spec:
variables:
- name: sshKey
value: '${VSPHERE_SSH_AUTHORIZED_KEY}'
- name: infraServer
value:
thumbprint: '${VSPHERE_TLS_THUMBPRINT}'
url: '${VSPHERE_SERVER}'
- name: kubeVipPodManifest
value: |
apiVersion: v1
Expand Down Expand Up @@ -93,6 +89,10 @@ spec:
value: ${CONTROL_PLANE_ENDPOINT_IP}
- name: controlPlanePort
value: ${CONTROL_PLANE_ENDPOINT_PORT:=6443}
- name: infraServer
value:
thumbprint: '${VSPHERE_TLS_THUMBPRINT}'
url: '${VSPHERE_SERVER}'
- name: credsSecretName
value: '${CLUSTER_NAME}'
version: '${KUBERNETES_VERSION}'
Expand Down
18 changes: 0 additions & 18 deletions templates/clusterclass-template-supervisor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,6 @@ spec:
openAPIV3Schema:
description: Public key to SSH onto the cluster nodes.
type: string
- metadata: {}
name: infraServer
required: true
schema:
openAPIV3Schema:
properties:
thumbprint:
type: string
url:
type: string
type: object
- metadata: {}
name: controlPlaneIpAddr
required: true
Expand All @@ -219,13 +208,6 @@ spec:
openAPIV3Schema:
description: Port for the control plane endpoint.
type: integer
- metadata: {}
name: credsSecretName
required: true
schema:
openAPIV3Schema:
description: Secret containing the credentials for the infra cluster.
type: string
- metadata: {}
name: kubeVipPodManifest
required: true
Expand Down
30 changes: 15 additions & 15 deletions templates/clusterclass-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ spec:
openAPIV3Schema:
description: Public key to SSH onto the cluster nodes.
type: string
- metadata: {}
name: infraServer
required: true
schema:
openAPIV3Schema:
properties:
thumbprint:
type: string
url:
type: string
type: object
- metadata: {}
name: controlPlaneIpAddr
required: true
Expand All @@ -234,18 +223,29 @@ spec:
description: Port for the control plane endpoint.
type: integer
- metadata: {}
name: credsSecretName
name: kubeVipPodManifest
required: true
schema:
openAPIV3Schema:
description: Secret containing the credentials for the infra cluster.
description: kube-vip manifest for the control plane.
type: string
- metadata: {}
name: kubeVipPodManifest
name: infraServer
required: true
schema:
openAPIV3Schema:
description: kube-vip manifest for the control plane.
properties:
thumbprint:
type: string
url:
type: string
type: object
- metadata: {}
name: credsSecretName
required: true
schema:
openAPIV3Schema:
description: Secret containing the credentials for the infra cluster.
type: string
workers:
machineDeployments:
Expand Down

0 comments on commit f4a53e8

Please sign in to comment.