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

Commit

Permalink
introduce cluster config malformed condition to kubefedcluster
Browse files Browse the repository at this point in the history
  • Loading branch information
zqzten committed Nov 12, 2021
1 parent 2fc7e36 commit fb3e51e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/core/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
ClusterReady ClusterConditionType = "Ready"
// ClusterOffline means the cluster is temporarily down or not reachable
ClusterOffline ClusterConditionType = "Offline"
// ClusterConfigMalformed means the cluster's configuration may be malformed.
ClusterConfigMalformed ClusterConditionType = "ConfigMalformed"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/core/v1beta1/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func validateDisabledTLSValidations(disabledTLSValidations []v1beta1.TLSValidati
func validateClusterCondition(cc *v1beta1.ClusterCondition, path *field.Path) field.ErrorList {
var allErrs field.ErrorList

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

if cc.LastProbeTime.IsZero() {
Expand Down
33 changes: 25 additions & 8 deletions pkg/controller/kubefedcluster/clusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ const (
LabelZoneRegion = "failure-domain.beta.kubernetes.io/region"

// Common ClusterConditions for KubeFedClusterStatus
ClusterReady = "ClusterReady"
HealthzOk = "/healthz responded with ok"
ClusterNotReady = "ClusterNotReady"
HealthzNotOk = "/healthz responded without ok"
ClusterNotReachableReason = "ClusterNotReachable"
ClusterNotReachableMsg = "cluster is not reachable"
ClusterReachableReason = "ClusterReachable"
ClusterReachableMsg = "cluster is reachable"
ClusterReady = "ClusterReady"
HealthzOk = "/healthz responded with ok"
ClusterNotReady = "ClusterNotReady"
HealthzNotOk = "/healthz responded without ok"
ClusterNotReachableReason = "ClusterNotReachable"
ClusterNotReachableMsg = "cluster is not reachable"
ClusterReachableReason = "ClusterReachable"
ClusterReachableMsg = "cluster is reachable"
ClusterConfigMalformedReason = "ClusterConfigMalformed"
ClusterConfigMalformedMsg = "cluster's configuration may be malformed"
)

// ClusterClient provides methods for determining the status and zones of a
Expand Down Expand Up @@ -124,6 +126,21 @@ func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus,
LastProbeTime: currentTime,
LastTransitionTime: &currentTime,
}
clusterConfigMalformedReason := ClusterConfigMalformedReason
clusterConfigMalformedMsg := ClusterConfigMalformedMsg
newClusterConfigMalformedCondition := fedv1b1.ClusterCondition{
Type: fedcommon.ClusterConfigMalformed,
Status: corev1.ConditionTrue,
Reason: &clusterConfigMalformedReason,
Message: &clusterConfigMalformedMsg,
LastProbeTime: currentTime,
LastTransitionTime: &currentTime,
}
if c == nil {
clusterStatus.Conditions = append(clusterStatus.Conditions, newClusterConfigMalformedCondition)
metrics.RegisterKubefedClusterTotal(metrics.ClusterNotReady, c.clusterName)
return &clusterStatus, nil
}
body, err := c.kubeClient.DiscoveryClient.RESTClient().Get().AbsPath("/healthz").Do(context.Background()).Raw()
if err != nil {
runtime.HandleError(errors.Wrapf(err, "Failed to do cluster health check for cluster %q", c.clusterName))
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/kubefedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func (cc *ClusterController) addToClusterSet(obj *fedv1b1.KubeFedCluster) {
if err != nil || restClient == nil {
cc.RecordError(obj, "MalformedClusterConfig", errors.Wrap(err, "The configuration for this cluster may be malformed"))
klog.Errorf("The configuration for cluster %s may be malformed", obj.Name)
return
}
cc.clusterDataMap[obj.Name] = &ClusterData{clusterKubeClient: restClient, cachedObj: obj.DeepCopy()}
}
Expand Down Expand Up @@ -217,7 +216,7 @@ func (cc *ClusterController) updateClusterStatus() error {
cluster := obj.DeepCopy()
clusterData := cc.clusterDataMap[cluster.Name]
cc.mu.RUnlock()
if clusterData == nil {
if clusterData == nil || clusterData.clusterKubeClient == nil {
// Retry adding cluster client
cc.addToClusterSet(cluster)
cc.mu.RLock()
Expand Down

0 comments on commit fb3e51e

Please sign in to comment.