Skip to content

Commit

Permalink
ignore specified update in NAD webhook
Browse files Browse the repository at this point in the history
- For nad validating webhook, ignore the update if the config and route annotation are not being updated.
- For nad mutating webhook, ignore the update if the config is not being updated.
  • Loading branch information
yaocw2020 committed Mar 24, 2023
1 parent c00dd1a commit a91751e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/manager/clusternetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (h Handler) deleteLinkMonitor(name string) error {
func (h Handler) setNadReadyLabel(cn *networkv1.ClusterNetwork) error {
isReady := utils.ValueFalse
// Set all net-attach-defs under the cluster network to be deleted as unready
if cn.DeletionTimestamp != nil && networkv1.Ready.IsTrue(cn.Status) {
if cn.DeletionTimestamp == nil && networkv1.Ready.IsTrue(cn.Status) {
isReady = utils.ValueTrue
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/webhook/nad/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (m *Mutator) Update(_ *types.Request, oldObj, newObj runtime.Object) (types
if newNad.DeletionTimestamp != nil {
return nil, nil
}

// ignore the update if the config is not being updated
if oldNad.Spec.Config == newNad.Spec.Config {
return nil, nil
}
Expand Down Expand Up @@ -120,6 +120,7 @@ func (m *Mutator) ensureLabels(nad *cniv1.NetworkAttachmentDefinition, oldConf,
}}, nil
}

// If the vlan or bridge name is changed, we need to tag the route annotation outdated
func tagRouteOutdated(nad *cniv1.NetworkAttachmentDefinition, oldConf, newConf *utils.NetConf) (types.Patch, error) {
if oldConf.BrName == newConf.BrName && oldConf.Vlan == newConf.Vlan {
return nil, nil
Expand Down
7 changes: 7 additions & 0 deletions pkg/webhook/nad/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ func (v *Validator) Create(_ *types.Request, newObj runtime.Object) error {

func (v *Validator) Update(_ *types.Request, oldObj, newObj runtime.Object) error {
newNad := newObj.(*cniv1.NetworkAttachmentDefinition)
oldNad := oldObj.(*cniv1.NetworkAttachmentDefinition)

// ignore the update if the resource is being deleted
if newNad.DeletionTimestamp != nil {
return nil
}
// ignore the update if the config and route are not being updated
if newNad.Spec.Config == oldNad.Spec.Config &&
newNad.Annotations[utils.KeyNetworkRoute] == oldNad.Annotations[utils.KeyNetworkRoute] {
return nil
}

if err := v.checkNadConfig(newNad.Spec.Config); err != nil {
return fmt.Errorf(updateErr, newNad.Namespace, newNad.Name, err)
Expand Down

0 comments on commit a91751e

Please sign in to comment.