Skip to content

Commit

Permalink
add -A flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed May 5, 2022
1 parent 8249a35 commit 51e8598
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type Cluster struct {
}

// Clusters gets cluster configurations from kubeconfigs and from within a
// cluster if running inside one.
func Clusters(kubeconfigs []string) ([]Cluster, error) {
// cluster if running inside one. It sets cluster.namespace to empty string
// (which means all namespaces) if allNamespaces is true.
func Clusters(kubeconfigs []string, allNamespaces bool) ([]Cluster, error) {
var clusters []Cluster

for _, kc := range kubeconfigs {
Expand All @@ -34,6 +35,12 @@ func Clusters(kubeconfigs []string) ([]Cluster, error) {
clusters = append(clusters, c)
}

if allNamespaces {
for i := range clusters {
clusters[i].namespace = ""
}
}

return clusters, nil
}

Expand Down
2 changes: 2 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

type Flags struct {
allNamespaces bool
age bool
daemon bool
kind kinds
Expand All @@ -30,6 +31,7 @@ func (k *kinds) Set(value string) error {
func parseFlags() Flags {
var f Flags

flag.BoolVar(&f.allNamespaces, "A", false, "count objects across all namespaces")
flag.BoolVar(&f.age, "a", false, "show also age of newest and oldest object")
flag.BoolVar(&f.daemon, "d", false, "run as daemon exposing prometheus metrics")
flag.Var(&f.kind, "k", "object kind or kinds (default pod)")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
log.SetPrefix(os.Args[0] + ": ")
}

clusters, err := Clusters(flag.Args())
clusters, err := Clusters(flag.Args(), flags.allNamespaces)
if err != nil {
log.Fatalf("getting cluster configs: %v", err)
}
Expand Down

0 comments on commit 51e8598

Please sign in to comment.