mirror of https://github.com/kubernetes/kops.git
Move DNS validation into validation
This commit is contained in:
parent
717eb4f6c5
commit
02d9819785
|
|
@ -34,7 +34,6 @@ import (
|
||||||
"k8s.io/kops/cmd/kops/util"
|
"k8s.io/kops/cmd/kops/util"
|
||||||
api "k8s.io/kops/pkg/apis/kops"
|
api "k8s.io/kops/pkg/apis/kops"
|
||||||
apiutil "k8s.io/kops/pkg/apis/kops/util"
|
apiutil "k8s.io/kops/pkg/apis/kops/util"
|
||||||
"k8s.io/kops/pkg/dns"
|
|
||||||
"k8s.io/kops/pkg/validation"
|
"k8s.io/kops/pkg/validation"
|
||||||
"k8s.io/kops/util/pkg/tables"
|
"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)
|
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)
|
validationCluster, validationFailed := validation.ValidateCluster(cluster, list, k8sClient)
|
||||||
|
|
||||||
if validationCluster == nil || validationCluster.NodeList == nil || validationCluster.NodeList.Items == nil {
|
if validationCluster == nil || validationCluster.NodeList == nil || validationCluster.NodeList.Items == nil {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ go_library(
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/kops:go_default_library",
|
"//pkg/apis/kops:go_default_library",
|
||||||
"//pkg/apis/kops/util:go_default_library",
|
"//pkg/apis/kops/util:go_default_library",
|
||||||
|
"//pkg/dns:go_default_library",
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
@ -28,6 +27,7 @@ import (
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/pkg/apis/kops/util"
|
"k8s.io/kops/pkg/apis/kops/util"
|
||||||
|
"k8s.io/kops/pkg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidationCluster a cluster to validate.
|
// 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) {
|
func ValidateCluster(cluster *kops.Cluster, instanceGroupList *kops.InstanceGroupList, clusterKubernetesClient kubernetes.Interface) (*ValidationCluster, error) {
|
||||||
clusterName := cluster.Name
|
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
|
var instanceGroups []*kops.InstanceGroup
|
||||||
|
|
||||||
for i := range instanceGroupList.Items {
|
for i := range instanceGroupList.Items {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue