/
connections.go
83 lines (64 loc) · 2.28 KB
/
connections.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the Submariner project.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package diagnose
import (
"encoding/json"
"errors"
"github.com/submariner-io/admiral/pkg/reporter"
"github.com/submariner-io/subctl/pkg/cluster"
submv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
)
func Connections(clusterInfo *cluster.Info, _ string, status reporter.Interface) error {
status.Start("Checking gateway connections")
defer status.End()
gateways, err := clusterInfo.GetGateways()
if err != nil {
return status.Error(err, "Error retrieving gateways")
}
if len(gateways) == 0 {
return status.Error(errors.New("no gateways were detected"), "")
}
tracker := reporter.NewTracker(status)
foundActive := false
for i := range gateways {
gateway := &gateways[i]
if gateway.Status.HAStatus != submv1.HAStatusActive {
continue
}
foundActive = true
if len(gateway.Status.Connections) == 0 {
tracker.Failure("There are no active connections on gateway %q", gateway.Name)
}
for j := range gateway.Status.Connections {
connection := &gateway.Status.Connections[j]
if connection.Status == submv1.Connecting {
tracker.Failure("Connection to cluster %q is in progress", connection.Endpoint.ClusterID)
} else if connection.Status == submv1.ConnectionError {
out, err := json.MarshalIndent(connection, "", " ")
if err != nil {
tracker.Warning("Unable to marshal Connection to json: %v", err)
}
tracker.Failure("Connection to cluster %q is not established. Connection details:\n%s",
connection.Endpoint.ClusterID, out)
}
}
}
if !foundActive {
tracker.Failure("No active gateway was found")
}
if tracker.HasFailures() {
return errors.New("failures while diagnosing connections")
}
return nil
}