Skip to content

Commit

Permalink
Print out brokers information on subctl show all
Browse files Browse the repository at this point in the history
Print out the info, even if clusters only have brokers.
Clusters that don't have brokers will just show informatory "Detecting
brokers" message and nothing further.

Resolves: #1894

Signed-off-by: Mike Kolesnik <[email protected]>
  • Loading branch information
mkolesnik authored and skitt committed Mar 8, 2022
1 parent e644897 commit 56dbe51
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/subctl/cmd/show/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ func init() {
func showAll(cluster *cmd.Cluster) bool {
status := cli.NewStatus()

success := showBrokers(cluster)

fmt.Println()

if cluster.Submariner == nil {
success = getVersions(cluster) && success

fmt.Println()
status.Start(cmd.SubmMissingMessage)
status.EndWith(cli.Warning)

return true
return success
}

success := showConnections(cluster)
success = showConnections(cluster) && success

fmt.Println()

Expand Down
71 changes: 71 additions & 0 deletions pkg/subctl/cmd/show/brokers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
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 show

import (
"context"
"fmt"
"strings"

"github.com/submariner-io/submariner-operator/internal/cli"
"github.com/submariner-io/submariner-operator/pkg/client"
"github.com/submariner-io/submariner-operator/pkg/subctl/cmd"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func showBrokers(cluster *cmd.Cluster) bool {
template := "%-25.24s%-25.24s%-40.39s\n"
status := cli.NewStatus()

status.Start("Detecting broker(s)")

clientProducer, err := client.NewProducerFromRestConfig(cluster.Config)
if err != nil {
status.EndWithFailure("Error creating client producer")
return false
}

brokerList, err := clientProducer.ForOperator().SubmarinerV1alpha1().Brokers(corev1.NamespaceAll).List(
context.TODO(), metav1.ListOptions{})
if err != nil && !apierrors.IsNotFound(err) {
status.EndWithFailure(err.Error())
return false
}

status.End()

brokers := brokerList.Items
if len(brokers) == 0 {
return true
}

fmt.Printf(template, "NAMESPACE", "NAME", "COMPONENTS")

for i := range brokers {
fmt.Printf(
template,
brokers[i].Namespace,
brokers[i].Name,
strings.Join(brokers[i].Spec.Components, ", "),
)
}

return true
}
12 changes: 11 additions & 1 deletion pkg/subctl/cmd/show/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func getSubmarinerVersion(submariner *v1alpha1.Submariner, versions []versionIma
func getOperatorVersion(clientSet kubernetes.Interface, versions []versionImageInfo) ([]versionImageInfo, error) {
operatorConfig, err := clientSet.AppsV1().Deployments(cmd.OperatorNamespace).Get(context.TODO(), names.OperatorComponent, v1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return versions, nil
}

return nil, errors.Wrap(err, "error retrieving Deployment")
}

Expand Down Expand Up @@ -105,7 +109,9 @@ func getVersions(cluster *cmd.Cluster) bool {
submarinerClient, err := submarinerclientset.NewForConfig(cluster.Config)
exit.OnErrorWithMessage(err, "Unable to get the Submariner client")

versions = getSubmarinerVersion(cluster.Submariner, versions)
if cluster.Submariner != nil {
versions = getSubmarinerVersion(cluster.Submariner, versions)
}

versions, err = getOperatorVersion(cluster.KubeClient, versions)
exit.OnErrorWithMessage(err, "Unable to get the Operator version")
Expand All @@ -116,6 +122,10 @@ func getVersions(cluster *cmd.Cluster) bool {
status.EndWith(cli.Success)
printVersions(versions)

if len(versions) > 0 {
printVersions(versions)
}

return true
}

Expand Down

0 comments on commit 56dbe51

Please sign in to comment.