Skip to content

Commit

Permalink
3826 - backport to 1.4.xwq
Browse files Browse the repository at this point in the history
  • Loading branch information
rrajendran17 authored and starbops committed Aug 19, 2024
1 parent 157d1e2 commit 50eb085
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/webhook/clusternetwork/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (

networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1"
ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1"
"github.com/harvester/harvester-network-controller/pkg/network/iface"
"github.com/harvester/harvester-network-controller/pkg/utils"
)

const (
createErr = "could not create cluster network %s because %w"
deleteErr = "could not delete cluster network %s because %w"
)

Expand All @@ -31,6 +33,19 @@ func NewCnValidator(vcCache ctlnetworkv1.VlanConfigCache) *CnValidator {
return validator
}

func (c *CnValidator) Create(_ *admission.Request, newObj runtime.Object) error {
cn := newObj.(*networkv1.ClusterNetwork)

maxClusterNetworkNameLen := iface.MaxDeviceNameLen - len(iface.BridgeSuffix)

if len(cn.Name) > maxClusterNetworkNameLen {
return fmt.Errorf(createErr, cn.Name, fmt.Errorf("the length of the clusterNetwork value is "+
"more than %d", maxClusterNetworkNameLen))
}

return nil
}

func (c *CnValidator) Delete(_ *admission.Request, oldObj runtime.Object) error {
cn := oldObj.(*networkv1.ClusterNetwork)

Expand Down Expand Up @@ -65,6 +80,7 @@ func (c *CnValidator) Resource() admission.Resource {
APIVersion: networkv1.SchemeGroupVersion.Version,
ObjectType: &networkv1.ClusterNetwork{},
OperationTypes: []admissionregv1.OperationType{
admissionregv1.Create,
admissionregv1.Delete,
},
}
Expand Down

0 comments on commit 50eb085

Please sign in to comment.