Skip to content

Commit 010c1e0

Browse files
author
Ryan Zhang
committed
fix api test
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 8e50d3b commit 010c1e0

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

apis/placement/v1beta1/stageupdate_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ const (
171171

172172
// UpdateRunSpec defines the desired rollout strategy and the snapshot indices of the resources to be updated.
173173
// It specifies a stage-by-stage update process across selected clusters for the given ResourcePlacement object.
174-
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.state) || oldSelf.state != 'Initialize' || self.state != 'Pause'",message="invalid state transition: cannot transition from Initialize to Pause"
175-
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.state) || oldSelf.state != 'Execute' || self.state != 'Initialize'",message="invalid state transition: cannot transition from Execute to Initialize"
176-
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.state) || oldSelf.state != 'Pause' || self.state != 'Initialize'",message="invalid state transition: cannot transition from Pause to Initialize"
174+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Initialize' && self.state == 'Pause')",message="invalid state transition: cannot transition from Initialize to Pause"
175+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Execute' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Execute to Initialize"
176+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Pause' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Pause to Initialize"
177177
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.state) || oldSelf.state != 'Abandon' || self.state == 'Abandon'",message="invalid state transition: Abandon is a terminal state and cannot transition to any other state"
178178
type UpdateRunSpec struct {
179179
// PlacementName is the name of placement that this update run is applied to.

config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,16 +1205,16 @@ spec:
12051205
x-kubernetes-validations:
12061206
- message: 'invalid state transition: cannot transition from Initialize
12071207
to Pause'
1208-
rule: '!has(oldSelf.state) || oldSelf.state != ''Initialize'' || self.state
1209-
!= ''Pause'''
1208+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Initialize'' && self.state
1209+
== ''Pause'')'
12101210
- message: 'invalid state transition: cannot transition from Execute to
12111211
Initialize'
1212-
rule: '!has(oldSelf.state) || oldSelf.state != ''Execute'' || self.state
1213-
!= ''Initialize'''
1212+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Execute'' && self.state
1213+
== ''Initialize'')'
12141214
- message: 'invalid state transition: cannot transition from Pause to
12151215
Initialize'
1216-
rule: '!has(oldSelf.state) || oldSelf.state != ''Pause'' || self.state
1217-
!= ''Initialize'''
1216+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Pause'' && self.state
1217+
== ''Initialize'')'
12181218
- message: 'invalid state transition: Abandon is a terminal state and
12191219
cannot transition to any other state'
12201220
rule: '!has(oldSelf.state) || oldSelf.state != ''Abandon'' || self.state

config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ spec:
125125
x-kubernetes-validations:
126126
- message: 'invalid state transition: cannot transition from Initialize
127127
to Pause'
128-
rule: '!has(oldSelf.state) || oldSelf.state != ''Initialize'' || self.state
129-
!= ''Pause'''
128+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Initialize'' && self.state
129+
== ''Pause'')'
130130
- message: 'invalid state transition: cannot transition from Execute to
131131
Initialize'
132-
rule: '!has(oldSelf.state) || oldSelf.state != ''Execute'' || self.state
133-
!= ''Initialize'''
132+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Execute'' && self.state
133+
== ''Initialize'')'
134134
- message: 'invalid state transition: cannot transition from Pause to
135135
Initialize'
136-
rule: '!has(oldSelf.state) || oldSelf.state != ''Pause'' || self.state
137-
!= ''Initialize'''
136+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Pause'' && self.state
137+
== ''Initialize'')'
138138
- message: 'invalid state transition: Abandon is a terminal state and
139139
cannot transition to any other state'
140140
rule: '!has(oldSelf.state) || oldSelf.state != ''Abandon'' || self.state

test/apis/placement/v1beta1/api_validation_integration_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
18131813
})
18141814
})
18151815

1816-
Context("Test ClusterStagedUpdateRun State API validation - valid NotStarted state transitions", func() {
1816+
Context("Test ClusterStagedUpdateRun State API validation - valid Initialize state transitions", func() {
18171817
var updateRun *placementv1beta1.ClusterStagedUpdateRun
18181818
updateRunName := fmt.Sprintf(validupdateRunNameTemplate, GinkgoParallelProcess())
18191819

@@ -1839,15 +1839,15 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
18391839
Name: "unspecfied-state-update-run-" + fmt.Sprintf("%d", GinkgoParallelProcess()),
18401840
},
18411841
Spec: placementv1beta1.UpdateRunSpec{
1842-
// State not specified - should default to NotStarted
1842+
// State not specified - should default to Initialize
18431843
},
18441844
}
18451845
Expect(hubClient.Create(ctx, updateRunWithDefaultState)).Should(Succeed())
18461846
Expect(updateRunWithDefaultState.Spec.State).To(Equal(placementv1beta1.StateNotStarted))
18471847
Expect(hubClient.Delete(ctx, updateRunWithDefaultState)).Should(Succeed())
18481848
})
18491849

