diff --git a/pkg/providers/nutanix/template.go b/pkg/providers/nutanix/template.go index 124b2e010c13..b60b0d664472 100644 --- a/pkg/providers/nutanix/template.go +++ b/pkg/providers/nutanix/template.go @@ -4,8 +4,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "log" - "net" "sigs.k8s.io/yaml" @@ -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 } diff --git a/pkg/providers/nutanix/validator.go b/pkg/providers/nutanix/validator.go index 827d91b20652..1edcd0746586 100644 --- a/pkg/providers/nutanix/validator.go +++ b/pkg/providers/nutanix/validator.go @@ -3,6 +3,7 @@ package nutanix import ( "context" "fmt" + "net" "net/http" "regexp" "strconv" @@ -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) @@ -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)