1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00

feat(helm): update helm view [r8s-256] (#582)

Co-authored-by: Cara Ryan <cara.ryan@portainer.io>
Co-authored-by: James Player <james.player@portainer.io>
Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
Ali 2025-04-10 16:08:24 +12:00 committed by GitHub
parent 46eddbe7b9
commit 0ca9321db1
57 changed files with 2635 additions and 222 deletions

63
pkg/libkubectl/client.go Normal file
View file

@ -0,0 +1,63 @@
package libkubectl
import (
"bytes"
"errors"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/kubectl/pkg/cmd/util"
)
type ClientAccess struct {
Token string
ServerUrl string
}
type Client struct {
factory util.Factory
streams genericclioptions.IOStreams
out *bytes.Buffer
}
// NewClient creates a new kubectl client
func NewClient(libKubectlAccess *ClientAccess, namespace, kubeconfig string, insecure bool) (*Client, error) {
configFlags, err := generateConfigFlags(libKubectlAccess.Token, libKubectlAccess.ServerUrl, namespace, kubeconfig, insecure)
if err != nil {
return nil, err
}
streams, _, out, _ := genericiooptions.NewTestIOStreams()
return &Client{
factory: util.NewFactory(configFlags),
streams: streams,
out: out,
}, nil
}
// generateConfigFlags generates the config flags for the kubectl client
// If kubeconfigPath is provided, it will be used instead of server and token
// If server and token are provided, they will be used to connect to the cluster
// If neither kubeconfigPath or server and token are provided, an error will be returned
func generateConfigFlags(token, server, namespace, kubeconfigPath string, insecure bool) (*genericclioptions.ConfigFlags, error) {
if kubeconfigPath == "" && (server == "" || token == "") {
return nil, errors.New("must provide either a kubeconfig path or a server and token")
}
configFlags := genericclioptions.NewConfigFlags(true)
if namespace != "" {
configFlags.Namespace = &namespace
}
if kubeconfigPath != "" {
configFlags.KubeConfig = &kubeconfigPath
} else {
configFlags.APIServer = &server
configFlags.BearerToken = &token
}
configFlags.Insecure = &insecure
return configFlags, nil
}