Skip to content

Commit

Permalink
Fixed metallb#2173
Browse files Browse the repository at this point in the history
  • Loading branch information
shimritproj committed Dec 11, 2023
1 parent 2e52e4f commit ad5a656
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions internal/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,53 @@ func (v *validator) Validate(resources ...client.ObjectList) error {
clusterResources.Pools = append(clusterResources.Pools, list.Items...)
case *metallbv1beta2.BGPPeerList:
clusterResources.Peers = append(clusterResources.Peers, list.Items...)
for i := range (clusterResources.Peers) {
clusterResources.Peers[i].Spec.BFDProfile = ""
clusterResources.Peers[i].Spec.PasswordSecret.Name = ""
}
case *metallbv1beta1.BFDProfileList:
clusterResources.BFDProfiles = append(clusterResources.BFDProfiles, list.Items...)
case *metallbv1beta1.BGPAdvertisementList:
clusterResources.BGPAdvs = append(clusterResources.BGPAdvs, list.Items...)
for _, bgpAdv := range(clusterResources.BGPAdvs){
for _, community := range(bgpAdv.Spec.Communities){
if !ExistCommunity(community, clusterResources.Communities){
bgpAdv.Spec.Communities = RemoveElement(bgpAdv.Spec.Communities, community)

}
}
}
case *metallbv1beta1.L2AdvertisementList:
clusterResources.L2Advs = append(clusterResources.L2Advs, list.Items...)
case *metallbv1beta1.AddressPoolList:
clusterResources.LegacyAddressPools = append(clusterResources.LegacyAddressPools, list.Items...)
for _, legacyAddrPool := range clusterResources.LegacyAddressPools {
for _, bgpAdv := range legacyAddrPool.Spec.BGPAdvertisements {
for k := range(bgpAdv.Communities){
if !ExistCommunity(bgpAdv.Communities[k], clusterResources.Communities) {
bgpAdv.Communities = RemoveElement(bgpAdv.Communities, bgpAdv.Communities[k])
}
}
}
}
clusterResources.LegacyAddressPools = append(clusterResources.LegacyAddressPools, list.Items...)
case *metallbv1beta1.CommunityList:
clusterResources.Communities = append(clusterResources.Communities, list.Items...)
case *v1.NodeList:
clusterResources.Nodes = append(clusterResources.Nodes, list.Items...)
}
}

clusterResources = Resetfields(clusterResources)
_, err := For(clusterResources, v.validate)
if errors.As(err, &TransientError{}) { // we do not want to make assumption on ordering in webhooks.
return nil
}
return err
}

func Resetfields(clusterResources ClusterResources) (ClusterResources){
for i := range (clusterResources.Peers) {
clusterResources.Peers[i].Spec.BFDProfile = ""
clusterResources.Peers[i].Spec.PasswordSecret.Name = ""
}
for _, bgpAdv := range(clusterResources.BGPAdvs){
for _, community := range(bgpAdv.Spec.Communities){
if !ExistCommunity(community, clusterResources.Communities){
bgpAdv.Spec.Communities = RemoveElement(bgpAdv.Spec.Communities, community)
}
}
}
for _, legacyAddrPool := range clusterResources.LegacyAddressPools {
for _, bgpAdv := range legacyAddrPool.Spec.BGPAdvertisements {
for k := range(bgpAdv.Communities){
if !ExistCommunity(bgpAdv.Communities[k], clusterResources.Communities) {
bgpAdv.Communities = RemoveElement(bgpAdv.Communities, bgpAdv.Communities[k])
}
}
}
}
return clusterResources
}

func NewValidator(validate Validate) apivalidate.ClusterObjects {
return &validator{validate: validate}
}
Expand Down

0 comments on commit ad5a656

Please sign in to comment.