Skip to content

Commit

Permalink
feat: update crp webhook to validate the applyStrategy field (Azure#729)
Browse files Browse the repository at this point in the history
update crp webhook
  • Loading branch information
britaniar authored Mar 21, 2024
1 parent 62bc6dc commit cea4be8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/utils/validator/clusterresourceplacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Licensed under the MIT license.
package validator

import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -336,5 +337,12 @@ func validateRolloutStrategy(rolloutStrategy placementv1beta1.RolloutStrategy) e
}
}

// server-side apply strategy type is only valid for server-side apply strategy type
if rolloutStrategy.ApplyStrategy != nil {
if rolloutStrategy.ApplyStrategy.Type != placementv1beta1.ApplyStrategyTypeServerSideApply && rolloutStrategy.ApplyStrategy.ServerSideApplyConfig != nil {
allErr = append(allErr, errors.New("serverSideApplyConfig is only valid for ServerSideApply strategy type"))
}
}

return apiErrors.NewAggregate(allErr)
}
13 changes: 13 additions & 0 deletions pkg/utils/validator/clusterresourceplacement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ func TestValidateClusterResourcePlacement_RolloutStrategy(t *testing.T) {
wantErr: true,
wantErrMsg: "maxSurge must be greater than or equal to 0, got `-10`",
},
"invalid rollout strategy - ServerSideApplyConfig not valid when type is not serversideApply": {
strategy: placementv1beta1.RolloutStrategy{
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
ApplyStrategy: &placementv1beta1.ApplyStrategy{
Type: placementv1beta1.ApplyStrategyTypeFailIfExists,
ServerSideApplyConfig: &placementv1beta1.ServerSideApplyConfig{
ForceConflicts: false,
},
},
},
wantErr: true,
wantErrMsg: "serverSideApplyConfig is only valid for ServerSideApply strategy type",
},
}

for testName, testCase := range tests {
Expand Down

0 comments on commit cea4be8

Please sign in to comment.