Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow login with token #105

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Kubernetes struct {
// KubeConfig represents the initialization settings for the kubernetes api client.
type KubeConfig struct {
ConfigPath string
Server string
Token string
}

// Ensure the interfaces are implemented correctly.
Expand Down Expand Up @@ -145,6 +147,18 @@ func (mi *ModuleInstance) newClient(c goja.ConstructorCall) *goja.Object {
}

func getClientConfig(options KubeConfig) (*rest.Config, error) {
// If server and token are provided, use them
if options.Server != "" && options.Token != "" {
return &rest.Config{
Host: options.Server,
BearerToken: options.Token,
TLSClientConfig: rest.TLSClientConfig{
Insecure: true,
},
}, nil
}

// If server and token are not provided, use kubeconfig
kubeconfig := options.ConfigPath
if kubeconfig == "" {
// are we in-cluster?
Expand Down