From bfdc62a271ca1905c30cb883b725228ff04d7dc9 Mon Sep 17 00:00:00 2001 From: Jens Jetzork Date: Fri, 15 Mar 2024 12:28:00 +0100 Subject: [PATCH 1/5] prohibit usage of vni zero --- api/v1alpha1/layer2networkconfiguration_types.go | 1 + ...twork.schiff.telekom.de_layer2networkconfigurations.yaml | 1 + pkg/reconciler/layer3.go | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/api/v1alpha1/layer2networkconfiguration_types.go b/api/v1alpha1/layer2networkconfiguration_types.go index b270f5da..a2bc3e8a 100644 --- a/api/v1alpha1/layer2networkconfiguration_types.go +++ b/api/v1alpha1/layer2networkconfiguration_types.go @@ -37,6 +37,7 @@ type Layer2NetworkConfigurationSpec struct { MTU int `json:"mtu"` // +kubebuilder:validation:Required + // +kubebuilder:validation:Minimum=1 // VXLAN VNI Id for the layer 2 network VNI int `json:"vni"` diff --git a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml index feec7d51..9e2b78f1 100644 --- a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml +++ b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml @@ -126,6 +126,7 @@ spec: x-kubernetes-map-type: atomic vni: description: VXLAN VNI Id for the layer 2 network + minimum: 1 type: integer vrf: description: VRF to attach Layer2 network to, default if not set diff --git a/pkg/reconciler/layer3.go b/pkg/reconciler/layer3.go index f3743214..4c3f6706 100644 --- a/pkg/reconciler/layer3.go +++ b/pkg/reconciler/layer3.go @@ -165,6 +165,12 @@ func (r *reconcile) createVrfConfigMap(l3vnis []networkv1alpha1.VRFRouteConfigur continue } + if vni == 0 { + err := fmt.Errorf("VNI can not be set to 0") + r.Logger.Error(err, "VNI can not be set to 0, ignoring", "vrf", spec.VRF, "name", l3vnis[i].ObjectMeta.Name, "namespace", l3vnis[i].ObjectMeta.Namespace) + continue + } + cfg, err := createVrfConfig(vrfConfigMap, &spec, vni, rt) if err != nil { return nil, err From 63d1f4dab6e013561ebbb240a1b89b4226c1a84e Mon Sep 17 00:00:00 2001 From: Jens Jetzork Date: Tue, 19 Mar 2024 07:55:37 +0100 Subject: [PATCH 2/5] implemented check for vni maximum --- .../network.schiff.telekom.de_layer2networkconfigurations.yaml | 1 + pkg/reconciler/layer3.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml index 9e2b78f1..7530c50b 100644 --- a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml +++ b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml @@ -127,6 +127,7 @@ spec: vni: description: VXLAN VNI Id for the layer 2 network minimum: 1 + maximum: 16777215 type: integer vrf: description: VRF to attach Layer2 network to, default if not set diff --git a/pkg/reconciler/layer3.go b/pkg/reconciler/layer3.go index 4c3f6706..f4a12156 100644 --- a/pkg/reconciler/layer3.go +++ b/pkg/reconciler/layer3.go @@ -165,7 +165,7 @@ func (r *reconcile) createVrfConfigMap(l3vnis []networkv1alpha1.VRFRouteConfigur continue } - if vni == 0 { + if vni > 0 && vni < 16777215 { err := fmt.Errorf("VNI can not be set to 0") r.Logger.Error(err, "VNI can not be set to 0, ignoring", "vrf", spec.VRF, "name", l3vnis[i].ObjectMeta.Name, "namespace", l3vnis[i].ObjectMeta.Namespace) continue From 88c397335ff6b651e94b0a027ad3bf797a51b273 Mon Sep 17 00:00:00 2001 From: Jens Jetzork Date: Tue, 19 Mar 2024 07:56:14 +0100 Subject: [PATCH 3/5] added correct check syntax --- pkg/reconciler/layer3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/layer3.go b/pkg/reconciler/layer3.go index f4a12156..4a0295e9 100644 --- a/pkg/reconciler/layer3.go +++ b/pkg/reconciler/layer3.go @@ -165,7 +165,7 @@ func (r *reconcile) createVrfConfigMap(l3vnis []networkv1alpha1.VRFRouteConfigur continue } - if vni > 0 && vni < 16777215 { + if vni == 0 && vni > 16777215 { err := fmt.Errorf("VNI can not be set to 0") r.Logger.Error(err, "VNI can not be set to 0, ignoring", "vrf", spec.VRF, "name", l3vnis[i].ObjectMeta.Name, "namespace", l3vnis[i].ObjectMeta.Namespace) continue From a5736d84cd82a09405a71592cf5758c309c6adbd Mon Sep 17 00:00:00 2001 From: Jens Jetzork Date: Tue, 19 Mar 2024 08:34:13 +0100 Subject: [PATCH 4/5] executed manifest generation --- .../network.schiff.telekom.de_layer2networkconfigurations.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml index 7530c50b..9e2b78f1 100644 --- a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml +++ b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml @@ -127,7 +127,6 @@ spec: vni: description: VXLAN VNI Id for the layer 2 network minimum: 1 - maximum: 16777215 type: integer vrf: description: VRF to attach Layer2 network to, default if not set From 3ad9d0635d0b430d6ee6f609cde672f1279ba86c Mon Sep 17 00:00:00 2001 From: Jens Jetzork Date: Tue, 19 Mar 2024 08:36:50 +0100 Subject: [PATCH 5/5] files are now including maximum for layer2 --- api/v1alpha1/layer2networkconfiguration_types.go | 1 + .../network.schiff.telekom.de_layer2networkconfigurations.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/api/v1alpha1/layer2networkconfiguration_types.go b/api/v1alpha1/layer2networkconfiguration_types.go index a2bc3e8a..153215cf 100644 --- a/api/v1alpha1/layer2networkconfiguration_types.go +++ b/api/v1alpha1/layer2networkconfiguration_types.go @@ -38,6 +38,7 @@ type Layer2NetworkConfigurationSpec struct { // +kubebuilder:validation:Required // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=16777215 // VXLAN VNI Id for the layer 2 network VNI int `json:"vni"` diff --git a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml index 9e2b78f1..198c365c 100644 --- a/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml +++ b/config/crd/bases/network.schiff.telekom.de_layer2networkconfigurations.yaml @@ -126,6 +126,7 @@ spec: x-kubernetes-map-type: atomic vni: description: VXLAN VNI Id for the layer 2 network + maximum: 16777215 minimum: 1 type: integer vrf: