Skip to content

Commit

Permalink
resources amount function created
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Oct 31, 2023
1 parent 436e21f commit ad47757
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (pr *PrintRunner) PrintGatewaysAndHTTPRoutes(cmd *cobra.Command, _ []string
}

func (pr *PrintRunner) outputResult(resources i2gw.GatewayResources) {
if len(resources.Gateways)+len(resources.HTTPRoutes)+len(resources.TCPRoutes) == 0 {
if resources.ResourcesAmount() == 0 {
msg := "No resources found"
if pr.namespaceFilter != "" {
msg = fmt.Sprintf("%s in %s namespace", msg, pr.namespaceFilter)
Expand Down
11 changes: 11 additions & 0 deletions pkg/i2gw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ type GatewayResources struct {
ReferenceGrants map[types.NamespacedName]gatewayv1alpha2.ReferenceGrant
}

// ResourcesAmount returns the total amount of Gateway API resources to display.
func (r GatewayResources) ResourcesAmount() int {
return len(r.Gateways) +
len(r.GatewayClasses) +
len(r.HTTPRoutes) +
len(r.TLSRoutes) +
len(r.TCPRoutes) +
len(r.UDPRoutes)

}

// FeatureParser is a function that reads the InputResources, and applies
// the appropriate modifications to the GatewayResources.
//
Expand Down

0 comments on commit ad47757

Please sign in to comment.