From 883252053d0a43d9ee1c6b0e0d8ba18c1984d042 Mon Sep 17 00:00:00 2001 From: Rado Chmiel Date: Fri, 2 Feb 2024 19:21:54 +0100 Subject: [PATCH] Revert "De duplication logic to NF Deploy Fn Param Ref" (#498) Reverts nephio-project/nephio#494 --- krm-functions/nfdeploy-fn/fn/function.go | 12 +- krm-functions/nfdeploy-fn/fn/helper.go | 21 +-- .../Kptfile | 34 ---- .../_expected.yaml | 156 ------------------ .../capacity.yaml | 11 -- .../dependency.yaml | 18 -- .../dependency_1.yaml | 18 -- .../dnn.yaml | 10 -- .../interface-n2.yaml | 18 -- .../nfdeployment.yaml | 8 - .../workload_cluster.yaml | 13 -- 11 files changed, 10 insertions(+), 309 deletions(-) delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/Kptfile delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/_expected.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/capacity.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency_1.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dnn.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/interface-n2.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/nfdeployment.yaml delete mode 100644 krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/workload_cluster.yaml diff --git a/krm-functions/nfdeploy-fn/fn/function.go b/krm-functions/nfdeploy-fn/fn/function.go index 4129b239..fa502894 100644 --- a/krm-functions/nfdeploy-fn/fn/function.go +++ b/krm-functions/nfdeploy-fn/fn/function.go @@ -259,11 +259,6 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku return nil, err } - // add all the existing param ref to the struct - // we need to compare for deduplication logic - // slice append is not ideal, it breaks the function idempotency requirement - f.paramRef = nf.Spec.ParametersRefs - capObjs := objs.Where(fn.IsGroupVersionKind(nephioreqv1alpha1.CapacityGroupVersionKind)) for _, o := range capObjs { if err := f.CapacityUpdate(o); err != nil { @@ -276,7 +271,6 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku return nil, err } } - itfceObjs := objs.Where(fn.IsGroupVersionKind(nephioreqv1alpha1.InterfaceGroupVersionKind)) for _, o := range itfceObjs { if err := f.InterfaceUpdate(o); err != nil { @@ -293,7 +287,11 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku f.FillCapacityDetails(nf) - nf.Spec.ParametersRefs = f.paramRef + if len(nf.Spec.ParametersRefs) == 0 { + nf.Spec.ParametersRefs = f.paramRef + } else { + nf.Spec.ParametersRefs = append(nf.Spec.ParametersRefs, f.paramRef...) + } //sort the paramRefs sort.Slice(nf.Spec.ParametersRefs, func(i, j int) bool { diff --git a/krm-functions/nfdeploy-fn/fn/helper.go b/krm-functions/nfdeploy-fn/fn/helper.go index 8bae5ae1..33f80eb6 100644 --- a/krm-functions/nfdeploy-fn/fn/helper.go +++ b/krm-functions/nfdeploy-fn/fn/helper.go @@ -121,20 +121,9 @@ func (h *NfDeployFn) FillCapacityDetails(nf *workloadv1alpha1.NFDeployment) { } func (h *NfDeployFn) AddDependencyRef(ref corev1.ObjectReference) { - if !h.checkDependencyExist(ref) { - h.paramRef = append(h.paramRef, workloadv1alpha1.ObjectReference{ - Name: &ref.Name, - Kind: ref.Kind, - APIVersion: ref.APIVersion, - }) - } -} - -func (h *NfDeployFn) checkDependencyExist(ref corev1.ObjectReference) bool { - for _, p := range h.paramRef { - if *p.Name == ref.Name && p.Kind == ref.Kind && p.APIVersion == ref.APIVersion { - return true - } - } - return false + h.paramRef = append(h.paramRef, workloadv1alpha1.ObjectReference{ + Name: &ref.Name, + Kind: ref.Kind, + APIVersion: ref.APIVersion, + }) } diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/Kptfile b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/Kptfile deleted file mode 100644 index 99373f61..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/Kptfile +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: cluster01-amf - annotations: - config.kubernetes.io/local-config: "true" -info: - description: amf package example -pipeline: {} -status: - conditions: - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Capacity.dataplane - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.DataNetwork.internet - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Interface.n2 - - message: update for condition - status: "False" - type: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Dependency.upf - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Dependency.upf_duplicate \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/_expected.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/_expected.yaml deleted file mode 100644 index 928960bd..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/_expected.yaml +++ /dev/null @@ -1,156 +0,0 @@ -apiVersion: config.kubernetes.io/v1 -kind: ResourceList -items: -- apiVersion: infra.nephio.org/v1alpha1 - kind: WorkloadCluster - metadata: - name: cluster01 - annotations: - config.kubernetes.io/local-config: "true" - spec: - clusterName: cluster01 - cnis: - - macvlan - - ipvlan - - sriov - masterInterface: eth1 -- apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: cluster01-amf - annotations: - config.kubernetes.io/local-config: "true" - info: - description: amf package example - readinessGates: - - conditionType: nephio.org.Specializer.specialize - pipeline: {} - status: - conditions: - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Capacity.dataplane - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.DataNetwork.internet - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Interface.n2 - - message: update done - status: "True" - type: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Dependency.upf - - message: update condition for initial resource - reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - status: "True" - type: req.nephio.org/v1alpha1.Dependency.upf_duplicate - - reason: Ready - status: "True" - type: nephio.org.Specializer.specialize -- apiVersion: req.nephio.org/v1alpha1 - kind: Capacity - metadata: - name: dataplane - annotations: - config.kubernetes.io/local-config: "true" - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - spec: - maxUplinkThroughput: 0 - maxSubscribers: 1000 - maxDownlinkThroughput: 0 -- apiVersion: req.nephio.org/v1alpha1 - kind: DataNetwork - metadata: - name: internet - annotations: - config.kubernetes.io/local-config: "true" - prefix: 10.0.0.0/8 - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - spec: - status: {} -- apiVersion: req.nephio.org/v1alpha1 - kind: Dependency - metadata: - name: upf - annotations: - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - specializer.nephio.org/namespace: free5gc-cp - spec: - packageName: free5gc-upf - injectors: - - apiVersion: workload.nephio.org/v1alpha1 - kind: NFDeployment - status: - injected: - - name: amf-regional-upf-edge02 - namespace: free5gc-cp - apiVersion: ref.nephio.org/v1alpha1 - kind: Config -- apiVersion: req.nephio.org/v1alpha1 - kind: Dependency - metadata: - name: upf_duplicate - annotations: - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - specializer.nephio.org/namespace: free5gc-cp - spec: - packageName: free5gc-upf - injectors: - - apiVersion: workload.nephio.org/v1alpha1 - kind: NFDeployment - status: - injected: - - name: amf-regional-upf-edge02 - namespace: free5gc-cp - apiVersion: ref.nephio.org/v1alpha1 - kind: Config -- apiVersion: req.nephio.org/v1alpha1 - kind: Interface - metadata: - name: n2 - annotations: - config.kubernetes.io/local-config: "true" - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - spec: - networkInstance: - name: vpc-ran - cniType: sriov - attachmentType: vlan - status: - ipClaimStatus: - - prefix: 10.0.0.3/24 - gateway: 10.0.0.1 - vlanClaimStatus: - vlanID: 100 -- apiVersion: workload.nephio.org/v1alpha1 - kind: NFDeployment - metadata: - name: amf-cluster01 - annotations: - specializer.nephio.org/debug: "true" - spec: - provider: amf.free5gc.io - interfaces: - - name: n2 - ipv4: - address: 10.0.0.3/24 - gateway: 10.0.0.1 - vlanID: 100 - networkInstances: - - name: vpc-ran - interfaces: - - n2 - parametersRefs: - - name: amf-regional-upf-edge02 - apiVersion: ref.nephio.org/v1alpha1 - kind: Config - capacity: - maxDownlinkThroughput: "0" - maxSubscribers: 1000 - maxUplinkThroughput: "0" diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/capacity.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/capacity.yaml deleted file mode 100644 index 97416ba0..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/capacity.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: req.nephio.org/v1alpha1 -kind: Capacity -metadata: - name: dataplane - annotations: - config.kubernetes.io/local-config: "true" - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 -spec: - maxUplinkThroughput: 0 - maxSubscribers: 1000 - maxDownlinkThroughput: 0 diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency.yaml deleted file mode 100644 index 967796b6..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: req.nephio.org/v1alpha1 -kind: Dependency -metadata: - name: upf - annotations: - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - specializer.nephio.org/namespace: free5gc-cp -spec: - packageName: free5gc-upf - injectors: - - apiVersion: workload.nephio.org/v1alpha1 - kind: NFDeployment -status: - injected: - - name: amf-regional-upf-edge02 - namespace: free5gc-cp - apiVersion: ref.nephio.org/v1alpha1 - kind: Config \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency_1.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency_1.yaml deleted file mode 100644 index 385ce475..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dependency_1.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: req.nephio.org/v1alpha1 -kind: Dependency -metadata: - name: upf_duplicate - annotations: - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 - specializer.nephio.org/namespace: free5gc-cp -spec: - packageName: free5gc-upf - injectors: - - apiVersion: workload.nephio.org/v1alpha1 - kind: NFDeployment -status: - injected: - - name: amf-regional-upf-edge02 - namespace: free5gc-cp - apiVersion: ref.nephio.org/v1alpha1 - kind: Config \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dnn.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dnn.yaml deleted file mode 100644 index 201c621b..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/dnn.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: req.nephio.org/v1alpha1 -kind: DataNetwork -metadata: - name: internet - annotations: - config.kubernetes.io/local-config: "true" - prefix: 10.0.0.0/8 - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 -spec: -status: {} \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/interface-n2.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/interface-n2.yaml deleted file mode 100644 index b4e59f25..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/interface-n2.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: req.nephio.org/v1alpha1 -kind: Interface -metadata: - name: n2 - annotations: - config.kubernetes.io/local-config: "true" - specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01 -spec: - networkInstance: - name: vpc-ran - cniType: sriov - attachmentType: vlan -status: - ipClaimStatus: - - prefix: 10.0.0.3/24 - gateway: 10.0.0.1 - vlanClaimStatus: - vlanID: 100 \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/nfdeployment.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/nfdeployment.yaml deleted file mode 100644 index d5beb796..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/nfdeployment.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: workload.nephio.org/v1alpha1 -kind: NFDeployment -metadata: - name: amf-cluster01 - annotations: - specializer.nephio.org/debug: "true" -spec: - provider: amf.free5gc.io \ No newline at end of file diff --git a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/workload_cluster.yaml b/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/workload_cluster.yaml deleted file mode 100644 index fdcebf54..00000000 --- a/krm-functions/nfdeploy-fn/fn/testdata/golden/nfdeployment_witthduplicatedependency/workload_cluster.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: infra.nephio.org/v1alpha1 -kind: WorkloadCluster -metadata: - name: cluster01 - annotations: - config.kubernetes.io/local-config: "true" -spec: - clusterName: cluster01 - cnis: - - macvlan - - ipvlan - - sriov - masterInterface: eth1