checkpoint rbac
parent
d2da8b177f
commit
0a6caa2d54
|
|
@ -17,6 +17,11 @@ builds:
|
||||||
goarch:
|
goarch:
|
||||||
- 386
|
- 386
|
||||||
- amd64
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
goarm:
|
||||||
|
- 6
|
||||||
|
- 7
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X github.com/derailed/k9s/cmd.version={{.Version}} -X github.com/derailed/k9s/cmd.commit={{.Commit}} -X github.com/derailed/k9s/cmd.date={{.Date}}
|
- -s -w -X github.com/derailed/k9s/cmd.version={{.Version}} -X github.com/derailed/k9s/cmd.commit={{.Commit}} -X github.com/derailed/k9s/cmd.date={{.Date}}
|
||||||
|
|
||||||
|
|
@ -25,6 +30,8 @@ archive:
|
||||||
darwin: Darwin
|
darwin: Darwin
|
||||||
linux: Linux
|
linux: Linux
|
||||||
windows: Windows
|
windows: Windows
|
||||||
|
arm: 32-bit
|
||||||
|
arm64: 64-bit
|
||||||
386: i386
|
386: i386
|
||||||
amd64: x86_64
|
amd64: x86_64
|
||||||
checksum:
|
checksum:
|
||||||
|
|
@ -52,3 +59,36 @@ brew:
|
||||||
description: Kubernetes CLI To Manage Your Clusters In Style!
|
description: Kubernetes CLI To Manage Your Clusters In Style!
|
||||||
test: |
|
test: |
|
||||||
system "k9s version"
|
system "k9s version"
|
||||||
|
|
||||||
|
# Snap
|
||||||
|
snapcraft:
|
||||||
|
name: k9s
|
||||||
|
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||||
|
|
||||||
|
replacements:
|
||||||
|
amd64: 64-bit
|
||||||
|
386: 32-bit
|
||||||
|
darwin: macOS
|
||||||
|
linux: Tux
|
||||||
|
|
||||||
|
publish: false
|
||||||
|
|
||||||
|
summary: K9s is a CLI to view and manage your Kubernetes clusters.
|
||||||
|
description: |
|
||||||
|
K9s is a CLI to view and manage your Kubernetes clusters.
|
||||||
|
By leveraging a terminal UI, you can easily traverse Kubernetes resources
|
||||||
|
and view the state of you clusters in a single powerful session.
|
||||||
|
|
||||||
|
grade: devel
|
||||||
|
confinement: devmode
|
||||||
|
|
||||||
|
apps:
|
||||||
|
k9s:
|
||||||
|
plugs: ["home", "network", "home-dir"]
|
||||||
|
|
||||||
|
plugs:
|
||||||
|
home-dir:
|
||||||
|
read:
|
||||||
|
- $HOME/.k9s
|
||||||
|
write:
|
||||||
|
- $HOME/.k9s
|
||||||
|
|
|
||||||
13
cmd/info.go
13
cmd/info.go
|
|
@ -21,13 +21,16 @@ func infoCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func printInfo() {
|
func printInfo() {
|
||||||
|
const secFmt = "%-15s "
|
||||||
|
|
||||||
|
printLogo()
|
||||||
|
printTuple(secFmt, "Configuration", config.K9sConfigFile)
|
||||||
|
printTuple(secFmt, "Logs", config.K9sLogs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printLogo() {
|
||||||
for _, l := range views.LogoSmall {
|
for _, l := range views.LogoSmall {
|
||||||
fmt.Println(printer.Colorize(l, printer.ColorCyan))
|
fmt.Println(printer.Colorize(l, printer.ColorCyan))
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Printf(printer.Colorize(fmt.Sprintf("%-15s", "Configuration:"), printer.ColorCyan))
|
|
||||||
fmt.Println(printer.Colorize(config.K9sConfigFile, printer.ColorWhite))
|
|
||||||
|
|
||||||
fmt.Printf(printer.Colorize(fmt.Sprintf("%-15s", "Logs:"), printer.ColorCyan))
|
|
||||||
fmt.Println(printer.Colorize(config.K9sLogs, printer.ColorWhite))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,21 @@ func versionCmd() *cobra.Command {
|
||||||
Short: "Print version info",
|
Short: "Print version info",
|
||||||
Long: "Prints version info",
|
Long: "Prints version info",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
const secFmt = "%-10s"
|
printVersion()
|
||||||
fmt.Printf(printer.Colorize(fmt.Sprintf(secFmt, "Version:"), printer.ColorMagenta))
|
|
||||||
fmt.Println(printer.Colorize(version, printer.ColorDarkGray))
|
|
||||||
fmt.Printf(printer.Colorize(fmt.Sprintf(secFmt, "Commit:"), printer.ColorMagenta))
|
|
||||||
fmt.Println(printer.Colorize(commit, printer.ColorDarkGray))
|
|
||||||
fmt.Printf(printer.Colorize(fmt.Sprintf(secFmt, "Date:"), printer.ColorMagenta))
|
|
||||||
fmt.Println(printer.Colorize(date, printer.ColorDarkGray))
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printVersion() {
|
||||||
|
const secFmt = "%-10s "
|
||||||
|
|
||||||
|
printLogo()
|
||||||
|
printTuple(secFmt, "Version", version)
|
||||||
|
printTuple(secFmt, "Commit", commit)
|
||||||
|
printTuple(secFmt, "Date", date)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printTuple(format, section, value string) {
|
||||||
|
fmt.Printf(printer.Colorize(fmt.Sprintf(format, section+":"), printer.ColorCyan))
|
||||||
|
fmt.Println(printer.Colorize(value, printer.ColorWhite))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
// rbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFu(c Connection, kind, name string) error {
|
||||||
|
defer func(t time.Time) {
|
||||||
|
log.Info().Msgf("Elapsed %v", time.Since(t))
|
||||||
|
}(time.Now())
|
||||||
|
|
||||||
|
crbs, err := c.DialOrDie().RbacV1().ClusterRoleBindings().List(metav1.ListOptions{
|
||||||
|
FieldSelector: "metadata.name=cluster-admin",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().Msgf("Len %d", len(crbs.Items))
|
||||||
|
|
||||||
|
var crs []string
|
||||||
|
for _, crb := range crbs.Items {
|
||||||
|
log.Info().Msgf("> CRB %s", crb.Name)
|
||||||
|
for _, s := range crb.Subjects {
|
||||||
|
// log.Info().Msgf(" Sub %s %s", s.Kind, s.Name)
|
||||||
|
if s.Kind == kind && s.Name == name {
|
||||||
|
crs = append(crs, crb.RoleRef.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Find cluster roles %#v\n", crs)
|
||||||
|
|
||||||
|
// Each role has multiple rules
|
||||||
|
for _, r := range crs {
|
||||||
|
cr, err := c.DialOrDie().RbacV1().ClusterRoles().Get(r, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msgf("Unable to find cluster role %s ", r)
|
||||||
|
}
|
||||||
|
for _, rule := range cr.Rules {
|
||||||
|
log.Info().Msgf("Found rule %#v", rule.APIGroups)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRBACFu(t *testing.T) {
|
||||||
|
con := dial()
|
||||||
|
assert.Nil(t, GetFu(con, "Group", "system:masters"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func dial() *APIClient {
|
||||||
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||||
|
|
||||||
|
// c, u := "gke_k9s", "gke_k9s_user"
|
||||||
|
c, u := "minikube", "minikube"
|
||||||
|
|
||||||
|
flags := genericclioptions.ConfigFlags{
|
||||||
|
ClusterName: &c,
|
||||||
|
AuthInfoName: &u,
|
||||||
|
}
|
||||||
|
cfg := NewConfig(&flags)
|
||||||
|
return InitConnectionOrDie(cfg, log.Logger)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue