@@ -46,14 +46,16 @@ const (
4646 LabelZoneRegion = "failure-domain.beta.kubernetes.io/region"
4747
4848 // Common ClusterConditions for KubeFedClusterStatus
49- ClusterReady = "ClusterReady"
50- HealthzOk = "/healthz responded with ok"
51- ClusterNotReady = "ClusterNotReady"
52- HealthzNotOk = "/healthz responded without ok"
53- ClusterNotReachableReason = "ClusterNotReachable"
54- ClusterNotReachableMsg = "cluster is not reachable"
55- ClusterReachableReason = "ClusterReachable"
56- ClusterReachableMsg = "cluster is reachable"
49+ ClusterReady = "ClusterReady"
50+ HealthzOk = "/healthz responded with ok"
51+ ClusterNotReady = "ClusterNotReady"
52+ HealthzNotOk = "/healthz responded without ok"
53+ ClusterNotReachableReason = "ClusterNotReachable"
54+ ClusterNotReachableMsg = "cluster is not reachable"
55+ ClusterReachableReason = "ClusterReachable"
56+ ClusterReachableMsg = "cluster is reachable"
57+ ClusterConfigMalformedReason = "ClusterConfigMalformed"
58+ ClusterConfigMalformedMsg = "cluster's configuration may be malformed"
5759)
5860
5961// ClusterClient provides methods for determining the status and zones of a
@@ -67,17 +69,14 @@ type ClusterClient struct {
6769// The kubeClient is used to configure the ClusterClient's internal client
6870// with information from a kubeconfig stored in a kubernetes secret.
6971func NewClusterClientSet (c * fedv1b1.KubeFedCluster , client generic.Client , fedNamespace string , timeout time.Duration ) (* ClusterClient , error ) {
72+ var clusterClientSet = ClusterClient {clusterName : c .Name }
7073 clusterConfig , err := util .BuildClusterConfig (c , client , fedNamespace )
7174 if err != nil {
72- return nil , err
75+ return & clusterClientSet , err
7376 }
7477 clusterConfig .Timeout = timeout
75- var clusterClientSet = ClusterClient {clusterName : c .Name }
76- clusterClientSet .kubeClient = kubeclientset .NewForConfigOrDie ((restclient .AddUserAgent (clusterConfig , UserAgentName )))
77- if clusterClientSet .kubeClient == nil {
78- return nil , nil
79- }
80- return & clusterClientSet , nil
78+ clusterClientSet .kubeClient , err = kubeclientset .NewForConfig (restclient .AddUserAgent (clusterConfig , UserAgentName ))
79+ return & clusterClientSet , err
8180}
8281
8382// GetClusterHealthStatus gets the kubernetes cluster health status by requesting "/healthz"
@@ -124,6 +123,21 @@ func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus,
124123 LastProbeTime : currentTime ,
125124 LastTransitionTime : & currentTime ,
126125 }
126+ clusterConfigMalformedReason := ClusterConfigMalformedReason
127+ clusterConfigMalformedMsg := ClusterConfigMalformedMsg
128+ newClusterConfigMalformedCondition := fedv1b1.ClusterCondition {
129+ Type : fedcommon .ClusterConfigMalformed ,
130+ Status : corev1 .ConditionTrue ,
131+ Reason : & clusterConfigMalformedReason ,
132+ Message : & clusterConfigMalformedMsg ,
133+ LastProbeTime : currentTime ,
134+ LastTransitionTime : & currentTime ,
135+ }
136+ if c .kubeClient == nil {
137+ clusterStatus .Conditions = append (clusterStatus .Conditions , newClusterConfigMalformedCondition )
138+ metrics .RegisterKubefedClusterTotal (metrics .ClusterNotReady , c .clusterName )
139+ return & clusterStatus , nil
140+ }
127141 body , err := c .kubeClient .DiscoveryClient .RESTClient ().Get ().AbsPath ("/healthz" ).Do (context .Background ()).Raw ()
128142 if err != nil {
129143 runtime .HandleError (errors .Wrapf (err , "Failed to do cluster health check for cluster %q" , c .clusterName ))
0 commit comments