Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adiantum committed Dec 13, 2024
1 parent 6e8c8a7 commit 6360551
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
23 changes: 2 additions & 21 deletions pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"net"

"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -525,25 +523,8 @@ func generateNutanixFailureDomains(eksNutanixFailureDomains []v1alpha1.NutanixDa
return failureDomains
}

func addKubeVipToIgnoredNodeIPsList(clusterSpec *cluster.Spec, result []string) []string {
kubeVipStr := clusterSpec.Cluster.Spec.ControlPlaneConfiguration.Endpoint.Host
if kubeVipStr != "" {
kubeVip, err := net.ResolveIPAddr("ip", kubeVipStr)
if err != nil {
// log error and continue
log.Printf("error resolving kube-vip IP address %s: %v", kubeVipStr, err)
} else {
result = append(result, kubeVip.IP.String())
}
}

return result
}

func generateCcmIgnoredNodeIPsList(clusterSpec *cluster.Spec) []string {
result := make([]string, 0)

result = addKubeVipToIgnoredNodeIPsList(clusterSpec, result)
ignoredIPs := []string{clusterSpec.Cluster.Spec.ControlPlaneConfiguration.Endpoint.Host}

return result
return ignoredIPs
}
14 changes: 14 additions & 0 deletions pkg/providers/nutanix/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nutanix
import (
"context"
"fmt"
"net"
"net/http"
"regexp"
"strconv"
Expand Down Expand Up @@ -49,6 +50,15 @@ func NewValidator(clientCache *ClientCache, certValidator crypto.TlsValidator, h
}
}

func (v *Validator) validateControlPlaneIp(ip string) error {
// check if controlPlaneEndpointIp is valid
parsedIp := net.ParseIP(ip)
if parsedIp == nil {
return fmt.Errorf("cluster controlPlaneConfiguration.Endpoint.Host is invalid: %s", ip)
}
return nil
}

// ValidateClusterSpec validates the cluster spec.
func (v *Validator) ValidateClusterSpec(ctx context.Context, spec *cluster.Spec, creds credentials.BasicAuthCredential) error {
logger.Info("ValidateClusterSpec for Nutanix datacenter", "NutanixDatacenter", spec.NutanixDatacenter.Name)
Expand All @@ -61,6 +71,10 @@ func (v *Validator) ValidateClusterSpec(ctx context.Context, spec *cluster.Spec,
return err
}

if err := v.validateControlPlaneIp(spec.Cluster.Spec.ControlPlaneConfiguration.Endpoint.Host); err != nil {
return err
}

for _, conf := range spec.NutanixMachineConfigs {
if err := v.ValidateMachineConfig(ctx, client, conf); err != nil {
return fmt.Errorf("failed to validate machine config: %v", err)
Expand Down

0 comments on commit 6360551

Please sign in to comment.