Skip to content

Commit

Permalink
add host group validations for vsAddress and ipamLabel (#3316)
Browse files Browse the repository at this point in the history
* add host group validations for vsAddress and ipamLabel

* fix uts
  • Loading branch information
vidyasagar-m committed Mar 5, 2024
1 parent 03ceb63 commit 3dc3ee6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/controller/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,24 @@ func (ctlr *Controller) getAssociatedVirtualServers(

// skip the virtuals in other HostGroups
if vrt.Spec.HostGroup != currentVS.Spec.HostGroup {
if currentVS.Spec.VirtualServerAddress != "" && vrt.Spec.VirtualServerAddress != "" && currentVS.Spec.VirtualServerAddress == vrt.Spec.VirtualServerAddress {
log.Errorf("Multiple Virtual Servers %v, %v are configured with same VirtualServerAddress: %v", currentVS.Name, vrt.Name, vrt.Spec.VirtualServerAddress)
return nil
}
continue
}

if vrt.Spec.HostGroup != "" && currentVS.Spec.HostGroup != "" && vrt.Spec.HostGroup == currentVS.Spec.HostGroup {
if currentVS.Spec.VirtualServerAddress != "" && vrt.Spec.VirtualServerAddress != "" && currentVS.Spec.VirtualServerAddress != vrt.Spec.VirtualServerAddress {
log.Errorf("Multiple Virtual Servers %v, %v are configured with different VirtualServerAddress: %v %v", currentVS.Name, vrt.Name, currentVS.Spec.VirtualServerAddress, vrt.Spec.VirtualServerAddress)
return nil
}
if currentVS.Spec.IPAMLabel != "" && vrt.Spec.IPAMLabel != "" && currentVS.Spec.IPAMLabel != vrt.Spec.IPAMLabel {
log.Errorf("Multiple Virtual Servers %v, %v are configured with different IPAM Labels: %v %v", currentVS.Name, vrt.Name, currentVS.Spec.IPAMLabel, vrt.Spec.IPAMLabel)
return nil
}
}

if currentVS.Spec.HostGroup != "" && vrt.Spec.HostGroup == currentVS.Spec.HostGroup && vrt.Spec.HostGroupVirtualServerName != currentVS.Spec.HostGroupVirtualServerName {
log.Errorf("Same host %v is configured with different HostGroupVirtualServerNames : %v ", vrt.Spec.HostGroup, vrt.Spec.HostGroupVirtualServerName)
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ var _ = Describe("Worker Tests", func() {
vrt2.Spec.HostGroup = "test"
vrt3.Spec.HostGroup = "test"
vrt3.Spec.Host = "test3.com"
vrt4.Spec.VirtualServerAddress = ""

virts := mockCtlr.getAssociatedVirtualServers(vrt2,
[]*cisapiv1.VirtualServer{vrt2, vrt3, vrt4},
Expand All @@ -665,6 +666,7 @@ var _ = Describe("Worker Tests", func() {
vrt3.Spec.HostGroup = "test"
vrt3.Spec.Host = "test3.com"
vrt3.Spec.VirtualServerAddress = ""
vrt4.Spec.VirtualServerAddress = ""

virts := mockCtlr.getAssociatedVirtualServers(vrt2,
[]*cisapiv1.VirtualServer{vrt2, vrt3, vrt4},
Expand Down

0 comments on commit 3dc3ee6

Please sign in to comment.