From 1ca2842ba4766b6805fabb7cf24e7454741fbb00 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Mon, 16 Sep 2024 13:32:34 -0400 Subject: [PATCH] Check route agent connections in subctl diagnose Signed-off-by: Tom Pantelis --- go.mod | 8 ++--- go.sum | 16 +++++----- pkg/cluster/info.go | 15 ++++++++++ pkg/diagnose/connections.go | 59 ++++++++++++++++++++++++++++++++----- 4 files changed, 78 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 13663e6d5..70d921be4 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 4cfcb3124..22f5352aa 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/cluster/info.go b/pkg/cluster/info.go index 3177c00a8..dff7f6f4d 100644 --- a/pkg/cluster/info.go +++ b/pkg/cluster/info.go @@ -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{}) diff --git a/pkg/diagnose/connections.go b/pkg/diagnose/connections.go index 707ef8d88..0fdae106d 100644 --- a/pkg/diagnose/connections.go +++ b/pkg/diagnose/connections.go @@ -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() @@ -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)) } } } @@ -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