Skip to content

Commit

Permalink
Check route agent connections in subctl diagnose
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Sep 24, 2024
1 parent 33ee906 commit 1ca2842
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ require (
github.com/submariner-io/cloud-prepare v0.19.0-m3
github.com/submariner-io/lighthouse v0.19.0-m3
github.com/submariner-io/shipyard v0.19.0-m3
github.com/submariner-io/submariner v0.19.0-m3
github.com/submariner-io/submariner v0.19.0-m3.0.20240917155703-5a6c358065a2
github.com/submariner-io/submariner-operator v0.19.0-m3
github.com/uw-labs/lichen v0.1.7
golang.org/x/net v0.29.0
golang.org/x/oauth2 v0.23.0
google.golang.org/api v0.195.0
k8s.io/api v0.31.0
k8s.io/api v0.31.1
k8s.io/apiextensions-apiserver v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/mcs-api v0.1.0
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ github.com/submariner-io/lighthouse v0.19.0-m3 h1:CDv7V6lM/ixurJKvM9H9D2ckVXD9bJ
github.com/submariner-io/lighthouse v0.19.0-m3/go.mod h1:SA5PyBm+pM2Dx2MgWFNz/eJPN3Wde4BrnNWysWQzBRQ=
github.com/submariner-io/shipyard v0.19.0-m3 h1:NliwAktRPF4OsLj1TDgpaOJD/bmmZW/FH9+mJmWgxbk=
github.com/submariner-io/shipyard v0.19.0-m3/go.mod h1:BY1ceSnPz1/hN5F9uljcSzy5n5qgAOENsIvZpJ+XPOU=
github.com/submariner-io/submariner v0.19.0-m3 h1:UHfG15WNOFH05WF6keLtj4+y1nxL7HiDmQqG6uk+EEI=
github.com/submariner-io/submariner v0.19.0-m3/go.mod h1:0Am9/udIvtZO8hM7YvRTbIsEWGD8YrCR2JHzNmTGyHg=
github.com/submariner-io/submariner v0.19.0-m3.0.20240917155703-5a6c358065a2 h1:SffTAy7zUR6fOr41EIGccVZHRNuExA78b7lLr84qizg=
github.com/submariner-io/submariner v0.19.0-m3.0.20240917155703-5a6c358065a2/go.mod h1:hKbs5L9QPDslJ6n4k3fsPRbr7JbpT5AVr58YgWQQCKQ=
github.com/submariner-io/submariner-operator v0.19.0-m3 h1:Op0KzkYvXK6cF3cG7KgeaRxKCfj5FJHeUq+s3JetOvI=
github.com/submariner-io/submariner-operator v0.19.0-m3/go.mod h1:XP9FHppFlUyUkoanMOzxJUpDNXZR8hr99cUNqfb2Rug=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down Expand Up @@ -790,22 +790,22 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
k8s.io/api v0.18.4/go.mod h1:lOIQAKYgai1+vz9J7YcDZwC26Z0zQewYOGWdyIPUUQ4=
k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo=
k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE=
k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU=
k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI=
k8s.io/apiextensions-apiserver v0.18.2/go.mod h1:q3faSnRGmYimiocj6cHQ1I3WpLqmDgJFlKL37fC4ZvY=
k8s.io/apiextensions-apiserver v0.18.4/go.mod h1:NYeyeYq4SIpFlPxSAB6jHPIdvu3hL0pc36wuRChybio=
k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk=
k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk=
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.4/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.18.2/go.mod h1:Xbh066NqrZO8cbsoenCwyDJ1OSi8Ag8I2lezeHxzwzw=
k8s.io/apiserver v0.18.4/go.mod h1:q+zoFct5ABNnYkGIaGQ3bcbUNdmPyOCoEBcg51LChY8=
k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU=
k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g=
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
k8s.io/code-generator v0.18.4/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
Expand Down
15 changes: 15 additions & 0 deletions pkg/cluster/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ func (c *Info) GetGateways() ([]submarinerv1.Gateway, error) {
return gateways.Items, nil
}

func (c *Info) GetRouteAgents() ([]submarinerv1.RouteAgent, error) {
routeAgents := &submarinerv1.RouteAgentList{}

err := c.ClientProducer.ForGeneral().List(context.TODO(), routeAgents, controllerClient.InNamespace(constants.OperatorNamespace))
if err != nil {
if resource.IsNotFoundErr(err) {
return []submarinerv1.RouteAgent{}, nil
}

return nil, err //nolint:wrapcheck // error can't be wrapped.
}

return routeAgents.Items, nil
}

func (c *Info) HasSingleNode() (bool, error) {
if c.nodeCount == -1 {
nodes, err := c.ClientProducer.ForKubernetes().CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
Expand Down
59 changes: 51 additions & 8 deletions pkg/diagnose/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ limitations under the License.
package diagnose

import (
"encoding/json"
"errors"

"github.com/submariner-io/admiral/pkg/reporter"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/subctl/pkg/cluster"
submv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
utilerrs "k8s.io/apimachinery/pkg/util/errors"
)

func Connections(clusterInfo *cluster.Info, _ string, status reporter.Interface) error {
return utilerrs.NewAggregate([]error{
checkGatewayConnections(clusterInfo, status),
checkRouteAgentConnections(clusterInfo, status),
})
}

func checkGatewayConnections(clusterInfo *cluster.Info, status reporter.Interface) error {
status.Start("Checking gateway connections")
defer status.End()

Expand Down Expand Up @@ -60,13 +68,8 @@ func Connections(clusterInfo *cluster.Info, _ string, status reporter.Interface)
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)
connection.Endpoint.ClusterID, resource.ToJSON(connection))
}
}
}
Expand All @@ -76,7 +79,47 @@ func Connections(clusterInfo *cluster.Info, _ string, status reporter.Interface)
}

if tracker.HasFailures() {
return errors.New("failures while diagnosing connections")
return errors.New("failures while diagnosing gateway connections")
}

return nil
}

func checkRouteAgentConnections(clusterInfo *cluster.Info, status reporter.Interface) error {
status.Start("Checking route agent connections")
defer status.End()

routeAgents, err := clusterInfo.GetRouteAgents()
if err != nil {
return status.Error(err, "Error retrieving route agents")
}

if len(routeAgents) == 0 {
return status.Error(errors.New("no route agents were detected"), "")
}

tracker := reporter.NewTracker(status)

for i := range routeAgents {
routeAgent := &routeAgents[i]

if len(routeAgent.Status.RemoteEndpoints) == 0 {
tracker.Success("There are no remote endpoint connections on route agent %q", routeAgent.Name)
}

for j := range routeAgent.Status.RemoteEndpoints {
remoteEndpoint := &routeAgent.Status.RemoteEndpoints[j]
if remoteEndpoint.Status == submv1.Connecting {
tracker.Failure("Connection to cluster %q is in progress", remoteEndpoint.Spec.ClusterID)
} else if remoteEndpoint.Status == submv1.ConnectionError {
tracker.Failure("Connection to cluster %q is not established. Connection details:\n%s",
remoteEndpoint.Spec.ClusterID, resource.ToJSON(remoteEndpoint))
}
}
}

if tracker.HasFailures() {
return errors.New("failures while diagnosing route agent connections")
}

return nil
Expand Down

0 comments on commit 1ca2842

Please sign in to comment.