Skip to content

Commit

Permalink
fix, ruleset webhook validating (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaofan-hs committed Aug 22, 2023
1 parent 93d00d0 commit bc4476b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/webhook/server/generic/pod/ruleset/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ func (r *RuleSetWebhook) Validating(ctx context.Context, c client.Client, oldPod
if !utils.ControlledByPodOpsLifecycle(newPod) || newPod.Annotations == nil {
return nil
}
ruleSetAnno := newPod.Annotations[appsv1alpha1.AnnotationRuleSets]
if operation == admissionv1.Update && ruleSetAnno == oldPod.Annotations[appsv1alpha1.AnnotationRuleSets] {

ruleSetAnno, ok := newPod.Annotations[appsv1alpha1.AnnotationRuleSets]
if (operation == admissionv1.Create && !ok) ||
(operation == admissionv1.Update && ruleSetAnno == oldPod.Annotations[appsv1alpha1.AnnotationRuleSets]) {
return nil
}

rs := &RuleSets{}
if err := json.Unmarshal([]byte(ruleSetAnno), rs); err != nil {
return fmt.Errorf("fail to unmarshal RuleSet annotation %s: %v", ruleSetAnno, err)
Expand Down

0 comments on commit bc4476b

Please sign in to comment.