Skip to content

Commit

Permalink
Add Broker to clusterInfo
Browse files Browse the repository at this point in the history
Since there are multiple places where a broker installation check on a
cluster is needed in multiple places (show brokers, uninstall and
recover-brokerinfo (soon)), add broker field as part of the clusterinfo
and a function that checks if the cluster has Broker installed.

This simplies code at multiple places.

Depends on:
submariner-io/submariner-operator#2432

Signed-off-by: Janki Chhatbar <[email protected]>
  • Loading branch information
Jaanki committed Jan 10, 2023
1 parent 3a926e6 commit 58ffa3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 3 additions & 11 deletions internal/show/brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,22 @@ limitations under the License.
package show

import (
"context"

"github.com/submariner-io/admiral/pkg/reporter"
"github.com/submariner-io/subctl/internal/show/table"
"github.com/submariner-io/subctl/pkg/cluster"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Brokers(clusterInfo *cluster.Info, _ string, status reporter.Interface) error {
status.Start("Detecting broker(s)")

brokerList := &v1alpha1.BrokerList{}
err := clusterInfo.ClientProducer.ForGeneral().List(context.TODO(), brokerList, client.InNamespace(metav1.NamespaceAll))

if err != nil && !apierrors.IsNotFound(err) {
return status.Error(err, "Error retrieving brokers")
brokers, err := clusterInfo.GetBrokers(metav1.NamespaceAll)
if err != nil {
return status.Error(err, "error retrieving broker")
}

status.End()

brokers := brokerList.Items
if len(brokers) == 0 {
status.Success("No brokers found")
return nil
Expand Down
11 changes: 11 additions & 0 deletions pkg/cluster/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,14 @@ func (c *Info) OperatorNamespace() string {

return constants.OperatorNamespace
}

func (c *Info) GetBrokers(namespace string) ([]v1alpha1.Broker, error) {
brokers := &v1alpha1.BrokerList{}
err := c.ClientProducer.ForGeneral().List(context.TODO(), brokers, controllerClient.InNamespace(namespace))

if err != nil && !apierrors.IsNotFound(err) && !meta.IsNoMatchError(err) {
return nil, errors.Wrapf(err, "error retrieving Broker in namespace %s", namespace)
}

return brokers.Items, nil
}

0 comments on commit 58ffa3b

Please sign in to comment.