Skip to content

Commit

Permalink
fix: yurtappset patch
Browse files Browse the repository at this point in the history
Signed-off-by: huiwq1990 <huiwq1990@163.com>
  • Loading branch information
huiwq1990 committed Apr 25, 2023
1 parent e548a5d commit ad3e0fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions charts/openyurt/crds/apps.openyurt.io_yurtappsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/apps/v1alpha1/yurtappset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
24 changes: 23 additions & 1 deletion test/e2e/yurt/yurtappset.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ 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 := `
Expand All @@ -97,6 +98,19 @@ var _ = Describe("YurtAppSet Test", func() {
b, _ := yaml.YAMLToJSON([]byte(yamlStr))
return &runtime.RawExtension{Raw: b}
}
hzBizImg := "busybox:1.36.0"
var hzPatchTemplate = func() *runtime.RawExtension {
yamlStr := fmt.Sprintf(`
spec:
template:
spec:
containers:
- name: %s
image: %s
`, bizContainerName, hzBizImg)
b, _ := yaml.YAMLToJSON([]byte(yamlStr))
return &runtime.RawExtension{Raw: b}
}

testNp := &v1alpha1.YurtAppSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -115,7 +129,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"},
Expand Down Expand Up @@ -151,6 +165,7 @@ var _ = Describe("YurtAppSet Test", func() {
},
},
Replicas: pointer.Int32Ptr(2),
Patch: hzPatchTemplate(),
},
},
},
Expand Down Expand Up @@ -185,6 +200,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")
}
Expand Down

0 comments on commit ad3e0fa

Please sign in to comment.