Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: yurtappset patch #1413

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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