From 3a11131b2ef7678ba3f1dd16a5de4262086b2ce5 Mon Sep 17 00:00:00 2001 From: huiwq1990 Date: Tue, 25 Apr 2023 15:52:01 +0800 Subject: [PATCH] fix: yurtappset patch (#1413) Signed-off-by: huiwq1990 --- .../crds/apps.openyurt.io_yurtappsets.yaml | 1 + pkg/apis/apps/v1alpha1/yurtappset_types.go | 1 + test/e2e/yurt/yurtappset.go | 40 +++++++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/charts/openyurt/crds/apps.openyurt.io_yurtappsets.yaml b/charts/openyurt/crds/apps.openyurt.io_yurtappsets.yaml index 6b7774fdbdf..93ef1d936c2 100644 --- a/charts/openyurt/crds/apps.openyurt.io_yurtappsets.yaml +++ b/charts/openyurt/crds/apps.openyurt.io_yurtappsets.yaml @@ -202,6 +202,7 @@ spec: also modifies the Replicas, use the Replicas value in the Patch type: object + x-kubernetes-preserve-unknown-fields: true replicas: description: Indicates the number of the pod to be created under this pool. diff --git a/pkg/apis/apps/v1alpha1/yurtappset_types.go b/pkg/apis/apps/v1alpha1/yurtappset_types.go index 214484aecdc..5af4f460801 100644 --- a/pkg/apis/apps/v1alpha1/yurtappset_types.go +++ b/pkg/apis/apps/v1alpha1/yurtappset_types.go @@ -139,6 +139,7 @@ type Pool struct { // Patch takes precedence over Replicas fields // If the Patch also modifies the Replicas, use the Replicas value in the Patch // +optional + // +kubebuilder:pruning:PreserveUnknownFields Patch *runtime.RawExtension `json:"patch,omitempty"` } diff --git a/test/e2e/yurt/yurtappset.go b/test/e2e/yurt/yurtappset.go index cf23aed4ca5..3416ccd252c 100644 --- a/test/e2e/yurt/yurtappset.go +++ b/test/e2e/yurt/yurtappset.go @@ -84,21 +84,22 @@ var _ = Describe("YurtAppSet Test", func() { }, timeoutSeconds, time.Millisecond*300).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) + bizContainerName := "biz" testLabel := map[string]string{"app": appName} - var bjPatchTemplate = func() *runtime.RawExtension { - yamlStr := ` - spec: - template: - spec: - containers: - - name: nginx - image: nginx:1.19.0 - ` - b, _ := yaml.YAMLToJSON([]byte(yamlStr)) - return &runtime.RawExtension{Raw: b} - } - testNp := &v1alpha1.YurtAppSet{ + hzBizImg := "busybox:1.36.0" + hzPatchStr := fmt.Sprintf(` +spec: + template: + spec: + containers: + - name: %s + image: %s +`, bizContainerName, hzBizImg) + hzPatchJson, _ := yaml.YAMLToJSON([]byte(hzPatchStr)) + hzPatch := &runtime.RawExtension{Raw: hzPatchJson} + + testYas := &v1alpha1.YurtAppSet{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespaceName, Name: appName, @@ -115,7 +116,7 @@ var _ = Describe("YurtAppSet Test", func() { }, Spec: corev1.PodSpec{ Containers: []corev1.Container{{ - Name: "bb", + Name: bizContainerName, Image: "busybox", Command: []string{"/bin/sh"}, Args: []string{"-c", "while true; do echo hello; sleep 10;done"}, @@ -139,7 +140,6 @@ var _ = Describe("YurtAppSet Test", func() { }, }, Replicas: pointer.Int32Ptr(1), - Patch: bjPatchTemplate(), }, {Name: hzNpName, NodeSelectorTerm: corev1.NodeSelectorTerm{ MatchExpressions: []corev1.NodeSelectorRequirement{ @@ -151,6 +151,7 @@ var _ = Describe("YurtAppSet Test", func() { }, }, Replicas: pointer.Int32Ptr(2), + Patch: hzPatch, }, }, }, @@ -158,7 +159,7 @@ var _ = Describe("YurtAppSet Test", func() { } Eventually(func() error { - return k8sClient.Create(ctx, testNp) + return k8sClient.Create(ctx, testYas) }, timeoutSeconds, time.Millisecond*300).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) Eventually(func() error { @@ -185,6 +186,13 @@ var _ = Describe("YurtAppSet Test", func() { return fmt.Errorf("not reconcile") } for _, tmp := range testPods.Items { + for _, tmpContainer := range tmp.Spec.Containers { + if tmpContainer.Name == bizContainerName { + if tmpContainer.Image != hzBizImg { + return errors.New("yurtappset topology patch not work") + } + } + } if tmp.Status.Phase != corev1.PodRunning { return errors.New("pod not running") }