Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kubectl-plus/kcf into add-oidc-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
naemono committed Feb 14, 2020
2 parents 8af107d + a1823c4 commit c174b48
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -15,3 +15,7 @@ jobs:
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@v0.0.36
with:
krew_template_file: deploy/krew/fleet.yaml
4 changes: 2 additions & 2 deletions .goreleaser.yml
@@ -1,7 +1,7 @@
project_name: fleet
release:
github:
owner: mhausenblas
owner: kubectl-plus
name: kcf
builds:
- id: fleet
Expand All @@ -19,7 +19,7 @@ builds:
- GO111MODULE=on
main: cmd/fleet/main.go
ldflags: -s -w
-X github.com/mhausenblas/kcf/pkg/version.version=
-X github.com/kubectl-plus/kcf/pkg/version.version=
archives:
- id: fleet
builds:
Expand Down
12 changes: 8 additions & 4 deletions README.md
Expand Up @@ -8,9 +8,13 @@ Meet `fleet`, a simple CLI tool that provides you with the status and configurat

```sh
$ kubectl fleet
CLUSTER VERSION NODES NAMESPACES API
mngbase.us-west-2.eksctl.io v1.14.8-eks-41be3d 2 5 https://123456789ABCDEF.gr7.us-west-2.eks.amazonaws.com
kind-mh9local v1.16.3 1 4 https://127.0.0.1:58836
CLUSTER VERSION NODES NAMESPACES PROVIDER API
kind-kind-3 v1.16.3 1/1 4 kind https://127.0.0.1:32769
test-cluster-2 v1.16.2 1/1 4 minikube https://192.168.64.4:8443
kind-test2 v1.16.3 1/1 4 kind https://127.0.0.1:32768
minikube v1.16.2 1/1 4 minikube https://192.168.64.3:8443
gke_krew-release-bot-260708_us-central1-a_standard-cluster-1 v1.15.8-gke.3 3/3 4 GKE https://104.197.42.183
do-sfo2-k8s-1-16-6-do-0-sfo2-1581265844177 v1.16.6 3/3 4 Digital Ocean https://f048f314-4f77-47c2-9264-764da91d35e0.k8s.ondigitalocean.com
```

