Skip to content

Commit

Permalink
clustermesh: Fix status when clustermesh is not available
Browse files Browse the repository at this point in the history
This makes 'cilium clustermesh status' succeed with a warning message
instead of failing when Cluster ID and/or Cluster Name has not been
set when Cilium was installed. In that case warn like this:

✅ Service "clustermesh-apiserver" of type "NodePort" found
⚠️  Cluster not configured for clustermesh, use '--cluster-id' and '--cluster-name' with 'cilium install'. External workloads may still be configured.

Signed-off-by: Jarno Rajahalme <jarno@covalent.io>
  • Loading branch information
jrajahalme committed Mar 18, 2021
1 parent 17ebab0 commit 077d821
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 14 additions & 6 deletions clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ retry:
}

func (k *K8sClusterMesh) determineStatusConnectivity(ctx context.Context) (*ConnectivityStatus, error) {
status := &ConnectivityStatus{
stats := &ConnectivityStatus{
GlobalServices: StatisticalStatus{Min: -1},
Connected: StatisticalStatus{Min: -1},
Errors: status.ErrorCountMapMap{},
Expand All @@ -1085,16 +1085,21 @@ func (k *K8sClusterMesh) determineStatusConnectivity(ctx context.Context) (*Conn
for _, pod := range pods.Items {
s, err := k.statusCollector.ClusterMeshConnectivity(ctx, pod.Name)
if err != nil {
if err == status.ErrClusterMeshStatusNotAvailable {
continue
}
return nil, fmt.Errorf("unable to determine status of cilium pod %q: %w", pod.Name, err)
}

status.parseAgentStatus(pod.Name, s)
stats.parseAgentStatus(pod.Name, s)
}

status.GlobalServices.Avg /= float64(len(pods.Items))
status.Connected.Avg /= float64(len(pods.Items))
if len(pods.Items) > 0 {
stats.GlobalServices.Avg /= float64(len(pods.Items))
stats.Connected.Avg /= float64(len(pods.Items))
}

return status, nil
return stats, nil
}

func (k *K8sClusterMesh) Status(ctx context.Context, log bool) (*Status, error) {
Expand Down Expand Up @@ -1148,7 +1153,10 @@ func (k *K8sClusterMesh) Status(ctx context.Context, log bool) (*Status, error)
s.Connectivity, err = k.statusConnectivity(ctx, log)

if log && s.Connectivity != nil {
if s.Connectivity.NotReady > 0 {
if len(s.Connectivity.Clusters) == 0 {
k.Log("⚠️ Cluster not configured for clustermesh, use '--cluster-id' and '--cluster-name' with 'cilium install'. External workloads may still be configured.")
return s, nil
} else if s.Connectivity.NotReady > 0 {
k.Log("⚠️ %d/%d nodes are not connected to all clusters [min:%d / avg:%.1f / max:%d]",
s.Connectivity.NotReady,
s.Connectivity.Total,
Expand Down
5 changes: 4 additions & 1 deletion status/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package status

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -103,6 +104,8 @@ retry:
return s, err
}

var ErrClusterMeshStatusNotAvailable = errors.New("ClusterMesh status is not available")

func (k *K8sStatusCollector) clusterMeshConnectivity(ctx context.Context, ciliumPod string) (*ClusterMeshAgentConnectivityStatus, error) {
c := &ClusterMeshAgentConnectivityStatus{
Clusters: map[string]*models.RemoteCluster{},
Expand All @@ -114,7 +117,7 @@ func (k *K8sStatusCollector) clusterMeshConnectivity(ctx context.Context, cilium
}

if status.ClusterMesh == nil {
return nil, fmt.Errorf("ClusterMesh status is not available")
return nil, ErrClusterMeshStatusNotAvailable
}

c.GlobalServices = status.ClusterMesh.NumGlobalServices
Expand Down

0 comments on commit 077d821

Please sign in to comment.