Skip to content

Commit b1518f3

Browse files
Wei WengWei Weng
authored andcommitted
enum for stateful set test yaml
Signed-off-by: Wei Weng <Wei.Weng@microsoft.com>
1 parent 9ba69dd commit b1518f3

8 files changed

+55
-10
lines changed

test/e2e/enveloped_object_placement_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ var _ = Describe("placing wrapped resources using a CRP", func() {
226226
// read the test resources.
227227
readDeploymentTestManifest(&testDeployment)
228228
readDaemonSetTestManifest(&testDaemonSet)
229-
readStatefulSetTestManifest(&testStatefulSet, true)
229+
readStatefulSetTestManifest(&testStatefulSet, StatefulSetWithStorage)
230230
readEnvelopeResourceTestManifest(&testResourceEnvelope)
231231
})
232232

test/e2e/resource_placement_hub_workload_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var _ = Describe("placing workloads using a CRP with PickAll policy", Label("res
3939
// Read the test manifests
4040
readDeploymentTestManifest(&testDeployment)
4141
readDaemonSetTestManifest(&testDaemonSet)
42-
readStatefulSetTestManifest(&testStatefulSet, false)
42+
readStatefulSetTestManifest(&testStatefulSet, StatefulSetWithStorage)
4343
workNamespace := appNamespace()
4444

4545
// Create namespace and workloads

test/e2e/resource_placement_rollout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var _ = Describe("placing namespaced scoped resources using a RP with rollout",
6969
testDaemonSet = appv1.DaemonSet{}
7070
readDaemonSetTestManifest(&testDaemonSet)
7171
testStatefulSet = appv1.StatefulSet{}
72-
readStatefulSetTestManifest(&testStatefulSet, false)
72+
readStatefulSetTestManifest(&testStatefulSet, StatefulSetBasic)
7373
testService = corev1.Service{}
7474
readServiceTestManifest(&testService)
7575
testJob = batchv1.Job{}
File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: test-ss
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: test-ss
9+
serviceName: "test-ss-svc"
10+
replicas: 2
11+
template:
12+
metadata:
13+
labels:
14+
app: test-ss
15+
spec:
16+
terminationGracePeriodSeconds: 10
17+
containers:
18+
- name: pause
19+
image: k8s.gcr.io/pause:3.8
20+
volumeClaimTemplates:
21+
- metadata:
22+
name: test-ss-pvc
23+
spec:
24+
accessModes: [ "ReadWriteOnce" ]
25+
storageClassName: "standard"
26+
resources:
27+
requests:
28+
storage: 100Mi

test/e2e/rollout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ var _ = Describe("placing wrapped resources using a CRP", Ordered, func() {
342342

343343
BeforeAll(func() {
344344
// Create the test resources.
345-
readStatefulSetTestManifest(&testStatefulSet, false)
345+
readStatefulSetTestManifest(&testStatefulSet, StatefulSetBasic)
346346
readEnvelopeResourceTestManifest(&testStatefulSetEnvelope)
347347
wantSelectedResources = []placementv1beta1.ResourceIdentifier{
348348
{

test/e2e/utils_test.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ import (
5757
"github.com/kubefleet-dev/kubefleet/test/e2e/framework"
5858
)
5959

60+
// StatefulSetVariant represents different StatefulSet configurations for testing
61+
type StatefulSetVariant int
62+
63+
const (
64+
// StatefulSetBasic is a StatefulSet without any persistent volume claims
65+
StatefulSetBasic StatefulSetVariant = iota
66+
// StatefulSetInvalidStorage is a StatefulSet with a non-existent storage class
67+
StatefulSetInvalidStorage
68+
// StatefulSetWithStorage is a StatefulSet with a valid standard storage class
69+
StatefulSetWithStorage
70+
)
71+
6072
var (
6173
croTestAnnotationKey = "cro-test-annotation"
6274
croTestAnnotationValue = "cro-test-annotation-val"
@@ -1532,13 +1544,18 @@ func readDaemonSetTestManifest(testDaemonSet *appsv1.DaemonSet) {
15321544
Expect(err).Should(Succeed())
15331545
}
15341546

1535-
func readStatefulSetTestManifest(testStatefulSet *appsv1.StatefulSet, withVolume bool) {
1547+
func readStatefulSetTestManifest(testStatefulSet *appsv1.StatefulSet, variant StatefulSetVariant) {
15361548
By("Read the statefulSet resource")
1537-
if withVolume {
1538-
Expect(utils.GetObjectFromManifest("resources/statefulset-with-volume.yaml", testStatefulSet)).Should(Succeed())
1539-
} else {
1540-
Expect(utils.GetObjectFromManifest("resources/test-statefulset.yaml", testStatefulSet)).Should(Succeed())
1541-
}
1549+
var manifestPath string
1550+
switch variant {
1551+
case StatefulSetBasic:
1552+
manifestPath = "resources/statefulset-basic.yaml"
1553+
case StatefulSetInvalidStorage:
1554+
manifestPath = "resources/statefulset-invalid-storage.yaml"
1555+
case StatefulSetWithStorage:
1556+
manifestPath = "resources/statefulset-with-storage.yaml"
1557+
}
1558+
Expect(utils.GetObjectFromManifest(manifestPath, testStatefulSet)).Should(Succeed())
15421559
}
15431560

15441561
func readServiceTestManifest(testService *corev1.Service) {

0 commit comments

Comments
 (0)