Skip to content

Commit

Permalink
Refactor reconcilation of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 committed Sep 24, 2024
1 parent 7716671 commit 0efc9f9
Show file tree
Hide file tree
Showing 4 changed files with 642 additions and 529 deletions.
12 changes: 12 additions & 0 deletions api/v1beta2/ibmpowervscluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterNetwork() *field.Error {
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 +122,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 +139,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
Loading

0 comments on commit 0efc9f9

Please sign in to comment.