Skip to content

Commit

Permalink
fix: yurtappset patch
Browse files Browse the repository at this point in the history
Signed-off-by: huiwq1990 <[email protected]>
  • Loading branch information
huiwq1990 committed Apr 25, 2023
1 parent e548a5d commit 9324351
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
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
40 changes: 24 additions & 16 deletions test/e2e/yurt/yurtappset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"},
Expand All @@ -139,7 +140,6 @@ var _ = Describe("YurtAppSet Test", func() {
},
},
Replicas: pointer.Int32Ptr(1),
Patch: bjPatchTemplate(),
},
{Name: hzNpName, NodeSelectorTerm: corev1.NodeSelectorTerm{
MatchExpressions: []corev1.NodeSelectorRequirement{
Expand All @@ -151,14 +151,15 @@ var _ = Describe("YurtAppSet Test", func() {
},
},
Replicas: pointer.Int32Ptr(2),
Patch: hzPatch,
},
},
},
},
}

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 {
Expand All @@ -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")
}
Expand Down

0 comments on commit 9324351

Please sign in to comment.