Merge pull request #4735 from justinsb/int_validation_fix_4

Move DNS validation into validation
This commit is contained in:
k8s-ci-robot 2018-03-20 17:46:03 -07:00 committed by GitHub
commit efcae92e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 44 deletions

View File

@ -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 {

View File

@ -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",

View File

@ -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 {