update build dependencies

mine
derailed 2021-09-23 13:41:44 -06:00
parent e5759218e6
commit 019121c04e
9 changed files with 405 additions and 687 deletions

65
go.mod
View File

@ -15,7 +15,6 @@ require (
github.com/cenkalti/backoff/v4 v4.1.1
github.com/derailed/popeye v0.9.7
github.com/derailed/tview v0.6.1
github.com/drone/envsubst v1.0.3 // indirect
github.com/fatih/color v1.12.0
github.com/fsnotify/fsnotify v1.4.9
github.com/fvbommel/sortorder v1.0.2
@ -23,13 +22,13 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.13
github.com/openfaas/faas v0.0.0-20200207215241-6afae214e3ec
github.com/openfaas/faas-cli v0.0.0-20200124160744-30b7cec9634c
github.com/openfaas/faas-provider v0.15.0
// BOZO!! revamp with latest...
// github.com/openfaas/faas v0.0.0-20200207215241-6afae214e3ec
// github.com/openfaas/faas-cli v0.0.0-20200124160744-30b7cec9634c
// github.com/openfaas/faas-provider v0.15.0
github.com/petergtz/pegomock v2.9.0+incompatible
github.com/rakyll/hey v0.1.4
github.com/rs/zerolog v1.23.0
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sahilm/fuzzy v0.1.0
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
@ -48,12 +47,12 @@ require (
require (
cloud.google.com/go v0.81.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.12 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
@ -82,66 +81,64 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/gorilla/mux v1.7.3 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/copystructure v1.1.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/onsi/gomega v1.10.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.10.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.18.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rubenv/sql-migrate v0.0.0-20200616145509-8d140a17f351 // indirect
@ -157,12 +154,12 @@ require (
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
@ -172,10 +169,10 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.21.0 // indirect
k8s.io/apiserver v0.21.2 // indirect
k8s.io/component-base v0.21.3 // indirect
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/kustomize/api v0.8.8 // indirect
sigs.k8s.io/kustomize/kyaml v0.10.17 // indirect
k8s.io/component-base v0.22.0 // indirect
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 // indirect
sigs.k8s.io/kustomize/api v0.8.11 // indirect
sigs.k8s.io/kustomize/kyaml v0.11.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
)

296
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,216 +1,218 @@
package dao
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"path"
"strings"
"time"
// BOZO!! Revamp with latest
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/render"
"github.com/openfaas/faas-cli/proxy"
"github.com/openfaas/faas/gateway/requests"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/yaml"
)
// import (
// "bytes"
// "context"
// "encoding/json"
// "errors"
// "fmt"
// "io/ioutil"
// "net/http"
// "net/url"
// "os"
// "path"
// "strings"
// "time"
const (
oFaasGatewayEnv = "OPENFAAS_GATEWAY"
oFaasJWTTokenEnv = "OPENFAAS_JWT_TOKEN"
oFaasTLSInsecure = "OPENFAAS_TLS_INSECURE"
)
// "github.com/derailed/k9s/internal/client"
// "github.com/derailed/k9s/internal/render"
// "github.com/openfaas/faas-cli/proxy"
// "github.com/openfaas/faas/gateway/requests"
// "github.com/rs/zerolog/log"
// "k8s.io/apimachinery/pkg/runtime"
// "sigs.k8s.io/yaml"
// )
var (
_ Accessor = (*OpenFaas)(nil)
_ Nuker = (*OpenFaas)(nil)
_ Describer = (*OpenFaas)(nil)
)
// const (
// oFaasGatewayEnv = "OPENFAAS_GATEWAY"
// oFaasJWTTokenEnv = "OPENFAAS_JWT_TOKEN"
// oFaasTLSInsecure = "OPENFAAS_TLS_INSECURE"
// )
// OpenFaas represents a faas gateway connection.
type OpenFaas struct {
NonResource
}
// var (
// _ Accessor = (*OpenFaas)(nil)
// _ Nuker = (*OpenFaas)(nil)
// _ Describer = (*OpenFaas)(nil)
// )
// IsOpenFaasEnabled returns true if a gateway url is set in the environment.
func IsOpenFaasEnabled() bool {
return os.Getenv(oFaasGatewayEnv) != ""
}
// // OpenFaas represents a faas gateway connection.
// type OpenFaas struct {
// NonResource
// }
func getOpenFAASFlags() (string, string, bool) {
gw, token := os.Getenv(oFaasGatewayEnv), os.Getenv(oFaasJWTTokenEnv)
tlsInsecure := false
if os.Getenv(oFaasTLSInsecure) == "true" {
tlsInsecure = true
}
// // IsOpenFaasEnabled returns true if a gateway url is set in the environment.
// func IsOpenFaasEnabled() bool {
// return os.Getenv(oFaasGatewayEnv) != ""
// }
return gw, token, tlsInsecure
}
// func getOpenFAASFlags() (string, string, bool) {
// gw, token := os.Getenv(oFaasGatewayEnv), os.Getenv(oFaasJWTTokenEnv)
// tlsInsecure := false
// if os.Getenv(oFaasTLSInsecure) == "true" {
// tlsInsecure = true
// }
// Get returns a function by name.
func (f *OpenFaas) Get(ctx context.Context, path string) (runtime.Object, error) {
ns, n := client.Namespaced(path)
// return gw, token, tlsInsecure
// }
oo, err := f.List(ctx, ns)
if err != nil {
return nil, err
}
// // Get returns a function by name.
// func (f *OpenFaas) Get(ctx context.Context, path string) (runtime.Object, error) {
// ns, n := client.Namespaced(path)
var found runtime.Object
for _, o := range oo {
r, ok := o.(render.OpenFaasRes)
if !ok {
continue
}
if r.Function.Name == n {
found = o
break
}
}
// oo, err := f.List(ctx, ns)
// if err != nil {
// return nil, err
// }
if found == nil {
return nil, fmt.Errorf("unable to locate function %q", path)
}
// var found runtime.Object
// for _, o := range oo {
// r, ok := o.(render.OpenFaasRes)
// if !ok {
// continue
// }
// if r.Function.Name == n {
// found = o
// break
// }
// }
return found, nil
}
// if found == nil {
// return nil, fmt.Errorf("unable to locate function %q", path)
// }
// List returns a collection of functions.
func (f *OpenFaas) List(_ context.Context, ns string) ([]runtime.Object, error) {
if !IsOpenFaasEnabled() {
return nil, errors.New("OpenFAAS is not enabled on this cluster")
}
// return found, nil
// }
gw, token, tls := getOpenFAASFlags()
ff, err := proxy.ListFunctionsToken(gw, tls, token, ns)
if err != nil {
return nil, err
}
// // List returns a collection of functions.
// func (f *OpenFaas) List(_ context.Context, ns string) ([]runtime.Object, error) {
// if !IsOpenFaasEnabled() {
// return nil, errors.New("OpenFAAS is not enabled on this cluster")
// }
oo := make([]runtime.Object, 0, len(ff))
for _, f := range ff {
oo = append(oo, render.OpenFaasRes{Function: f})
}
// gw, token, tls := getOpenFAASFlags()
// ff, err := proxy.ListFunctionsToken(gw, tls, token, ns)
// if err != nil {
// return nil, err
// }
return oo, nil
}
// oo := make([]runtime.Object, 0, len(ff))
// for _, f := range ff {
// oo = append(oo, render.OpenFaasRes{Function: f})
// }
// Delete removes a function.
func (f *OpenFaas) Delete(path string, _, _ bool) error {
gw, token, tls := getOpenFAASFlags()
ns, n := client.Namespaced(path)
// return oo, nil
// }
// BOZO!! openfaas spews to stdout. Not good for us...
return deleteFunctionToken(gw, n, tls, token, ns)
}
// // Delete removes a function.
// func (f *OpenFaas) Delete(path string, _, _ bool) error {
// gw, token, tls := getOpenFAASFlags()
// ns, n := client.Namespaced(path)
// ToYAML dumps a function to yaml.
func (f *OpenFaas) ToYAML(path string, _ bool) (string, error) {
return f.Describe(path)
}
// // BOZO!! openfaas spews to stdout. Not good for us...
// return deleteFunctionToken(gw, n, tls, token, ns)
// }
// Describe describes a function.
func (f *OpenFaas) Describe(path string) (string, error) {
o, err := f.Get(context.Background(), path)
if err != nil {
return "", err
}
// // ToYAML dumps a function to yaml.
// func (f *OpenFaas) ToYAML(path string, _ bool) (string, error) {
// return f.Describe(path)
// }
fn, ok := o.(render.OpenFaasRes)
if !ok {
return "", fmt.Errorf("expecting OpenFaasRes but got %T", o)
}
// // Describe describes a function.
// func (f *OpenFaas) Describe(path string) (string, error) {
// o, err := f.Get(context.Background(), path)
// if err != nil {
// return "", err
// }
raw, err := json.Marshal(fn)
if err != nil {
return "", err
}
// fn, ok := o.(render.OpenFaasRes)
// if !ok {
// return "", fmt.Errorf("expecting OpenFaasRes but got %T", o)
// }
bytes, err := yaml.JSONToYAML(raw)
if err != nil {
return "", err
}
// raw, err := json.Marshal(fn)
// if err != nil {
// return "", err
// }
return string(bytes), nil
}
// bytes, err := yaml.JSONToYAML(raw)
// if err != nil {
// return "", err
// }
// BOZO!! Meow! openfaas fn prints to stdout have to dup ;(.
func deleteFunctionToken(gateway string, functionName string, tlsInsecure bool, token string, namespace string) error {
defaultCommandTimeout := 60 * time.Second
// return string(bytes), nil
// }
gateway = strings.TrimRight(gateway, "/")
delReq := requests.DeleteFunctionRequest{FunctionName: functionName}
reqBytes, _ := json.Marshal(&delReq)
reader := bytes.NewReader(reqBytes)
// // BOZO!! Meow! openfaas fn prints to stdout have to dup ;(.
// func deleteFunctionToken(gateway string, functionName string, tlsInsecure bool, token string, namespace string) error {
// defaultCommandTimeout := 60 * time.Second
c := proxy.MakeHTTPClient(&defaultCommandTimeout, tlsInsecure)
// gateway = strings.TrimRight(gateway, "/")
// delReq := requests.DeleteFunctionRequest{FunctionName: functionName}
// reqBytes, _ := json.Marshal(&delReq)
// reader := bytes.NewReader(reqBytes)
deleteEndpoint, err := createSystemEndpoint(gateway, namespace)
if err != nil {
return err
}
// c := proxy.MakeHTTPClient(&defaultCommandTimeout, tlsInsecure)
req, err := http.NewRequestWithContext(context.Background(), "DELETE", deleteEndpoint, reader)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
// deleteEndpoint, err := createSystemEndpoint(gateway, namespace)
// if err != nil {
// return err
// }
if len(token) > 0 {
proxy.SetToken(req, token)
} else {
proxy.SetAuth(req, gateway)
}
// req, err := http.NewRequestWithContext(context.Background(), "DELETE", deleteEndpoint, reader)
// if err != nil {
// return err
// }
// req.Header.Set("Content-Type", "application/json")
delRes, delErr := c.Do(req)
if delErr != nil {
return delErr
}
// if len(token) > 0 {
// proxy.SetToken(req, token)
// } else {
// proxy.SetAuth(req, gateway)
// }
if delRes.Body != nil {
defer func() {
if err := delRes.Body.Close(); err != nil {
log.Error().Err(err).Msgf("closing delete-gtw body")
}
}()
}
// delRes, delErr := c.Do(req)
// if delErr != nil {
// return delErr
// }
switch delRes.StatusCode {
case http.StatusOK, http.StatusCreated, http.StatusAccepted:
return nil
case http.StatusNotFound:
return fmt.Errorf("no function named %s found", functionName)
case http.StatusUnauthorized:
return fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
default:
bytesOut, err := ioutil.ReadAll(delRes.Body)
if err != nil {
return err
}
return fmt.Errorf("server returned unexpected status code %d %s", delRes.StatusCode, string(bytesOut))
}
}
// if delRes.Body != nil {
// defer func() {
// if err := delRes.Body.Close(); err != nil {
// log.Error().Err(err).Msgf("closing delete-gtw body")
// }
// }()
// }
func createSystemEndpoint(gateway, namespace string) (string, error) {
const systemPath = "/system/functions"
// switch delRes.StatusCode {
// case http.StatusOK, http.StatusCreated, http.StatusAccepted:
// return nil
// case http.StatusNotFound:
// return fmt.Errorf("no function named %s found", functionName)
// case http.StatusUnauthorized:
// return fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
// default:
// bytesOut, err := ioutil.ReadAll(delRes.Body)
// if err != nil {
// return err
// }
// return fmt.Errorf("server returned unexpected status code %d %s", delRes.StatusCode, string(bytesOut))
// }
// }
gatewayURL, err := url.Parse(gateway)
if err != nil {
return "", fmt.Errorf("invalid gateway URL: %w", err)
}
gatewayURL.Path = path.Join(gatewayURL.Path, systemPath)
if len(namespace) > 0 {
q := gatewayURL.Query()
q.Set("namespace", namespace)
gatewayURL.RawQuery = q.Encode()
}
return gatewayURL.String(), nil
}
// func createSystemEndpoint(gateway, namespace string) (string, error) {
// const systemPath = "/system/functions"
// gatewayURL, err := url.Parse(gateway)
// if err != nil {
// return "", fmt.Errorf("invalid gateway URL: %w", err)
// }
// gatewayURL.Path = path.Join(gatewayURL.Path, systemPath)
// if len(namespace) > 0 {
// q := gatewayURL.Query()
// q.Set("namespace", namespace)
// gatewayURL.RawQuery = q.Encode()
// }
// return gatewayURL.String(), nil
// }

View File

@ -92,11 +92,12 @@ func AccessorFor(f Factory, gvr client.GVR) (Accessor, error) {
client.NewGVR("batch/v1/cronjobs"): &CronJob{},
client.NewGVR("batch/v1beta1/cronjobs"): &CronJob{},
client.NewGVR("batch/v1/jobs"): &Job{},
client.NewGVR("openfaas"): &OpenFaas{},
client.NewGVR("popeye"): &Popeye{},
client.NewGVR("sanitizer"): &Popeye{},
client.NewGVR("helm"): &Helm{},
client.NewGVR("dir"): &Dir{},
// BOZO!! Revamp with latest...
// client.NewGVR("openfaas"): &OpenFaas{},
client.NewGVR("popeye"): &Popeye{},
client.NewGVR("sanitizer"): &Popeye{},
client.NewGVR("helm"): &Helm{},
client.NewGVR("dir"): &Dir{},
}
r, ok := m[gvr]
@ -195,9 +196,10 @@ func loadNonResource(m ResourceMetas) {
loadK9s(m)
loadRBAC(m)
loadHelm(m)
if IsOpenFaasEnabled() {
loadOpenFaas(m)
}
// BOZO!! Revamp with latest...
// if IsOpenFaasEnabled() {
// loadOpenFaas(m)
// }
}
func loadK9s(m ResourceMetas) {
@ -301,16 +303,17 @@ func loadHelm(m ResourceMetas) {
}
}
func loadOpenFaas(m ResourceMetas) {
m[client.NewGVR("openfaas")] = metav1.APIResource{
Name: "openfaas",
Kind: "OpenFaaS",
ShortNames: []string{"ofaas", "ofa"},
Namespaced: true,
Verbs: []string{"delete"},
Categories: []string{"faas"},
}
}
// BOZO!! revamp with latest...
// func loadOpenFaas(m ResourceMetas) {
// m[client.NewGVR("openfaas")] = metav1.APIResource{
// Name: "openfaas",
// Kind: "OpenFaaS",
// ShortNames: []string{"ofaas", "ofa"},
// Namespaced: true,
// Verbs: []string{"delete"},
// Categories: []string{"faas"},
// }
// }
func loadRBAC(m ResourceMetas) {
m[client.NewGVR("rbac")] = metav1.APIResource{

View File

@ -25,10 +25,11 @@ var Registry = map[string]ResourceMeta{
DAO: &dao.Helm{},
Renderer: &render.Helm{},
},
"openfaas": {
DAO: &dao.OpenFaas{},
Renderer: &render.OpenFaas{},
},
// BOZO!! revamp with latest...
// "openfaas": {
// DAO: &dao.OpenFaas{},
// Renderer: &render.OpenFaas{},
// },
"containers": {
DAO: &dao.Container{},
Renderer: &render.Container{},

View File

@ -1,110 +1,113 @@
package render
import (
"errors"
"fmt"
"strconv"
"time"
// BOZO!! revamp with latest...
"github.com/derailed/k9s/internal/client"
"github.com/derailed/tview"
"github.com/gdamore/tcell/v2"
ofaas "github.com/openfaas/faas-provider/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// import (
// "errors"
// "fmt"
// "strconv"
// "time"
const (
fnStatusReady = "Ready"
fnStatusNotReady = "Not Ready"
)
// "github.com/derailed/k9s/internal/client"
// "github.com/derailed/tview"
// "github.com/gdamore/tcell/v2"
// OpenFaas renders an openfaas function to screen.
type OpenFaas struct{}
// ofaas "github.com/openfaas/faas-provider/types"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/runtime"
// "k8s.io/apimachinery/pkg/runtime/schema"
// )
// ColorerFunc colors a resource row.
func (o OpenFaas) ColorerFunc() ColorerFunc {
return func(ns string, h Header, re RowEvent) tcell.Color {
if !Happy(ns, h, re.Row) {
return ErrColor
}
// const (
// fnStatusReady = "Ready"
// fnStatusNotReady = "Not Ready"
// )
return tcell.ColorPaleTurquoise
}
}
// // OpenFaas renders an openfaas function to screen.
// type OpenFaas struct{}
// Header returns a header row.
func (OpenFaas) Header(ns string) Header {
return Header{
HeaderColumn{Name: "NAMESPACE"},
HeaderColumn{Name: "NAME"},
HeaderColumn{Name: "STATUS"},
HeaderColumn{Name: "IMAGE"},
HeaderColumn{Name: "LABELS"},
HeaderColumn{Name: "INVOCATIONS", Align: tview.AlignRight},
HeaderColumn{Name: "REPLICAS", Align: tview.AlignRight},
HeaderColumn{Name: "AVAILABLE", Align: tview.AlignRight},
HeaderColumn{Name: "VALID", Wide: true},
HeaderColumn{Name: "AGE", Time: true, Decorator: AgeDecorator},
}
}
// // ColorerFunc colors a resource row.
// func (o OpenFaas) ColorerFunc() ColorerFunc {
// return func(ns string, h Header, re RowEvent) tcell.Color {
// if !Happy(ns, h, re.Row) {
// return ErrColor
// }
// Render renders a chart to screen.
func (o OpenFaas) Render(i interface{}, ns string, r *Row) error {
fn, ok := i.(OpenFaasRes)
if !ok {
return fmt.Errorf("expected OpenFaasRes, but got %T", o)
}
// return tcell.ColorPaleTurquoise
// }
// }
var labels string
if fn.Function.Labels != nil {
labels = mapToStr(*fn.Function.Labels)
}
status := fnStatusReady
if fn.Function.AvailableReplicas == 0 {
status = fnStatusNotReady
}
// // Header returns a header row.
// func (OpenFaas) Header(ns string) Header {
// return Header{
// HeaderColumn{Name: "NAMESPACE"},
// HeaderColumn{Name: "NAME"},
// HeaderColumn{Name: "STATUS"},
// HeaderColumn{Name: "IMAGE"},
// HeaderColumn{Name: "LABELS"},
// HeaderColumn{Name: "INVOCATIONS", Align: tview.AlignRight},
// HeaderColumn{Name: "REPLICAS", Align: tview.AlignRight},
// HeaderColumn{Name: "AVAILABLE", Align: tview.AlignRight},
// HeaderColumn{Name: "VALID", Wide: true},
// HeaderColumn{Name: "AGE", Time: true, Decorator: AgeDecorator},
// }
// }
r.ID = client.FQN(fn.Function.Namespace, fn.Function.Name)
r.Fields = Fields{
fn.Function.Namespace,
fn.Function.Name,
status,
fn.Function.Image,
labels,
strconv.Itoa(int(fn.Function.InvocationCount)),
strconv.Itoa(int(fn.Function.Replicas)),
strconv.Itoa(int(fn.Function.AvailableReplicas)),
asStatus(o.diagnose(status)),
toAge(metav1.Time{Time: time.Now()}),
}
// // Render renders a chart to screen.
// func (o OpenFaas) Render(i interface{}, ns string, r *Row) error {
// fn, ok := i.(OpenFaasRes)
// if !ok {
// return fmt.Errorf("expected OpenFaasRes, but got %T", o)
// }
return nil
}
// var labels string
// if fn.Function.Labels != nil {
// labels = mapToStr(*fn.Function.Labels)
// }
// status := fnStatusReady
// if fn.Function.AvailableReplicas == 0 {
// status = fnStatusNotReady
// }
func (OpenFaas) diagnose(status string) error {
if status != "Ready" {
return errors.New("function not ready")
}
// r.ID = client.FQN(fn.Function.Namespace, fn.Function.Name)
// r.Fields = Fields{
// fn.Function.Namespace,
// fn.Function.Name,
// status,
// fn.Function.Image,
// labels,
// strconv.Itoa(int(fn.Function.InvocationCount)),
// strconv.Itoa(int(fn.Function.Replicas)),
// strconv.Itoa(int(fn.Function.AvailableReplicas)),
// asStatus(o.diagnose(status)),
// toAge(metav1.Time{Time: time.Now()}),
// }
return nil
}
// return nil
// }
// ----------------------------------------------------------------------------
// Helpers...
// func (OpenFaas) diagnose(status string) error {
// if status != "Ready" {
// return errors.New("function not ready")
// }
// OpenFaasRes represents an openfaas function resource.
type OpenFaasRes struct {
Function ofaas.FunctionStatus `json:"function"`
}
// return nil
// }
// GetObjectKind returns a schema object.
func (OpenFaasRes) GetObjectKind() schema.ObjectKind {
return nil
}
// // ----------------------------------------------------------------------------
// // Helpers...
// DeepCopyObject returns a container copy.
func (h OpenFaasRes) DeepCopyObject() runtime.Object {
return h
}
// // OpenFaasRes represents an openfaas function resource.
// type OpenFaasRes struct {
// Function ofaas.FunctionStatus `json:"function"`
// }
// // GetObjectKind returns a schema object.
// func (OpenFaasRes) GetObjectKind() schema.ObjectKind {
// return nil
// }
// // DeepCopyObject returns a container copy.
// func (h OpenFaasRes) DeepCopyObject() runtime.Object {
// return h
// }

View File

@ -1,34 +1,36 @@
package render_test
import (
"testing"
// BOZO!! revamp with latest...
"github.com/derailed/k9s/internal/render"
ofaas "github.com/openfaas/faas-provider/types"
"github.com/stretchr/testify/assert"
)
// import (
// "testing"
func TestOpenFaasRender(t *testing.T) {
c := render.OpenFaas{}
r := render.NewRow(9)
c.Render(makeFn("blee"), "", &r)
// "github.com/derailed/k9s/internal/render"
// ofaas "github.com/openfaas/faas-provider/types"
// "github.com/stretchr/testify/assert"
// )
assert.Equal(t, "default/blee", r.ID)
assert.Equal(t, render.Fields{"default", "blee", "Ready", "nginx:0", "fred=blee", "10", "1", "1"}, r.Fields[:8])
}
// func TestOpenFaasRender(t *testing.T) {
// c := render.OpenFaas{}
// r := render.NewRow(9)
// c.Render(makeFn("blee"), "", &r)
// Helpers...
// assert.Equal(t, "default/blee", r.ID)
// assert.Equal(t, render.Fields{"default", "blee", "Ready", "nginx:0", "fred=blee", "10", "1", "1"}, r.Fields[:8])
// }
func makeFn(n string) render.OpenFaasRes {
return render.OpenFaasRes{
Function: ofaas.FunctionStatus{
Name: n,
Namespace: "default",
Image: "nginx:0",
InvocationCount: 10,
Replicas: 1,
AvailableReplicas: 1,
Labels: &map[string]string{"fred": "blee"},
},
}
}
// // Helpers...
// func makeFn(n string) render.OpenFaasRes {
// return render.OpenFaasRes{
// Function: ofaas.FunctionStatus{
// Name: n,
// Namespace: "default",
// Image: "nginx:0",
// InvocationCount: 10,
// Replicas: 1,
// AvailableReplicas: 1,
// Labels: &map[string]string{"fred": "blee"},
// },
// }
// }

View File

@ -1,46 +1,47 @@
package view
import (
"strings"
// BOZO!! revamp with latest...
// import (
// "strings"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/k9s/internal/ui"
)
// "github.com/derailed/k9s/internal/client"
// "github.com/derailed/k9s/internal/render"
// "github.com/derailed/k9s/internal/ui"
// )
// OpenFaas represents an OpenFaaS viewer.
type OpenFaas struct {
ResourceViewer
}
// // OpenFaas represents an OpenFaaS viewer.
// type OpenFaas struct {
// ResourceViewer
// }
// NewOpenFaas returns a new viewer.
func NewOpenFaas(gvr client.GVR) ResourceViewer {
o := OpenFaas{ResourceViewer: NewBrowser(gvr)}
o.AddBindKeysFn(o.bindKeys)
o.GetTable().SetEnterFn(o.showPods)
o.GetTable().SetColorerFn(render.OpenFaas{}.ColorerFunc())
// // NewOpenFaas returns a new viewer.
// func NewOpenFaas(gvr client.GVR) ResourceViewer {
// o := OpenFaas{ResourceViewer: NewBrowser(gvr)}
// o.AddBindKeysFn(o.bindKeys)
// o.GetTable().SetEnterFn(o.showPods)
// o.GetTable().SetColorerFn(render.OpenFaas{}.ColorerFunc())
return &o
}
// return &o
// }
func (o *OpenFaas) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftS: ui.NewKeyAction("Sort Status", o.GetTable().SortColCmd(statusCol, true), false),
ui.KeyShiftI: ui.NewKeyAction("Sort Invocations", o.GetTable().SortColCmd("INVOCATIONS", false), false),
ui.KeyShiftR: ui.NewKeyAction("Sort Replicas", o.GetTable().SortColCmd("REPLICAS", false), false),
ui.KeyShiftL: ui.NewKeyAction("Sort Available", o.GetTable().SortColCmd(availCol, false), false),
})
}
// func (o *OpenFaas) bindKeys(aa ui.KeyActions) {
// aa.Add(ui.KeyActions{
// ui.KeyShiftS: ui.NewKeyAction("Sort Status", o.GetTable().SortColCmd(statusCol, true), false),
// ui.KeyShiftI: ui.NewKeyAction("Sort Invocations", o.GetTable().SortColCmd("INVOCATIONS", false), false),
// ui.KeyShiftR: ui.NewKeyAction("Sort Replicas", o.GetTable().SortColCmd("REPLICAS", false), false),
// ui.KeyShiftL: ui.NewKeyAction("Sort Available", o.GetTable().SortColCmd(availCol, false), false),
// })
// }
func (o *OpenFaas) showPods(a *App, _ ui.Tabular, _, path string) {
labels := o.GetTable().GetSelectedCell(o.GetTable().NameColIndex() + 3)
sels := make(map[string]string)
// func (o *OpenFaas) showPods(a *App, _ ui.Tabular, _, path string) {
// labels := o.GetTable().GetSelectedCell(o.GetTable().NameColIndex() + 3)
// sels := make(map[string]string)
tokens := strings.Split(labels, ",")
for _, t := range tokens {
s := strings.Split(t, "=")
sels[s[0]] = s[1]
}
// tokens := strings.Split(labels, ",")
// for _, t := range tokens {
// s := strings.Split(t, "=")
// sels[s[0]] = s[1]
// }
showPodsWithLabels(a, path, sels)
}
// showPodsWithLabels(a, path, sels)
// }

View File

@ -60,9 +60,10 @@ func miscViewers(vv MetaViewers) {
vv[client.NewGVR("contexts")] = MetaViewer{
viewerFn: NewContext,
}
vv[client.NewGVR("openfaas")] = MetaViewer{
viewerFn: NewOpenFaas,
}
// BOZO!! revamp with latest...
// vv[client.NewGVR("openfaas")] = MetaViewer{
// viewerFn: NewOpenFaas,
// }
vv[client.NewGVR("containers")] = MetaViewer{
viewerFn: NewContainer,
}