Skip to content

Commit

Permalink
clustermesh: Fix clustermesh status when clusters are not connected
Browse files Browse the repository at this point in the history
`cilium clustermesh status` was inadvertently broken by
cilium/cilium-cli#123 when clusters have not
been connected yet. Fix this by expliticly checking cluster's name and
id instead of checking the number of connections.

Add the same warning about missing cluster name and/or id to `cilium
clustermesh enable` as well with a note that external workloads do not
need either.

Fixes: #166
Signed-off-by: Jarno Rajahalme <jarno@covalent.io>
  • Loading branch information
jrajahalme authored and michi-covalent committed Apr 20, 2021
1 parent 50adf71 commit 8c823ee
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cli/clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,21 @@ func (k *K8sClusterMesh) GetClusterConfig(ctx context.Context) error {
}

clusterID := cm.Data[configNameClusterID]
if clusterID == "" || clusterID == "0" {
if clusterID == "" {
clusterID = "0"
}
k.clusterID = clusterID

clusterName := cm.Data[configNameClusterName]
if clusterName == "" || clusterName == "default" {
if clusterName == "" {
clusterName = "default"
}
k.clusterName = clusterName

if clusterID == "0" || clusterName == "default" {
k.Log("⚠️ Cluster not configured for clustermesh, use '--cluster-id' and '--cluster-name' with 'cilium install'. External workloads may still be configured.")
}

return nil
}

Expand Down Expand Up @@ -1125,10 +1129,10 @@ func (k *K8sClusterMesh) determineStatusConnectivity(ctx context.Context) (*Conn
}

func (k *K8sClusterMesh) Status(ctx context.Context, log bool) (*Status, error) {
var (
err error
s = &Status{}
)
err := k.GetClusterConfig(ctx)
if err != nil {
return nil, err
}

collector, err := status.NewK8sStatusCollector(ctx, k.client, status.K8sStatusParameters{
Namespace: k.params.Namespace,
Expand All @@ -1142,6 +1146,7 @@ func (k *K8sClusterMesh) Status(ctx context.Context, log bool) (*Status, error)
ctx, cancel := context.WithTimeout(ctx, k.params.waitTimeout())
defer cancel()

s := &Status{}
s.AccessInformation, err = k.statusAccessInformation(ctx, log)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1175,17 +1180,14 @@ func (k *K8sClusterMesh) Status(ctx context.Context, log bool) (*Status, error)
s.Connectivity, err = k.statusConnectivity(ctx, log)

if log && s.Connectivity != nil {
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 {
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,
s.Connectivity.Connected.Min,
s.Connectivity.Connected.Avg,
s.Connectivity.Connected.Max)
} else {
} else if len(s.Connectivity.Clusters) > 0 {
k.Log("✅ All %d nodes are connected to all clusters [min:%d / avg:%.1f / max:%d]",
s.Connectivity.Total,
s.Connectivity.Connected.Min,
Expand Down

0 comments on commit 8c823ee

Please sign in to comment.