Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Oct 6, 2023
1 parent bbe05a4 commit 8bd897a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/utils/validator/clusterresourceplacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func validateClusterAffinity(_ *placementv1beta1.ClusterAffinity) error {
func validateRolloutStrategy(rolloutStrategy placementv1beta1.RolloutStrategy) error {
allErr := make([]error, 0)

if rolloutStrategy.Type != "" && rolloutStrategy.Type != placementv1beta1.RollingUpdateRolloutStrategyType {
allErr = append(allErr, fmt.Errorf("unsupported rollout strategy type `%s`", rolloutStrategy.Type))
}

if rolloutStrategy.RollingUpdate != nil {
if rolloutStrategy.RollingUpdate.UnavailablePeriodSeconds != nil && *rolloutStrategy.RollingUpdate.UnavailablePeriodSeconds < 0 {
allErr = append(allErr, fmt.Errorf("unavailablePeriodSeconds must be greater than or equal to 0, got %d", *rolloutStrategy.RollingUpdate.UnavailablePeriodSeconds))
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/validator/clusterresourceplacement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ func Test_validateClusterResourcePlacement(t *testing.T) {
},
wantErr: false,
},
"invalid rollout strategy": {
crp: &placementv1beta1.ClusterResourcePlacement{
ObjectMeta: metav1.ObjectMeta{
Name: "test-crp",
},
Spec: placementv1beta1.ClusterResourcePlacementSpec{
ResourceSelectors: []placementv1beta1.ClusterResourceSelector{
{
Group: "rbac.authorization.k8s.io",
Version: "v1",
Kind: "ClusterRole",
Name: "test-cluster-role",
},
},
Strategy: placementv1beta1.RolloutStrategy{
Type: "random type",
},
},
},
wantErr: true,
},
"invalid rollout strategy - UnavailablePeriodSeconds": {
crp: &placementv1beta1.ClusterResourcePlacement{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 8bd897a

Please sign in to comment.