Skip to content

Commit

Permalink
Refactor reconcilation of resources (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 authored Oct 15, 2024
1 parent a10f44e commit 3edcccb
Show file tree
Hide file tree
Showing 4 changed files with 743 additions and 563 deletions.
32 changes: 31 additions & 1 deletion api/v1beta2/ibmpowervscluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,34 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterNetwork() *field.Error {
return nil
}

func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancers() (allErrs field.ErrorList) {
if err := r.validateIBMPowerVSClusterLoadBalancerNames(); err != nil {
allErrs = append(allErrs, err...)
}

if len(r.Spec.LoadBalancers) == 0 {
return allErrs
}

for _, loadbalancer := range r.Spec.LoadBalancers {
if *loadbalancer.Public {
return allErrs
}
}

return append(allErrs, field.Invalid(field.NewPath("spec.LoadBalancers"), r.Spec.LoadBalancers, "Expect atleast one of the load balancer to be public"))
}

func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancerNames() (allErrs field.ErrorList) {
found := make(map[string]bool)
for i, loadbalancer := range r.Spec.LoadBalancers {
if loadbalancer.Name == "" {
continue
}

if found[loadbalancer.Name] {
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("loadbalancers[%d]", i)), map[string]interface{}{"Name": loadbalancer.Name}))
continue
}
found[loadbalancer.Name] = true
}
Expand All @@ -117,8 +140,12 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancerNames() (allErr
func (r *IBMPowerVSCluster) validateIBMPowerVSClusterVPCSubnetNames() (allErrs field.ErrorList) {
found := make(map[string]bool)
for i, subnet := range r.Spec.VPCSubnets {
if subnet.Name == nil {
continue
}
if found[*subnet.Name] {
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("vpcSubnets[%d]", i)), map[string]interface{}{"Name": *subnet.Name}))
continue
}
found[*subnet.Name] = true
}
Expand All @@ -130,6 +157,9 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterTransitGateway() *field.Err
if r.Spec.Zone == nil && r.Spec.VPC == nil {
return nil
}
if r.Spec.TransitGateway == nil {
return nil
}
if _, globalRouting, _ := genUtil.GetTransitGatewayLocationAndRouting(r.Spec.Zone, r.Spec.VPC.Region); r.Spec.TransitGateway.GlobalRouting != nil && !*r.Spec.TransitGateway.GlobalRouting && globalRouting != nil && *globalRouting {
return field.Invalid(field.NewPath("spec.transitGateway.globalRouting"), r.Spec.TransitGateway.GlobalRouting, "global routing is required since PowerVS and VPC region are from different region")
}
Expand Down Expand Up @@ -183,7 +213,7 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterCreateInfraPrereq() (allErr
allErrs = append(allErrs, err...)
}

if err := r.validateIBMPowerVSClusterLoadBalancerNames(); err != nil {
if err := r.validateIBMPowerVSClusterLoadBalancers(); err != nil {
allErrs = append(allErrs, err...)
}

Expand Down
Loading

0 comments on commit 3edcccb

Please sign in to comment.