From b13b7b34ed9a275314f696e07ee08ae889014b5d Mon Sep 17 00:00:00 2001 From: rabi Date: Thu, 12 Sep 2024 10:09:51 +0530 Subject: [PATCH] Use ctlplane vlan in networkdata Note: this would only work when using virtmedia. Jira: https://issues.redhat.com/browse/OSPRH-10127 Signed-off-by: rabi --- ...emetal.openstack.org_openstackbaremetalsets.yaml | 3 +++ api/v1beta1/openstackbaremetalset_types.go | 3 +++ api/v1beta1/zz_generated.deepcopy.go | 5 +++++ ...emetal.openstack.org_openstackbaremetalsets.yaml | 3 +++ pkg/openstackbaremetalset/baremetalhost.go | 3 +++ .../openstackbaremetalset/cloudinit/networkdata | 13 +++++++++++++ 6 files changed, 30 insertions(+) diff --git a/api/bases/baremetal.openstack.org_openstackbaremetalsets.yaml b/api/bases/baremetal.openstack.org_openstackbaremetalsets.yaml index c9a2b0b9..a359a3f2 100644 --- a/api/bases/baremetal.openstack.org_openstackbaremetalsets.yaml +++ b/api/bases/baremetal.openstack.org_openstackbaremetalsets.yaml @@ -147,6 +147,9 @@ spec: description: 'CtlplaneNetmask - Netmask to use for ctlplane network (TODO: acquire this is another manner?)' type: string + ctlplaneVlan: + description: CtlplaneVlan - Vlan for ctlplane network + type: integer deploymentSSHSecret: description: DeploymentSSHSecret - Name of secret holding the cloud-admin ssh keys diff --git a/api/v1beta1/openstackbaremetalset_types.go b/api/v1beta1/openstackbaremetalset_types.go index 2063c7db..807edf8b 100644 --- a/api/v1beta1/openstackbaremetalset_types.go +++ b/api/v1beta1/openstackbaremetalset_types.go @@ -111,6 +111,9 @@ type OpenStackBaremetalSetSpec struct { // CtlplaneGateway - IP of gateway for ctrlplane network (TODO: acquire this is another manner?) // +kubebuilder:validation:Optional CtlplaneGateway string `json:"ctlplaneGateway,omitempty"` + // +kubebuilder:validation:Optional + // CtlplaneVlan - Vlan for ctlplane network + CtlplaneVlan *int `json:"ctlplaneVlan,omitempty"` // DomainName is the domain name that will be set on the underlying Metal3 BaremetalHosts (TODO: acquire this is another manner?) // +kubebuilder:validation:Optional DomainName string `json:"domainName,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 24c65df6..1996c4f7 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -308,6 +308,11 @@ func (in *OpenStackBaremetalSetSpec) DeepCopyInto(out *OpenStackBaremetalSetSpec (*out)[key] = *val.DeepCopy() } } + if in.CtlplaneVlan != nil { + in, out := &in.CtlplaneVlan, &out.CtlplaneVlan + *out = new(int) + **out = **in + } if in.BootstrapDNS != nil { in, out := &in.BootstrapDNS, &out.BootstrapDNS *out = make([]string, len(*in)) diff --git a/config/crd/bases/baremetal.openstack.org_openstackbaremetalsets.yaml b/config/crd/bases/baremetal.openstack.org_openstackbaremetalsets.yaml index c9a2b0b9..a359a3f2 100644 --- a/config/crd/bases/baremetal.openstack.org_openstackbaremetalsets.yaml +++ b/config/crd/bases/baremetal.openstack.org_openstackbaremetalsets.yaml @@ -147,6 +147,9 @@ spec: description: 'CtlplaneNetmask - Netmask to use for ctlplane network (TODO: acquire this is another manner?)' type: string + ctlplaneVlan: + description: CtlplaneVlan - Vlan for ctlplane network + type: integer deploymentSSHSecret: description: DeploymentSSHSecret - Name of secret holding the cloud-admin ssh keys diff --git a/pkg/openstackbaremetalset/baremetalhost.go b/pkg/openstackbaremetalset/baremetalhost.go index 1d4077d9..ed852e08 100644 --- a/pkg/openstackbaremetalset/baremetalhost.go +++ b/pkg/openstackbaremetalset/baremetalhost.go @@ -125,6 +125,9 @@ func BaremetalHostProvision( templateParameters := make(map[string]interface{}) templateParameters["CtlplaneIpVersion"] = CtlplaneIPVersion templateParameters["CtlplaneIp"] = ipAddr + if instance.Spec.CtlplaneVlan != nil { + templateParameters["CtlplaneVlan"] = *instance.Spec.CtlplaneVlan + } templateParameters["CtlplaneInterface"] = instance.Spec.CtlplaneInterface templateParameters["CtlplaneGateway"] = instance.Spec.CtlplaneGateway templateParameters["CtlplaneNetmask"] = net.IP(ipNet.Mask) diff --git a/templates/openstackbaremetalset/cloudinit/networkdata b/templates/openstackbaremetalset/cloudinit/networkdata index 750381a0..ba54a3d4 100644 --- a/templates/openstackbaremetalset/cloudinit/networkdata +++ b/templates/openstackbaremetalset/cloudinit/networkdata @@ -2,9 +2,22 @@ links: - name: {{ .CtlplaneInterface }} id: {{ .CtlplaneInterface }} type: vif +{{- if (index . "CtlplaneVlan") }} +- name: {{ .CtlplaneInterface }}.{{ .CtlplaneVlan }} + id: {{ .CtlplaneInterface }}.{{ .CtlplaneVlan }} + type: vlan + vlan_id: {{ .CtlplaneVlan }} + vlan_link: {{ .CtlplaneInterface }} + vlan_mac_address: null +{{- end }} networks: +{{- if (index . "CtlplaneVlan") }} +- link: {{ .CtlplaneInterface }}.{{ .CtlplaneVlan }} + id: {{ .CtlplaneInterface }}.{{ .CtlplaneVlan }} +{{- else }} - link: {{ .CtlplaneInterface }} id: {{ .CtlplaneInterface }} +{{- end }} type: {{ .CtlplaneIpVersion }} ip_address: {{ .CtlplaneIp }} netmask: "{{ .CtlplaneNetmask }}"