Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit cca42aa

Browse files
authored
Merge pull request #1476 from zqzten/kubefedcluster_condition
Introduce cluster config malformed condition to KubeFedCluster
2 parents ae42003 + 809c271 commit cca42aa

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

pkg/apis/core/common/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
ClusterReady ClusterConditionType = "Ready"
2525
// ClusterOffline means the cluster is temporarily down or not reachable
2626
ClusterOffline ClusterConditionType = "Offline"
27+
// ClusterConfigMalformed means the cluster's configuration may be malformed.
28+
ClusterConfigMalformed ClusterConditionType = "ConfigMalformed"
2729
)
2830

2931
const (

pkg/apis/core/v1beta1/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func validateDisabledTLSValidations(disabledTLSValidations []v1beta1.TLSValidati
255255
func validateClusterCondition(cc *v1beta1.ClusterCondition, path *field.Path) field.ErrorList {
256256
var allErrs field.ErrorList
257257

258-
allErrs = append(allErrs, validateEnumStrings(path.Child("type"), string(cc.Type), []string{string(common.ClusterReady), string(common.ClusterOffline)})...)
258+
allErrs = append(allErrs, validateEnumStrings(path.Child("type"), string(cc.Type), []string{string(common.ClusterReady), string(common.ClusterOffline), string(common.ClusterConfigMalformed)})...)
259259
allErrs = append(allErrs, validateEnumStrings(path.Child("status"), string(cc.Status), []string{string(corev1.ConditionTrue), string(corev1.ConditionFalse), string(corev1.ConditionUnknown)})...)
260260

261261
if cc.LastProbeTime.IsZero() {

pkg/controller/kubefedcluster/clusterclient.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
6971
func 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))

pkg/controller/kubefedcluster/controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,17 @@ func (cc *ClusterController) addToClusterSet(obj *fedv1b1.KubeFedCluster) {
175175
cc.mu.Lock()
176176
defer cc.mu.Unlock()
177177
clusterData := cc.clusterDataMap[obj.Name]
178-
if clusterData != nil && clusterData.clusterKubeClient != nil {
178+
if clusterData != nil && clusterData.clusterKubeClient.kubeClient != nil {
179179
return
180180
}
181181

182182
klog.V(1).Infof("ClusterController observed a new cluster: %v", obj.Name)
183183

184184
// create the restclient of cluster
185185
restClient, err := NewClusterClientSet(obj, cc.client, cc.fedNamespace, cc.clusterHealthCheckConfig.Timeout)
186-
if err != nil || restClient == nil {
186+
if err != nil || restClient.kubeClient == nil {
187187
cc.RecordError(obj, "MalformedClusterConfig", errors.Wrap(err, "The configuration for this cluster may be malformed"))
188-
klog.Errorf("The configuration for cluster %s may be malformed", obj.Name)
189-
return
188+
klog.Errorf("The configuration for cluster %q may be malformed: %v", obj.Name, err)
190189
}
191190
cc.clusterDataMap[obj.Name] = &ClusterData{clusterKubeClient: restClient, cachedObj: obj.DeepCopy()}
192191
}
@@ -217,7 +216,7 @@ func (cc *ClusterController) updateClusterStatus() error {
217216
cluster := obj.DeepCopy()
218217
clusterData := cc.clusterDataMap[cluster.Name]
219218
cc.mu.RUnlock()
220-
if clusterData == nil {
219+
if clusterData == nil || clusterData.clusterKubeClient.kubeClient == nil {
221220
// Retry adding cluster client
222221
cc.addToClusterSet(cluster)
223222
cc.mu.RLock()

pkg/controller/sync/status/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func IsRecoverableError(status PropagationStatus) bool {
173173
DeletionFailed,
174174
LabelRemovalFailed,
175175
RetrievalFailed,
176+
ClientRetrievalFailed,
176177
CreationTimedOut,
177178
UpdateTimedOut,
178179
DeletionTimedOut,

0 commit comments

Comments
 (0)