Skip to content

Commit f91b98c

Browse files
committed
Refactor reconcilation of resources
1 parent 6ad79d2 commit f91b98c

File tree

3 files changed

+107
-84
lines changed

3 files changed

+107
-84
lines changed

api/v1beta2/ibmpowervscluster_webhook.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterNetwork() *field.Error {
105105
func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancerNames() (allErrs field.ErrorList) {
106106
found := make(map[string]bool)
107107
for i, loadbalancer := range r.Spec.LoadBalancers {
108-
if found[loadbalancer.Name] {
109-
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("loadbalancers[%d]", i)), map[string]interface{}{"Name": loadbalancer.Name}))
108+
if loadbalancer.Name != "" {
109+
if found[loadbalancer.Name] {
110+
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("loadbalancers[%d]", i)), map[string]interface{}{"Name": loadbalancer.Name}))
111+
}
112+
found[loadbalancer.Name] = true
110113
}
111-
found[loadbalancer.Name] = true
112114
}
113115

114116
return allErrs
@@ -117,10 +119,12 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancerNames() (allErr
117119
func (r *IBMPowerVSCluster) validateIBMPowerVSClusterVPCSubnetNames() (allErrs field.ErrorList) {
118120
found := make(map[string]bool)
119121
for i, subnet := range r.Spec.VPCSubnets {
120-
if found[*subnet.Name] {
121-
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("vpcSubnets[%d]", i)), map[string]interface{}{"Name": *subnet.Name}))
122+
if subnet.Name != nil {
123+
if found[*subnet.Name] {
124+
allErrs = append(allErrs, field.Duplicate(field.NewPath("spec", fmt.Sprintf("vpcSubnets[%d]", i)), map[string]interface{}{"Name": *subnet.Name}))
125+
}
126+
found[*subnet.Name] = true
122127
}
123-
found[*subnet.Name] = true
124128
}
125129

126130
return allErrs
@@ -130,6 +134,9 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterTransitGateway() *field.Err
130134
if r.Spec.Zone == nil && r.Spec.VPC == nil {
131135
return nil
132136
}
137+
if r.Spec.TransitGateway == nil {
138+
return nil
139+
}
133140
if _, globalRouting, _ := genUtil.GetTransitGatewayLocationAndRouting(r.Spec.Zone, r.Spec.VPC.Region); r.Spec.TransitGateway.GlobalRouting != nil && !*r.Spec.TransitGateway.GlobalRouting && globalRouting != nil && *globalRouting {
134141
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")
135142
}

0 commit comments

Comments
 (0)