Skip to content

Commit cb7ce98

Browse files
authored
πŸ› Make the work feedback rule jaonpath name unique (#346)
* Make the work feedback rule jaonpath name unique Signed-off-by: zhujian <[email protected]> * Update crds Signed-off-by: zhujian <[email protected]> * Address code review comments Signed-off-by: zhujian <[email protected]> * Add unit tests Signed-off-by: zhujian <[email protected]> --------- Signed-off-by: zhujian <[email protected]>
1 parent db876bf commit cb7ce98

5 files changed

+76
-1
lines changed

β€Žaddon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yamlβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ spec:
203203
- path
204204
type: object
205205
type: array
206+
x-kubernetes-list-map-keys:
207+
- name
208+
x-kubernetes-list-type: map
206209
type:
207210
description: |-
208211
Type defines the option of how status can be returned.

β€Žtest/integration/api/manifestwork_test.goβ€Ž

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ var _ = ginkgo.Describe("ManifestWork API test", func() {
214214
gomega.Expect(err).To(gomega.HaveOccurred())
215215
})
216216

217-
ginkgo.It("set feedback rule", func() {
217+
ginkgo.It("set well known status feedback rule", func() {
218218
work := &workv1.ManifestWork{
219219
ObjectMeta: metav1.ObjectMeta{
220220
Name: manifestWorkName,
@@ -239,5 +239,69 @@ var _ = ginkgo.Describe("ManifestWork API test", func() {
239239
Create(context.TODO(), work, metav1.CreateOptions{})
240240
gomega.Expect(err).ToNot(gomega.HaveOccurred())
241241
})
242+
243+
ginkgo.It("set jsonpath feedback rule", func() {
244+
work := &workv1.ManifestWork{
245+
ObjectMeta: metav1.ObjectMeta{
246+
Name: manifestWorkName,
247+
},
248+
Spec: workv1.ManifestWorkSpec{
249+
ManifestConfigs: []workv1.ManifestConfigOption{
250+
{
251+
ResourceIdentifier: workv1.ResourceIdentifier{
252+
Resource: "foo",
253+
Name: "test",
254+
Namespace: "testns",
255+
},
256+
FeedbackRules: []workv1.FeedbackRule{
257+
{
258+
Type: workv1.JSONPathsType,
259+
JsonPaths: []workv1.JsonPath{
260+
{Name: "Replica", Path: ".spec.replicas"},
261+
{Name: "StatusReplica", Path: ".status.replicas"},
262+
},
263+
},
264+
},
265+
},
266+
},
267+
},
268+
}
269+
270+
_, err := hubWorkClient.WorkV1().ManifestWorks(testNamespace).
271+
Create(context.TODO(), work, metav1.CreateOptions{})
272+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
273+
})
274+
275+
ginkgo.It("set feedback rule with same jsonpath name", func() {
276+
work := &workv1.ManifestWork{
277+
ObjectMeta: metav1.ObjectMeta{
278+
Name: manifestWorkName,
279+
},
280+
Spec: workv1.ManifestWorkSpec{
281+
ManifestConfigs: []workv1.ManifestConfigOption{
282+
{
283+
ResourceIdentifier: workv1.ResourceIdentifier{
284+
Resource: "foo",
285+
Name: "test",
286+
Namespace: "testns",
287+
},
288+
FeedbackRules: []workv1.FeedbackRule{
289+
{
290+
Type: workv1.JSONPathsType,
291+
JsonPaths: []workv1.JsonPath{
292+
{Name: "Replica", Path: ".spec.replicas"},
293+
{Name: "Replica", Path: ".status.replicas"},
294+
},
295+
},
296+
},
297+
},
298+
},
299+
},
300+
}
301+
302+
_, err := hubWorkClient.WorkV1().ManifestWorks(testNamespace).
303+
Create(context.TODO(), work, metav1.CreateOptions{})
304+
gomega.Expect(err).To(gomega.HaveOccurred())
305+
})
242306
})
243307
})

β€Žwork/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yamlβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ spec:
187187
- path
188188
type: object
189189
type: array
190+
x-kubernetes-list-map-keys:
191+
- name
192+
x-kubernetes-list-type: map
190193
type:
191194
description: |-
192195
Type defines the option of how status can be returned.

β€Žwork/v1/types.goβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ type FeedbackRule struct {
226226
Type FeedBackType `json:"type"`
227227

228228
// JsonPaths defines the json path under status field to be synced.
229+
// +listType:=map
230+
// +listMapKey:=name
229231
// +optional
230232
JsonPaths []JsonPath `json:"jsonPaths,omitempty"`
231233
}

β€Žwork/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yamlβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ spec:
210210
- path
211211
type: object
212212
type: array
213+
x-kubernetes-list-map-keys:
214+
- name
215+
x-kubernetes-list-type: map
213216
type:
214217
description: |-
215218
Type defines the option of how status can be returned.

0 commit comments

Comments
Β (0)