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 12, 2023
1 parent 9b355c6 commit f0d1d7c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions internal/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ func (v *validator) Validate(resources ...client.ObjectList) error {
return err
}

func resetfields(clusterResources ClusterResources) ClusterResources{
for i := range (clusterResources.Peers) {
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){
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){
for k := range bgpAdv.Communities {
if !ExistCommunity(bgpAdv.Communities[k], clusterResources.Communities) {
bgpAdv.Communities = RemoveElement(bgpAdv.Communities, bgpAdv.Communities[k])
}
}
}
}
}
return clusterResources
Expand All @@ -94,9 +94,9 @@ func NewValidator(validate Validate) apivalidate.ClusterObjects {
return &validator{validate: validate}
}

func ExistCommunity(community string, communities []metallbv1beta1.Community ) bool {
func ExistCommunity(community string, communities []metallbv1beta1.Community) bool {
for i := range communities {
for j := range communities[i].Spec.Communities{
for j := range communities[i].Spec.Communities {
if community == communities[i].Spec.Communities[j].Name {
return true
}
Expand All @@ -106,21 +106,21 @@ func ExistCommunity(community string, communities []metallbv1beta1.Community ) b
}

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

// If the element is found, remove it
if index != -1 {
// Create a new slice without the element
return append(slice[:index], slice[index+1:]...)
}
// If the element is found, remove it
if index != -1 {
// Create a new slice without the element
return append(slice[:index], slice[index+1:]...)
}

// If the element is not found, return the original slice
return slice
// If the element is not found, return the original slice
return slice
}

0 comments on commit f0d1d7c

Please sign in to comment.