Above, you see `fleet` used as a `kubectl` plugin, available via [krew](http://krew.dev/).
Expand All @@ -21,7 +25,7 @@ the control plane version or API server endpoint are displayed, as well as selec
stats, for example, the number of worker nodes or namespaces found in the cluster.

Note that you can also use it standalone, simply download the binary for your platform
from the [release page](https://github.com/mhausenblas/kcf/releases).
from the [release page](https://github.com/kubectl-plus/kcf/releases).

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet/cli/details.go
@@ -1,7 +1,7 @@
package cli

import (
"github.com/mhausenblas/kcf/pkg/fleet"
"github.com/kubectl-plus/kcf/pkg/fleet"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet/cli/resources.go
@@ -1,7 +1,7 @@
package cli

import (
"github.com/mhausenblas/kcf/pkg/fleet"
"github.com/kubectl-plus/kcf/pkg/fleet"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet/cli/root.go
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"github.com/mhausenblas/kcf/pkg/fleet"
"github.com/kubectl-plus/kcf/pkg/fleet"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet/main.go
@@ -1,7 +1,7 @@
package main

import (
"github.com/mhausenblas/kcf/cmd/fleet/cli"
"github.com/kubectl-plus/kcf/cmd/fleet/cli"
_ "k8s.io/client-go/plugin/pkg/client/auth" // required for GKE/OIDC/Dex style auth
)

Expand Down
39 changes: 6 additions & 33 deletions deploy/krew/fleet.yaml
Expand Up @@ -3,38 +3,13 @@ kind: Plugin
metadata:
name: fleet
spec:
version: "v0.1.4"
version: {{ .TagName }}
platforms:
- selector:
matchLabels:
os: linux
arch: amd64
uri: https://github.com/mhausenblas/kcf/releases/download/v0.1.4/fleet_linux_amd64.tar.gz
sha256: "56f0536804bc5230cb0a4e4c87861c27828fee1b71aab1b192fa54c75e090db1"
files:
- from: "./fleet"
to: "."
- from: "./LICENSE"
to: "."
bin: "fleet"
- selector:
matchLabels:
os: linux
arch: arm64
uri: https://github.com/mhausenblas/kcf/releases/download/v0.1.4/fleet_linux_arm64.tar.gz
sha256: "a041edf6caee7b20fa25c6a0a366620a5178484173aa01d8281bef608a82653a"
files:
- from: "./fleet"
to: "."
- from: "./LICENSE"
to: "."
bin: "fleet"
- selector:
matchLabels:
os: linux
arch: arm
uri: https://github.com/mhausenblas/kcf/releases/download/v0.1.4/fleet_linux_arm.tar.gz
sha256: "b77ddaeaf27435b1cf41e909d33dbe5574640572219e4aec5ccbc769c4f83d2b"
{{addURIAndSha "https://github.com/kubectl-plus/kcf/releases/download/{{ .TagName }}/fleet_linux_amd64.tar.gz" .TagName }}
files:
- from: "./fleet"
to: "."
Expand All @@ -45,8 +20,7 @@ spec:
matchLabels:
os: darwin
arch: amd64
uri: https://github.com/mhausenblas/kcf/releases/download/v0.1.4/fleet_darwin_amd64.tar.gz
sha256: "867f1c40b90334f4416062efb4651dca037defc31a0881575c0c408486487d6f"
{{addURIAndSha "https://github.com/kubectl-plus/kcf/releases/download/{{ .TagName }}/fleet_darwin_amd64.tar.gz" .TagName }}
files:
- from: "./fleet"
to: "."
Expand All @@ -57,23 +31,22 @@ spec:
matchLabels:
os: windows
arch: amd64
uri: https://github.com/mhausenblas/kcf/releases/download/v0.1.4/fleet_windows_amd64.zip
sha256: "33e29a5f65ba8ec16008fd51a9b62d8f9f0d25a066ea700d5cffaf0fa4757f1a"
{{addURIAndSha "https://github.com/kubectl-plus/kcf/releases/download/{{ .TagName }}/fleet_windows_amd64.zip" .TagName }}
files:
- from: "/fleet.exe"
to: "."
- from: "./LICENSE"
to: "."
bin: "fleet.exe"
shortDescription: Shows config and resources of a fleet of clusters
homepage: https://github.com/mhausenblas/kcf
homepage: https://github.com/kubectl-plus/kcf
caveats: |
Usage:
$ kubectl fleet
For additional options:
$ kubectl fleet --help
or https://github.com/mhausenblas/kcf/blob/v0.1.4/doc/USAGE.md
or https://github.com/kubectl-plus/kcf/blob/v0.1.4/doc/USAGE.md
description: |
Allows to get an overview and details on a fleet of Kubernetes clusters.
Expand Down
18 changes: 7 additions & 11 deletions doc/USAGE.md
Expand Up @@ -9,14 +9,6 @@ In order to be able to do that, make sure you have [krew installed](https://gith
$ kubectl krew install fleet
```

Alternatively, for a version that is not yet updated and hence available in the [krew index](https://index.krew.dev/), you can install `fleet` from this repo as follows:

```sh
$ git clone https://github.com/mhausenblas/kcf.git && cd kcf

$ kubectl krew install --manifest=deploy/krew/fleet.yaml
```

If the installation fails, check if `krew` is available on your local system
and also, make sure you're using the most recent index (run `kubectl krew update`) to ensure this.

Expand All @@ -35,9 +27,13 @@ To get an overview of your entire fleet, do:

```sh
$ kubectl fleet
CLUSTER VERSION NODES NAMESPACES API
mngbase.us-west-2.eksctl.io v1.14.8-eks-41be3d 2 5 https://123456789ABCDEF.gr7.us-west-2.eks.amazonaws.com
kind-mh9local v1.16.3 1 4 https://127.0.0.1:58836
CLUSTER VERSION NODES NAMESPACES PROVIDER API
kind-kind-3 v1.16.3 1/1 4 kind https://127.0.0.1:32769
test-cluster-2 v1.16.2 1/1 4 minikube https://192.168.64.4:8443
kind-test2 v1.16.3 1/1 4 kind https://127.0.0.1:32768
minikube v1.16.2 1/1 4 minikube https://192.168.64.3:8443
gke_krew-release-bot-260708_us-central1-a_standard-cluster-1 v1.15.8-gke.3 3/3 4 GKE https://104.197.42.183
do-sfo2-k8s-1-16-6-do-0-sfo2-1581265844177 v1.16.6 3/3 4 Digital Ocean https://f048f314-4f77-47c2-9264-764da91d35e0.k8s.ondigitalocean.com
```

### Exploring clusters in the fleet
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,4 +1,4 @@
module github.com/mhausenblas/kcf
module github.com/kubectl-plus/kcf

go 1.12

Expand Down
4 changes: 4 additions & 0 deletions pkg/fleet/details.go
Expand Up @@ -23,6 +23,10 @@ func Details(configFlags *genericclioptions.ConfigFlags, args []string) error {
}
clusterID := args[0]
cluster := cfg.Clusters[clusterID]
if cluster == nil {
return errors.New(fmt.Sprintf("cluster %q not found in kubeconfig", clusterID))
}

fmt.Printf("API server endpoint: %v\n", cluster.Server)
context := contextOf(cfg, clusterID)
coreres, err := coreResDetails(cfg, context)
Expand Down
51 changes: 49 additions & 2 deletions pkg/fleet/overview.go
Expand Up @@ -3,6 +3,7 @@ package fleet
import (
"fmt"
"os"
"strings"
"text/tabwriter"

"github.com/pkg/errors"
Expand All @@ -21,7 +22,7 @@ func Overview(configFlags *genericclioptions.ConfigFlags) error {
return errors.Wrap(err, "Can't assemble raw config")
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
fmt.Fprintln(w, "CLUSTER\tVERSION\tNODES\tNAMESPACES\tAPI")
fmt.Fprintln(w, "CLUSTER\tVERSION\tNODES\tNAMESPACES\tPROVIDER\tAPI")
for name, context := range cfg.Contexts {
cluster := cfg.Clusters[context.Cluster]
clusterVersion, err := clusterVersion(cfg, name)
Expand All @@ -40,7 +41,9 @@ func Overview(configFlags *genericclioptions.ConfigFlags) error {
if cluster != nil {
apiServerEndpoint = cluster.Server
}
fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%v\t%v\t%v", context.Cluster, clusterVersion, noinfo, nsinfo, apiServerEndpoint))
provider := getProvider(cfg, name)

fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v", context.Cluster, clusterVersion, noinfo, nsinfo, provider, apiServerEndpoint))
}
w.Flush()
return nil
Expand Down Expand Up @@ -98,3 +101,47 @@ func nsOverview(cfg api.Config, context string) (string, error) {
nsverview := fmt.Sprintf("%v", len(ns.Items))
return nsverview, nil
}

func getProvider(cfg api.Config, contextName string) string {
context := cfg.Contexts[contextName]
if context == nil {
return "?"
}

apiServerEndpoint := cfg.Clusters[context.Cluster].Server
switch {
case strings.HasPrefix(contextName, "kind-"):
return "kind"
case strings.HasPrefix(contextName, "gke"):
return "GKE"
case strings.Contains(apiServerEndpoint, "amazon"):
return "AWS"
case strings.Contains(apiServerEndpoint, "ondigitalocean"):
return "Digital Ocean"
case strings.Contains(apiServerEndpoint, "azmk8s.io"):
return "Microsoft AKS"
default:
provider, err := getProviderFromNodeMetadata(cfg, contextName)
if err != nil {
return "?"
}

return provider
}
}

func getProviderFromNodeMetadata(cfg api.Config, context string) (string, error) {
cs, err := csForContext(cfg, context)
if err != nil {
return "", errors.Wrap(err, "Can't create a clientset based on config provided")
}

nodes, err := cs.CoreV1().Nodes().List(metav1.ListOptions{})
for _, node := range nodes.Items {
if strings.Contains(node.Labels["kubernetes.io/hostname"], "minikube") {
return "minikube", nil
}
}

return "", fmt.Errorf("failed to identify provider from node metadata")
}

0 comments on commit c174b48

Please sign in to comment.