1850-
It("should allow creation of ClusterStagedUpdateRun with empty state (defaults to NotStarted)", func() {
1850+
It("should allow creation of ClusterStagedUpdateRun with empty state (defaults to Initialize)", func() {
18511851
updateRun := &placementv1beta1.ClusterStagedUpdateRun{
18521852
ObjectMeta: metav1.ObjectMeta{
18531853
Name: "empty-state-update-run-" + fmt.Sprintf("%d", GinkgoParallelProcess()),
@@ -1861,18 +1861,18 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
18611861
Expect(hubClient.Delete(ctx, updateRun)).Should(Succeed())
18621862
})
18631863

1864-
It("should allow transition from NotStarted to Started", func() {
1864+
It("should allow transition from Initialize to Execute", func() {
18651865
updateRun.Spec.State = placementv1beta1.StateStarted
18661866
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
18671867
})
18681868

1869-
It("should allow transition from NotStarted to Abandoned", func() {
1869+
It("should allow transition from Initialize to Abandon", func() {
18701870
updateRun.Spec.State = placementv1beta1.StateAbandoned
18711871
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
18721872
})
18731873
})
18741874

1875-
Context("Test ClusterStagedUpdateRun State API validation - valid Started state transitions", func() {
1875+
Context("Test ClusterStagedUpdateRun State API validation - valid Execute state transitions", func() {
18761876
var updateRun *placementv1beta1.ClusterStagedUpdateRun
18771877
updateRunName := fmt.Sprintf(validupdateRunNameTemplate, GinkgoParallelProcess())
18781878

@@ -1892,18 +1892,18 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
18921892
Expect(hubClient.Delete(ctx, updateRun)).Should(Succeed())
18931893
})
18941894

1895-
It("should allow transition from Started to Stopped", func() {
1895+
It("should allow transition from Execute to Pause", func() {
18961896
updateRun.Spec.State = placementv1beta1.StateStopped
18971897
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
18981898
})
18991899

1900-
It("should allow transition from Started to Abandoned", func() {
1900+
It("should allow transition from Execute to Abandon", func() {
19011901
updateRun.Spec.State = placementv1beta1.StateAbandoned
19021902
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
19031903
})
19041904
})
19051905

1906-
Context("Test ClusterStagedUpdateRun State API validation - valid Stopped state transitions", func() {
1906+
Context("Test ClusterStagedUpdateRun State API validation - valid Pause state transitions", func() {
19071907
var updateRun *placementv1beta1.ClusterStagedUpdateRun
19081908
updateRunName := fmt.Sprintf(validupdateRunNameTemplate, GinkgoParallelProcess())
19091909

@@ -1917,7 +1917,7 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19171917
},
19181918
}
19191919
Expect(hubClient.Create(ctx, updateRun)).Should(Succeed())
1920-
// Transition to Stopped state first
1920+
// Transition to Pause state first
19211921
updateRun.Spec.State = placementv1beta1.StateStopped
19221922
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
19231923
})
@@ -1926,12 +1926,12 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19261926
Expect(hubClient.Delete(ctx, updateRun)).Should(Succeed())
19271927
})
19281928

1929-
It("should allow transition from Stopped to Started", func() {
1929+
It("should allow transition from Pause to Execute", func() {
19301930
updateRun.Spec.State = placementv1beta1.StateStarted
19311931
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
19321932
})
19331933

1934-
It("should allow transition from Stopped to Abandoned", func() {
1934+
It("should allow transition from Pause to Abandon", func() {
19351935
updateRun.Spec.State = placementv1beta1.StateAbandoned
19361936
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
19371937
})
@@ -1947,7 +1947,7 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19471947
}
19481948
})
19491949

1950-
It("should deny transition from NotStarted to Stopped", func() {
1950+
It("should deny transition from Initialize to Pause", func() {
19511951
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
19521952
ObjectMeta: metav1.ObjectMeta{
19531953
Name: updateRunName,
@@ -1962,10 +1962,10 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19621962
err := hubClient.Update(ctx, updateRun)
19631963
var statusErr *k8sErrors.StatusError
19641964
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
1965-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from NotStarted to Stopped"))
1965+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from Initialize to Pause"))
19661966
})
19671967

1968-
It("should deny transition from Started to NotStarted", func() {
1968+
It("should deny transition from Execute to Initialize", func() {
19691969
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
19701970
ObjectMeta: metav1.ObjectMeta{
19711971
Name: updateRunName,
@@ -1980,10 +1980,10 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19801980
err := hubClient.Update(ctx, updateRun)
19811981
var statusErr *k8sErrors.StatusError
19821982
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
1983-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from Started to NotStarted"))
1983+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from Execute to Initialize"))
19841984
})
19851985

1986-
It("should deny transition from Stopped to NotStarted", func() {
1986+
It("should deny transition from Pause to Initialize", func() {
19871987
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
19881988
ObjectMeta: metav1.ObjectMeta{
19891989
Name: updateRunName,
@@ -1994,19 +1994,19 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
19941994
}
19951995
Expect(hubClient.Create(ctx, updateRun)).Should(Succeed())
19961996

1997-
// Transition to Stopped first
1997+
// Transition to Pause first
19981998
updateRun.Spec.State = placementv1beta1.StateStopped
19991999
Expect(hubClient.Update(ctx, updateRun)).Should(Succeed())
20002000

2001-
// Try to transition back to NotStarted
2001+
// Try to transition back to Initialize
20022002
updateRun.Spec.State = placementv1beta1.StateNotStarted
20032003
err := hubClient.Update(ctx, updateRun)
20042004
var statusErr *k8sErrors.StatusError
20052005
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
2006-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from Stopped to NotStarted"))
2006+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: cannot transition from Pause to Initialize"))
20072007
})
20082008

2009-
It("should deny transition from Abandoned to NotStarted", func() {
2009+
It("should deny transition from Abandon to Initialize", func() {
20102010
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
20112011
ObjectMeta: metav1.ObjectMeta{
20122012
Name: updateRunName,
@@ -2021,10 +2021,10 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
20212021
err := hubClient.Update(ctx, updateRun)
20222022
var statusErr *k8sErrors.StatusError
20232023
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
2024-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandoned is a terminal state and cannot transition to any other state"))
2024+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandon is a terminal state and cannot transition to any other state"))
20252025
})
20262026

2027-
It("should deny transition from Abandoned to Started", func() {
2027+
It("should deny transition from Abandon to Execute", func() {
20282028
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
20292029
ObjectMeta: metav1.ObjectMeta{
20302030
Name: updateRunName,
@@ -2039,10 +2039,10 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
20392039
err := hubClient.Update(ctx, updateRun)
20402040
var statusErr *k8sErrors.StatusError
20412041
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
2042-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandoned is a terminal state and cannot transition to any other state"))
2042+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandon is a terminal state and cannot transition to any other state"))
20432043
})
20442044

2045-
It("should deny transition from Abandoned to Stopped", func() {
2045+
It("should deny transition from Abandon to Pause", func() {
20462046
updateRun = &placementv1beta1.ClusterStagedUpdateRun{
20472047
ObjectMeta: metav1.ObjectMeta{
20482048
Name: updateRunName,
@@ -2057,7 +2057,7 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
20572057
err := hubClient.Update(ctx, updateRun)
20582058
var statusErr *k8sErrors.StatusError
20592059
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
2060-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandoned is a terminal state and cannot transition to any other state"))
2060+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("invalid state transition: Abandon is a terminal state and cannot transition to any other state"))
20612061
})
20622062
})
20632063

@@ -2077,7 +2077,7 @@ var _ = Describe("Test placement v1beta1 API validation", func() {
20772077
err := hubClient.Create(ctx, updateRun)
20782078
var statusErr *k8sErrors.StatusError
20792079
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create ClusterStagedUpdateRun call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
2080-
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("supported values: \"NotStarted\", \"Started\", \"Stopped\", \"Abandoned\""))
2080+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("supported values: \"Initialize\", \"Execute\", \"Pause\", \"Abandon\""))
20812081
})
20822082
})
20832083

0 commit comments

Comments
 (0)