From 78c892eae2ba153f048546381e3a81e2a8a3bb03 Mon Sep 17 00:00:00 2001 From: frapizzato Date: Tue, 27 May 2025 09:12:32 +0200 Subject: [PATCH 1/2] Fix of misalignment between PodNamespaceSelector representations causing parsing error on REAR Controller --- pkg/utils/models/network-identity-models.go | 9 ++------- pkg/utils/parseutil/parseutil.go | 2 +- pkg/utils/resourceforge/forge.go | 20 ++------------------ 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/pkg/utils/models/network-identity-models.go b/pkg/utils/models/network-identity-models.go index 49d9f63..65a0a04 100644 --- a/pkg/utils/models/network-identity-models.go +++ b/pkg/utils/models/network-identity-models.go @@ -58,11 +58,6 @@ type CIDRSelector string // PodNamespaceSelector represents the pod namespace selector of a SourceDestination. type PodNamespaceSelector struct { - Pod []keyValuePair `json:"pod"` - Namespace []keyValuePair `json:"namespace"` -} - -type keyValuePair struct { - Key string `json:"key"` - Value string `json:"value"` + Pod map[string]string `json:"pod"` + Namespace map[string]string `json:"namespace"` } diff --git a/pkg/utils/parseutil/parseutil.go b/pkg/utils/parseutil/parseutil.go index 93f0cf7..d505d81 100644 --- a/pkg/utils/parseutil/parseutil.go +++ b/pkg/utils/parseutil/parseutil.go @@ -489,7 +489,7 @@ func ParseSourceDestination(sourceDestination nodecorev1alpha1.SourceDestination return nil, err } resourceSelector = models.ResourceSelector{ - TypeIdentifier: models.CIDRSelectorType, + TypeIdentifier: models.PodNamespaceSelectorType, Selector: podNamespaceSelectorData, } default: diff --git a/pkg/utils/resourceforge/forge.go b/pkg/utils/resourceforge/forge.go index 31ffc06..ce77ac6 100644 --- a/pkg/utils/resourceforge/forge.go +++ b/pkg/utils/resourceforge/forge.go @@ -766,24 +766,8 @@ func ForgeResourceSelectorFromObj(resourceSelector *models.ResourceSelector) *no } // Create PodNamespaceSelector nodecorev1alpha1 podNamespaceSelectorCR := nodecorev1alpha1.PodNamespaceSelector{ - // Copy map of models.PodNamespaceSelector.Pod to nodecorev1alpha1.PodNamespaceSelector.Pod - Pod: func() map[string]string { - podMap := make(map[string]string) - for i := range resourceSelectorStruct.Pod { - keyValuePair := resourceSelectorStruct.Pod[i] - podMap[keyValuePair.Key] = keyValuePair.Value - } - return podMap - }(), - // Copy map of models.PodNamespaceSelector.Namespace to nodecorev1alpha1.PodNamespaceSelector.Namespace - Namespace: func() map[string]string { - namespaceMap := make(map[string]string) - for i := range resourceSelectorStruct.Namespace { - keyValuePair := resourceSelectorStruct.Namespace[i] - namespaceMap[keyValuePair.Key] = keyValuePair.Value - } - return namespaceMap - }(), + Pod: resourceSelectorStruct.Pod, + Namespace: resourceSelectorStruct.Namespace, } // Marshal PodNamespaceSelector to JSON resourceSelectorData, err := json.Marshal(podNamespaceSelectorCR) From 89f0a6e4f61dd08e7d6536b54a67af2622c05877 Mon Sep 17 00:00:00 2001 From: fluidos Date: Wed, 2 Jul 2025 10:45:25 +0200 Subject: [PATCH 2/2] Fixed mispelling of network intent resource field --- apis/nodecore/v1alpha1/network_intent.go | 4 ++-- pkg/utils/models/network-identity-models.go | 2 +- pkg/utils/parseutil/parseutil.go | 2 +- pkg/utils/resourceforge/forge.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apis/nodecore/v1alpha1/network_intent.go b/apis/nodecore/v1alpha1/network_intent.go index 1a119a0..a278bcf 100644 --- a/apis/nodecore/v1alpha1/network_intent.go +++ b/apis/nodecore/v1alpha1/network_intent.go @@ -52,8 +52,8 @@ type ResourceSelector struct { // SourceDestination can represent either the source or destination of a network intent. type SourceDestination struct { - // IsHotCluster is true if the source/destination is a hot cluster. - IsHotCluster bool `json:"isHotCluster"` + // IsHostCluster is true if the source/destination is a hot cluster. + IsHostCluster bool `json:"isHostCluster"` // ResourceSelector is the resource selector of the source/destination. ResourceSelector ResourceSelector `json:"resourceSelector"` } diff --git a/pkg/utils/models/network-identity-models.go b/pkg/utils/models/network-identity-models.go index 65a0a04..f996c7a 100644 --- a/pkg/utils/models/network-identity-models.go +++ b/pkg/utils/models/network-identity-models.go @@ -43,7 +43,7 @@ type NetworkAuthorizations struct { // SourceDestination represents the source or destination of a network intent. type SourceDestination struct { - IsHotCluster bool `json:"isHotCluster"` + IsHostCluster bool `json:"isHostCluster"` ResourceSelector ResourceSelector `json:"resourceSelectors"` } diff --git a/pkg/utils/parseutil/parseutil.go b/pkg/utils/parseutil/parseutil.go index d505d81..2786de9 100644 --- a/pkg/utils/parseutil/parseutil.go +++ b/pkg/utils/parseutil/parseutil.go @@ -496,7 +496,7 @@ func ParseSourceDestination(sourceDestination nodecorev1alpha1.SourceDestination return nil, fmt.Errorf("unknown resource selector type") } sourceDestinationModel := models.SourceDestination{ - IsHotCluster: sourceDestination.IsHotCluster, + IsHostCluster: sourceDestination.IsHostCluster, ResourceSelector: resourceSelector, } diff --git a/pkg/utils/resourceforge/forge.go b/pkg/utils/resourceforge/forge.go index ce77ac6..2f7864b 100644 --- a/pkg/utils/resourceforge/forge.go +++ b/pkg/utils/resourceforge/forge.go @@ -794,7 +794,7 @@ func ForgeSourceDestinationFromObj(sourceDestination *models.SourceDestination) return nil } return &nodecorev1alpha1.SourceDestination{ - IsHotCluster: sourceDestination.IsHotCluster, + IsHostCluster: sourceDestination.IsHostCluster, ResourceSelector: *resourceSelector, } }