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

Commit 0fbc077

Browse files
committed
introduce cluster config malformed condition to kubefedcluster
1 parent 2fc7e36 commit 0fbc077

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

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: 25 additions & 8 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
@@ -124,6 +126,21 @@ func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus,
124126
LastProbeTime: currentTime,
125127
LastTransitionTime: &currentTime,
126128
}
129+
clusterConfigMalformedReason := ClusterConfigMalformedReason
130+
clusterConfigMalformedMsg := ClusterConfigMalformedMsg
131+
newClusterConfigMalformedCondition := fedv1b1.ClusterCondition{
132+
Type: fedcommon.ClusterConfigMalformed,
133+
Status: corev1.ConditionTrue,
134+
Reason: &clusterConfigMalformedReason,
135+
Message: &clusterConfigMalformedMsg,
136+
LastProbeTime: currentTime,
137+
LastTransitionTime: &currentTime,
138+
}
139+
if c == nil {
140+
clusterStatus.Conditions = append(clusterStatus.Conditions, newClusterConfigMalformedCondition)
141+
metrics.RegisterKubefedClusterTotal(metrics.ClusterNotReady, c.clusterName)
142+
return &clusterStatus, nil
143+
}
127144
body, err := c.kubeClient.DiscoveryClient.RESTClient().Get().AbsPath("/healthz").Do(context.Background()).Raw()
128145
if err != nil {
129146
runtime.HandleError(errors.Wrapf(err, "Failed to do cluster health check for cluster %q", c.clusterName))

pkg/controller/kubefedcluster/controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func (cc *ClusterController) addToClusterSet(obj *fedv1b1.KubeFedCluster) {
186186
if err != nil || restClient == nil {
187187
cc.RecordError(obj, "MalformedClusterConfig", errors.Wrap(err, "The configuration for this cluster may be malformed"))
188188
klog.Errorf("The configuration for cluster %s may be malformed", obj.Name)
189-
return
190189
}
191190
cc.clusterDataMap[obj.Name] = &ClusterData{clusterKubeClient: restClient, cachedObj: obj.DeepCopy()}
192191
}

0 commit comments

Comments
 (0)