Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reconcilation of resources #1937

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Amulyam24 marked this conversation as resolved.
Show resolved Hide resolved
}

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