Skip to content

Commit

Permalink
Merge pull request #98126 from ii/statefulset_test
Browse files Browse the repository at this point in the history
Update: StatefulSet Replica scaling to include Patch Scale +1 endpoint
  • Loading branch information
k8s-ci-robot committed Feb 12, 2021
2 parents a2d5c58 + 866f658 commit 5283903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/conformance/testdata/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@
description: Create a StatefulSet resource. Newly created StatefulSet resource MUST
have a scale of one. Bring the scale of the StatefulSet resource up to two. StatefulSet
scale MUST be at two replicas.
release: v1.16
release: v1.16, v1.21
file: test/e2e/apps/statefulset.go
- testname: StatefulSet, Rolling Update with Partition
codename: '[sig-apps] StatefulSet [k8s.io] Basic StatefulSet functionality [StatefulSetBasic]
Expand Down
22 changes: 21 additions & 1 deletion test/e2e/apps/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package apps

import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -830,7 +832,7 @@ var _ = SIGDescribe("StatefulSet", func() {
})

/*
Release: v1.16
Release: v1.16, v1.21
Testname: StatefulSet resource Replica scaling
Description: Create a StatefulSet resource.
Newly created StatefulSet resource MUST have a scale of one.
Expand Down Expand Up @@ -868,6 +870,24 @@ var _ = SIGDescribe("StatefulSet", func() {
framework.Failf("Failed to get statefulset resource: %v", err)
}
framework.ExpectEqual(*(ss.Spec.Replicas), int32(2))

ginkgo.By("Patch a scale subresource")
scale.ResourceVersion = "" // indicate the scale update should be unconditional
scale.Spec.Replicas = 4 // should be 2 after "UpdateScale" operation, now Patch to 4
ssScalePatchPayload, err := json.Marshal(autoscalingv1.Scale{
Spec: autoscalingv1.ScaleSpec{
Replicas: scale.Spec.Replicas,
},
})
framework.ExpectNoError(err, "Could not Marshal JSON for patch payload")

_, err = c.AppsV1().StatefulSets(ns).Patch(context.TODO(), ssName, types.StrategicMergePatchType, []byte(ssScalePatchPayload), metav1.PatchOptions{}, "scale")
framework.ExpectNoError(err, "Failed to patch stateful set: %v", err)

ginkgo.By("verifying the statefulset Spec.Replicas was modified")
ss, err = c.AppsV1().StatefulSets(ns).Get(context.TODO(), ssName, metav1.GetOptions{})
framework.ExpectNoError(err, "Failed to get statefulset resource: %v", err)
framework.ExpectEqual(*(ss.Spec.Replicas), int32(4), "statefulset should have 4 replicas")
})
})

Expand Down

0 comments on commit 5283903

Please sign in to comment.