Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 0.12: Print out brokers information on subctl show all #1924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
printVersions(versions)
status.EndWith(cli.Success)

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

return true
}

Expand Down