Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip vlanconfig webhook if the spec is not changed
Browse files Browse the repository at this point in the history
yaocw2020 committed Mar 23, 2023
1 parent 9db718d commit 5f517ae
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/webhook/vlanconfig/mutator.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package vlanconfig
import (
"encoding/json"
"fmt"
"reflect"

"github.com/harvester/webhook/pkg/types"
ctlcorev1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
@@ -43,6 +44,11 @@ func (m *Mutator) Update(_ *types.Request, oldObj, newObj runtime.Object) (types
newVc := newObj.(*networkv1.VlanConfig)
oldVc := oldObj.(*networkv1.VlanConfig)

// skip mutation if spec is not changed
if reflect.DeepEqual(oldVc.Spec, newVc.Spec) {
return nil, nil
}

var cnLabelPatch, annotationPatch types.Patch
if newVc.Spec.ClusterNetwork != oldVc.Spec.ClusterNetwork {
cnLabelPatch = getCnLabelPatch(newVc)
5 changes: 5 additions & 0 deletions pkg/webhook/vlanconfig/validator.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package vlanconfig
import (
"encoding/json"
"fmt"
"reflect"
"strings"

mapset "github.com/deckarep/golang-set/v2"
@@ -83,6 +84,10 @@ func (v *Validator) Update(_ *types.Request, oldObj, newObj runtime.Object) erro
return fmt.Errorf(updateErr, newVc.Name, fmt.Errorf("cluster network could not be %s",
utils.ManagementClusterNetworkName))
}
// skip validation if spec is not changed
if reflect.DeepEqual(oldVc.Spec, newVc.Spec) {
return nil
}

newNodes, err := getMatchNodes(newVc)
if err != nil {

0 comments on commit 5f517ae

Please sign in to comment.