-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.go
40 lines (33 loc) · 1.07 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils
import (
"log/slog"
"os"
pluginTypes "github.com/argoproj/argo-rollouts/utils/plugin/types"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func NewKubeConfig() (*rest.Config, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
// if you want to change the loading rules (which files in which order), you can do so here
configOverrides := &clientcmd.ConfigOverrides{}
// if you want to change override values or bind them to flags, there are methods to help you
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
return nil, pluginTypes.RpcError{ErrorString: err.Error()}
}
return config, nil
}
func InitLogger(lvl slog.Level) {
lvlVar := &slog.LevelVar{}
lvlVar.Set(lvl)
opts := slog.HandlerOptions{
Level: lvlVar,
}
attrs := []slog.Attr{
slog.String("plugin", "trafficrouter"),
slog.String("vendor", "contour"),
}
l := slog.New(slog.NewTextHandler(os.Stderr, &opts).WithAttrs(attrs))
slog.SetDefault(l)
}