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 10, 2023
1 parent 1781c54 commit 1dc5bdc
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions internal/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ func (v *validator) Validate(resources ...client.ObjectList) error {
clusterResources.BFDProfiles = append(clusterResources.BFDProfiles, list.Items...)
case *metallbv1beta1.BGPAdvertisementList:
clusterResources.BGPAdvs = append(clusterResources.BGPAdvs, list.Items...)
for i := range(clusterResources.BGPAdvs){
for j:= range(clusterResources.BGPAdvs[i].Spec.Communities){
if !existString(clusterResources.BGPAdvs[i].Spec.Communities[j],clusterResources.Communities){
clusterResources.BGPAdvs[i].Spec.Communities = removeElement(clusterResources.BGPAdvs[i].Spec.Communities, clusterResources.BGPAdvs[i].Spec.Communities[j])
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 i := range (clusterResources.LegacyAddressPools) {
for j := range(clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements) {
for k := range(clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements[j].Communities){
if !existString(clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements[j].Communities[k], clusterResources.Communities) {
clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements[j].Communities = removeElement(clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements[j].Communities,
clusterResources.LegacyAddressPools[i].Spec.BGPAdvertisements[j].Communities[k])
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])
}
}
}
Expand All @@ -90,18 +90,18 @@ func NewValidator(validate Validate) apivalidate.ClusterObjects {
return &validator{validate: validate}
}

func existString(c string, community []metallbv1beta1.Community ) bool {
for i := range community {
for j := range community[i].Spec.Communities{
if c == community[i].Spec.Communities[j].Name {
func ExistCommunity(community string, communities []metallbv1beta1.Community ) bool {
for i := range communities {
for j := range communities[i].Spec.Communities{
if community == communities[i].Spec.Communities[j].Name {
return true
}
}
}
return false
}

func removeElement(slice []string, elementToRemove string) []string {
func RemoveElement(slice []string, elementToRemove string) []string {
// Find the index of the element
index := -1
for i, v := range slice {
Expand Down

0 comments on commit 1dc5bdc

Please sign in to comment.