Skip to content

Commit e1135be

Browse files
authored
De duplication logic to NF Deploy Fn Param Ref (#494)
These changes will ensure we have nf deploy fn to apply de dupulication logic to NF Deploy Param Ref 1. Changes to Add Dependency to check if it already exist before adding. Thanks @gvbalaji for the code snippet in chat. 2. Added test cases to handle dependency, if same file is present multiple times. Its not in our use case, but its better to add that too. 3. Added changes to pipeline tests to ensure, if I run the NF Deploy Fn multiples after that, it doesn't break the idempotency principle. Docker image I used for testing - [docker.io/lostbrain/nfdeployfn:test-5](http://docker.io/lostbrain/nfdeployfn:test-5)
1 parent b768829 commit e1135be

File tree

11 files changed

+309
-10
lines changed

11 files changed

+309
-10
lines changed

krm-functions/nfdeploy-fn/fn/function.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku
259259
return nil, err
260260
}
261261

262+
// add all the existing param ref to the struct
263+
// we need to compare for deduplication logic
264+
// slice append is not ideal, it breaks the function idempotency requirement
265+
f.paramRef = nf.Spec.ParametersRefs
266+
262267
capObjs := objs.Where(fn.IsGroupVersionKind(nephioreqv1alpha1.CapacityGroupVersionKind))
263268
for _, o := range capObjs {
264269
if err := f.CapacityUpdate(o); err != nil {
@@ -271,6 +276,7 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku
271276
return nil, err
272277
}
273278
}
279+
274280
itfceObjs := objs.Where(fn.IsGroupVersionKind(nephioreqv1alpha1.InterfaceGroupVersionKind))
275281
for _, o := range itfceObjs {
276282
if err := f.InterfaceUpdate(o); err != nil {
@@ -287,11 +293,7 @@ func (f *NfDeployFn) UpdateResourceFn(nfDeploymentObj *fn.KubeObject, objs fn.Ku
287293

288294
f.FillCapacityDetails(nf)
289295

290-
if len(nf.Spec.ParametersRefs) == 0 {
291-
nf.Spec.ParametersRefs = f.paramRef
292-
} else {
293-
nf.Spec.ParametersRefs = append(nf.Spec.ParametersRefs, f.paramRef...)
294-
}
296+
nf.Spec.ParametersRefs = f.paramRef
295297

296298
//sort the paramRefs
297299
sort.Slice(nf.Spec.ParametersRefs, func(i, j int) bool {

krm-functions/nfdeploy-fn/fn/helper.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,20 @@ func (h *NfDeployFn) FillCapacityDetails(nf *workloadv1alpha1.NFDeployment) {
121121
}
122122

123123
func (h *NfDeployFn) AddDependencyRef(ref corev1.ObjectReference) {
124-
h.paramRef = append(h.paramRef, workloadv1alpha1.ObjectReference{
125-
Name: &ref.Name,
126-
Kind: ref.Kind,
127-
APIVersion: ref.APIVersion,
128-
})
124+
if !h.checkDependencyExist(ref) {
125+
h.paramRef = append(h.paramRef, workloadv1alpha1.ObjectReference{
126+
Name: &ref.Name,
127+
Kind: ref.Kind,
128+
APIVersion: ref.APIVersion,
129+
})
130+
}
131+
}
132+
133+
func (h *NfDeployFn) checkDependencyExist(ref corev1.ObjectReference) bool {
134+
for _, p := range h.paramRef {
135+
if *p.Name == ref.Name && p.Kind == ref.Kind && p.APIVersion == ref.APIVersion {
136+
return true
137+
}
138+
}
139+
return false
129140
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: cluster01-amf
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
info:
8+
description: amf package example
9+
pipeline: {}
10+
status:
11+
conditions:
12+
- message: update condition for initial resource
13+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
14+
status: "True"
15+
type: req.nephio.org/v1alpha1.Capacity.dataplane
16+
- message: update condition for initial resource
17+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
18+
status: "True"
19+
type: req.nephio.org/v1alpha1.DataNetwork.internet
20+
- message: update condition for initial resource
21+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
22+
status: "True"
23+
type: req.nephio.org/v1alpha1.Interface.n2
24+
- message: update for condition
25+
status: "False"
26+
type: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
27+
- message: update condition for initial resource
28+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
29+
status: "True"
30+
type: req.nephio.org/v1alpha1.Dependency.upf
31+
- message: update condition for initial resource
32+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
33+
status: "True"
34+
type: req.nephio.org/v1alpha1.Dependency.upf_duplicate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
apiVersion: config.kubernetes.io/v1
2+
kind: ResourceList
3+
items:
4+
- apiVersion: infra.nephio.org/v1alpha1
5+
kind: WorkloadCluster
6+
metadata:
7+
name: cluster01
8+
annotations:
9+
config.kubernetes.io/local-config: "true"
10+
spec:
11+
clusterName: cluster01
12+
cnis:
13+
- macvlan
14+
- ipvlan
15+
- sriov
16+
masterInterface: eth1
17+
- apiVersion: kpt.dev/v1
18+
kind: Kptfile
19+
metadata:
20+
name: cluster01-amf
21+
annotations:
22+
config.kubernetes.io/local-config: "true"
23+
info:
24+
description: amf package example
25+
readinessGates:
26+
- conditionType: nephio.org.Specializer.specialize
27+
pipeline: {}
28+
status:
29+
conditions:
30+
- message: update condition for initial resource
31+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
32+
status: "True"
33+
type: req.nephio.org/v1alpha1.Capacity.dataplane
34+
- message: update condition for initial resource
35+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
36+
status: "True"
37+
type: req.nephio.org/v1alpha1.DataNetwork.internet
38+
- message: update condition for initial resource
39+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
40+
status: "True"
41+
type: req.nephio.org/v1alpha1.Interface.n2
42+
- message: update done
43+
status: "True"
44+
type: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
45+
- message: update condition for initial resource
46+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
47+
status: "True"
48+
type: req.nephio.org/v1alpha1.Dependency.upf
49+
- message: update condition for initial resource
50+
reason: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
51+
status: "True"
52+
type: req.nephio.org/v1alpha1.Dependency.upf_duplicate
53+
- reason: Ready
54+
status: "True"
55+
type: nephio.org.Specializer.specialize
56+
- apiVersion: req.nephio.org/v1alpha1
57+
kind: Capacity
58+
metadata:
59+
name: dataplane
60+
annotations:
61+
config.kubernetes.io/local-config: "true"
62+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
63+
spec:
64+
maxUplinkThroughput: 0
65+
maxSubscribers: 1000
66+
maxDownlinkThroughput: 0
67+
- apiVersion: req.nephio.org/v1alpha1
68+
kind: DataNetwork
69+
metadata:
70+
name: internet
71+
annotations:
72+
config.kubernetes.io/local-config: "true"
73+
prefix: 10.0.0.0/8
74+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
75+
spec:
76+
status: {}
77+
- apiVersion: req.nephio.org/v1alpha1
78+
kind: Dependency
79+
metadata:
80+
name: upf
81+
annotations:
82+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
83+
specializer.nephio.org/namespace: free5gc-cp
84+
spec:
85+
packageName: free5gc-upf
86+
injectors:
87+
- apiVersion: workload.nephio.org/v1alpha1
88+
kind: NFDeployment
89+
status:
90+
injected:
91+
- name: amf-regional-upf-edge02
92+
namespace: free5gc-cp
93+
apiVersion: ref.nephio.org/v1alpha1
94+
kind: Config
95+
- apiVersion: req.nephio.org/v1alpha1
96+
kind: Dependency
97+
metadata:
98+
name: upf_duplicate
99+
annotations:
100+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
101+
specializer.nephio.org/namespace: free5gc-cp
102+
spec:
103+
packageName: free5gc-upf
104+
injectors:
105+
- apiVersion: workload.nephio.org/v1alpha1
106+
kind: NFDeployment
107+
status:
108+
injected:
109+
- name: amf-regional-upf-edge02
110+
namespace: free5gc-cp
111+
apiVersion: ref.nephio.org/v1alpha1
112+
kind: Config
113+
- apiVersion: req.nephio.org/v1alpha1
114+
kind: Interface
115+
metadata:
116+
name: n2
117+
annotations:
118+
config.kubernetes.io/local-config: "true"
119+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
120+
spec:
121+
networkInstance:
122+
name: vpc-ran
123+
cniType: sriov
124+
attachmentType: vlan
125+
status:
126+
ipClaimStatus:
127+
- prefix: 10.0.0.3/24
128+
gateway: 10.0.0.1
129+
vlanClaimStatus:
130+
vlanID: 100
131+
- apiVersion: workload.nephio.org/v1alpha1
132+
kind: NFDeployment
133+
metadata:
134+
name: amf-cluster01
135+
annotations:
136+
specializer.nephio.org/debug: "true"
137+
spec:
138+
provider: amf.free5gc.io
139+
interfaces:
140+
- name: n2
141+
ipv4:
142+
address: 10.0.0.3/24
143+
gateway: 10.0.0.1
144+
vlanID: 100
145+
networkInstances:
146+
- name: vpc-ran
147+
interfaces:
148+
- n2
149+
parametersRefs:
150+
- name: amf-regional-upf-edge02
151+
apiVersion: ref.nephio.org/v1alpha1
152+
kind: Config
153+
capacity:
154+
maxDownlinkThroughput: "0"
155+
maxSubscribers: 1000
156+
maxUplinkThroughput: "0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: req.nephio.org/v1alpha1
2+
kind: Capacity
3+
metadata:
4+
name: dataplane
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
8+
spec:
9+
maxUplinkThroughput: 0
10+
maxSubscribers: 1000
11+
maxDownlinkThroughput: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: req.nephio.org/v1alpha1
2+
kind: Dependency
3+
metadata:
4+
name: upf
5+
annotations:
6+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
7+
specializer.nephio.org/namespace: free5gc-cp
8+
spec:
9+
packageName: free5gc-upf
10+
injectors:
11+
- apiVersion: workload.nephio.org/v1alpha1
12+
kind: NFDeployment
13+
status:
14+
injected:
15+
- name: amf-regional-upf-edge02
16+
namespace: free5gc-cp
17+
apiVersion: ref.nephio.org/v1alpha1
18+
kind: Config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: req.nephio.org/v1alpha1
2+
kind: Dependency
3+
metadata:
4+
name: upf_duplicate
5+
annotations:
6+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
7+
specializer.nephio.org/namespace: free5gc-cp
8+
spec:
9+
packageName: free5gc-upf
10+
injectors:
11+
- apiVersion: workload.nephio.org/v1alpha1
12+
kind: NFDeployment
13+
status:
14+
injected:
15+
- name: amf-regional-upf-edge02
16+
namespace: free5gc-cp
17+
apiVersion: ref.nephio.org/v1alpha1
18+
kind: Config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: req.nephio.org/v1alpha1
2+
kind: DataNetwork
3+
metadata:
4+
name: internet
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
prefix: 10.0.0.0/8
8+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
9+
spec:
10+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: req.nephio.org/v1alpha1
2+
kind: Interface
3+
metadata:
4+
name: n2
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
specializer.nephio.org/owner: workload.nephio.org/v1alpha1.NFDeployment.amf-cluster01
8+
spec:
9+
networkInstance:
10+
name: vpc-ran
11+
cniType: sriov
12+
attachmentType: vlan
13+
status:
14+
ipClaimStatus:
15+
- prefix: 10.0.0.3/24
16+
gateway: 10.0.0.1
17+
vlanClaimStatus:
18+
vlanID: 100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: workload.nephio.org/v1alpha1
2+
kind: NFDeployment
3+
metadata:
4+
name: amf-cluster01
5+
annotations:
6+
specializer.nephio.org/debug: "true"
7+
spec:
8+
provider: amf.free5gc.io
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: infra.nephio.org/v1alpha1
2+
kind: WorkloadCluster
3+
metadata:
4+
name: cluster01
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
spec:
8+
clusterName: cluster01
9+
cnis:
10+
- macvlan
11+
- ipvlan
12+
- sriov
13+
masterInterface: eth1

0 commit comments

Comments
 (0)