Skip to content

Commit

Permalink
🐛 Make the work feedback rule jaonpath name unique (#346)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
zhujian7 authored Nov 20, 2024
1 parent db876bf commit cb7ce98
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ spec:
- path
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
type:
description: |-
Type defines the option of how status can be returned.
Expand Down
66 changes: 65 additions & 1 deletion test/integration/api/manifestwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var _ = ginkgo.Describe("ManifestWork API test", func() {
gomega.Expect(err).To(gomega.HaveOccurred())
})

ginkgo.It("set feedback rule", func() {
ginkgo.It("set well known status feedback rule", func() {
work := &workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: manifestWorkName,
Expand All @@ -239,5 +239,69 @@ var _ = ginkgo.Describe("ManifestWork API test", func() {
Create(context.TODO(), work, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})

ginkgo.It("set jsonpath feedback rule", func() {
work := &workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: manifestWorkName,
},
Spec: workv1.ManifestWorkSpec{
ManifestConfigs: []workv1.ManifestConfigOption{
{
ResourceIdentifier: workv1.ResourceIdentifier{
Resource: "foo",
Name: "test",
Namespace: "testns",
},
FeedbackRules: []workv1.FeedbackRule{
{
Type: workv1.JSONPathsType,
JsonPaths: []workv1.JsonPath{
{Name: "Replica", Path: ".spec.replicas"},
{Name: "StatusReplica", Path: ".status.replicas"},
},
},
},
},
},
},
}

_, err := hubWorkClient.WorkV1().ManifestWorks(testNamespace).
Create(context.TODO(), work, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})

ginkgo.It("set feedback rule with same jsonpath name", func() {
work := &workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: manifestWorkName,
},
Spec: workv1.ManifestWorkSpec{
ManifestConfigs: []workv1.ManifestConfigOption{
{
ResourceIdentifier: workv1.ResourceIdentifier{
Resource: "foo",
Name: "test",
Namespace: "testns",
},
FeedbackRules: []workv1.FeedbackRule{
{
Type: workv1.JSONPathsType,
JsonPaths: []workv1.JsonPath{
{Name: "Replica", Path: ".spec.replicas"},
{Name: "Replica", Path: ".status.replicas"},
},
},
},
},
},
},
}

_, err := hubWorkClient.WorkV1().ManifestWorks(testNamespace).
Create(context.TODO(), work, metav1.CreateOptions{})
gomega.Expect(err).To(gomega.HaveOccurred())
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ spec:
- path
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
type:
description: |-
Type defines the option of how status can be returned.
Expand Down
2 changes: 2 additions & 0 deletions work/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ type FeedbackRule struct {
Type FeedBackType `json:"type"`

// JsonPaths defines the json path under status field to be synced.
// +listType:=map
// +listMapKey:=name
// +optional
JsonPaths []JsonPath `json:"jsonPaths,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ spec:
- path
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
type:
description: |-
Type defines the option of how status can be returned.
Expand Down

0 comments on commit cb7ce98

Please sign in to comment.