From 02d9819785a8d779e529aae468609ed37a991806 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Tue, 20 Mar 2018 01:22:51 -0400 Subject: [PATCH] Move DNS validation into validation --- cmd/kops/validate_cluster.go | 42 ------------------------------ pkg/validation/BUILD.bazel | 1 + pkg/validation/validate_cluster.go | 30 +++++++++++++++++++-- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/cmd/kops/validate_cluster.go b/cmd/kops/validate_cluster.go index a354050a9c..23da77f135 100644 --- a/cmd/kops/validate_cluster.go +++ b/cmd/kops/validate_cluster.go @@ -34,7 +34,6 @@ import ( "k8s.io/kops/cmd/kops/util" api "k8s.io/kops/pkg/apis/kops" apiutil "k8s.io/kops/pkg/apis/kops/util" - "k8s.io/kops/pkg/dns" "k8s.io/kops/pkg/validation" "k8s.io/kops/util/pkg/tables" ) @@ -130,47 +129,6 @@ func RunValidateCluster(f *util.Factory, cmd *cobra.Command, args []string, out return nil, fmt.Errorf("Cannot build kubernetes api client for %q: %v", contextName, err) } - // Do not use if we are running gossip - if !dns.IsGossipHostname(cluster.ObjectMeta.Name) { - // TODO we may want to return validation.ValidationCluster instead of building it later on - hasPlaceHolderIPAddress, err := validation.HasPlaceHolderIP(contextName) - if err != nil { - return nil, err - } - - if hasPlaceHolderIPAddress { - message := "Validation Failed\n\n" + - "The dns-controller Kubernetes deployment has not updated the Kubernetes cluster's API DNS entry to the correct IP address." + - " The API DNS IP address is the placeholder address that kops creates: 203.0.113.123." + - " Please wait about 5-10 minutes for a master to start, dns-controller to launch, and DNS to propagate." + - " The protokube container and dns-controller deployment logs may contain more diagnostic information." + - " Etcd and the API DNS entries must be updated for a kops Kubernetes cluster to start." - validationCluster := &validation.ValidationCluster{ - ClusterName: cluster.ObjectMeta.Name, - ErrorMessage: message, - Status: validation.ClusterValidationFailed, - } - validationFailed := fmt.Errorf("\nCannot reach cluster's API server: unable to Validate Cluster: %s", cluster.ObjectMeta.Name) - switch options.output { - case OutputTable: - fmt.Println(message) - return validationCluster, validationFailed - case OutputYaml: - if err := validateClusterOutputYAML(validationCluster, validationFailed, out); err != nil { - return nil, err - } - case OutputJSON: - if err := validateClusterOutputJSON(validationCluster, validationFailed, out); err != nil { - return nil, err - } - default: - return nil, fmt.Errorf("Unknown output format: %q", options.output) - } - - return validationCluster, validationFailed - } - } - validationCluster, validationFailed := validation.ValidateCluster(cluster, list, k8sClient) if validationCluster == nil || validationCluster.NodeList == nil || validationCluster.NodeList.Items == nil { diff --git a/pkg/validation/BUILD.bazel b/pkg/validation/BUILD.bazel index cec037ea1b..66fdba083a 100644 --- a/pkg/validation/BUILD.bazel +++ b/pkg/validation/BUILD.bazel @@ -11,6 +11,7 @@ go_library( deps = [ "//pkg/apis/kops:go_default_library", "//pkg/apis/kops/util:go_default_library", + "//pkg/dns:go_default_library", "//vendor/github.com/golang/glog:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", diff --git a/pkg/validation/validate_cluster.go b/pkg/validation/validate_cluster.go index 700200a4bd..d4d86fa3ae 100644 --- a/pkg/validation/validate_cluster.go +++ b/pkg/validation/validate_cluster.go @@ -18,9 +18,8 @@ package validation import ( "fmt" - "net/url" - "net" + "net/url" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -28,6 +27,7 @@ import ( "k8s.io/client-go/tools/clientcmd" "k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/apis/kops/util" + "k8s.io/kops/pkg/dns" ) // ValidationCluster a cluster to validate. @@ -95,6 +95,32 @@ func HasPlaceHolderIP(clusterName string) (bool, error) { func ValidateCluster(cluster *kops.Cluster, instanceGroupList *kops.InstanceGroupList, clusterKubernetesClient kubernetes.Interface) (*ValidationCluster, error) { clusterName := cluster.Name + // Do not use if we are running gossip + if !dns.IsGossipHostname(clusterName) { + contextName := clusterName + + hasPlaceHolderIPAddress, err := HasPlaceHolderIP(contextName) + if err != nil { + return nil, err + } + + if hasPlaceHolderIPAddress { + message := "Validation Failed\n\n" + + "The dns-controller Kubernetes deployment has not updated the Kubernetes cluster's API DNS entry to the correct IP address." + + " The API DNS IP address is the placeholder address that kops creates: 203.0.113.123." + + " Please wait about 5-10 minutes for a master to start, dns-controller to launch, and DNS to propagate." + + " The protokube container and dns-controller deployment logs may contain more diagnostic information." + + " Etcd and the API DNS entries must be updated for a kops Kubernetes cluster to start." + validationCluster := &ValidationCluster{ + ClusterName: clusterName, + ErrorMessage: message, + Status: ClusterValidationFailed, + } + validationFailed := fmt.Errorf("\nCannot reach cluster's API server: unable to Validate Cluster: %s", clusterName) + return validationCluster, validationFailed + } + } + var instanceGroups []*kops.InstanceGroup for i := range instanceGroupList.Items {