Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7669181
commit c196e5f
Showing
12 changed files
with
143 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "kube", | ||
srcs = ["context.go"], | ||
importpath = "cli/pkg/kube", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@io_k8s_client_go//kubernetes:go_default_library", | ||
"@io_k8s_client_go//tools/clientcmd:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kube | ||
|
||
import ( | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
type KubeCtx struct { | ||
kubeConfigPath string | ||
contextName string | ||
} | ||
|
||
func New(kubeConfigPath, contextName string) KubeCtx { | ||
return KubeCtx{ | ||
kubeConfigPath: kubeConfigPath, | ||
contextName: contextName, | ||
} | ||
} | ||
|
||
func (c *KubeCtx) GetClientSet() (*kubernetes.Clientset, error) { | ||
if c.contextName == "" { | ||
config, err := clientcmd.BuildConfigFromFlags("", c.kubeConfigPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return kubernetes.NewForConfig(config) | ||
} | ||
|
||
file, err := clientcmd.LoadFromFile(c.kubeConfigPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config, err := clientcmd.NewNonInteractiveClientConfig(*file, c.contextName, nil, nil).ClientConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return kubernetes.NewForConfig(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package aws | ||
|
||
import ( | ||
"cli/pkg/kube" | ||
"fmt" | ||
"k8s.io/client-go/kubernetes" | ||
"os" | ||
) | ||
|
||
type Aws struct { | ||
} | ||
|
||
func Create() (*kubernetes.Clientset, error) { | ||
fmt.Println("aws provider not yet implemented") | ||
func (a *Aws) Provision() (kube.KubeCtx, error) { | ||
// Use this to | ||
//clientcmd.NewNonInteractiveClientConfig() | ||
fmt.Println("minikube provider not yet implemented") | ||
os.Exit(1) | ||
return nil, nil | ||
return kube.KubeCtx{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
package minikube | ||
|
||
import ( | ||
"cli/pkg/kube" | ||
"fmt" | ||
"k8s.io/client-go/kubernetes" | ||
"os" | ||
) | ||
|
||
func Create() (*kubernetes.Clientset, error) { | ||
type Minikube struct { | ||
} | ||
|
||
func (m *Minikube) Provision() (kube.KubeCtx, error) { | ||
// Use this to | ||
//clientcmd.NewNonInteractiveClientConfig() | ||
fmt.Println("minikube provider not yet implemented") | ||
os.Exit(1) | ||
return nil, nil | ||
return kube.KubeCtx{}, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package providers | ||
|
||
import ( | ||
"cli/pkg/kube" | ||
"cli/pkg/providers/aws" | ||
"cli/pkg/providers/minikube" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type ProviderName string | ||
|
||
const ( | ||
Local ProviderName = "local" | ||
Minikube ProviderName = "minikube" | ||
Aws ProviderName = "aws" | ||
) | ||
|
||
type Provider interface { | ||
Provision() (kube.KubeCtx, error) | ||
} | ||
|
||
func MustGet(providerName ProviderName) Provider { | ||
if providerName == Minikube { | ||
return &minikube.Minikube{} | ||
} | ||
|
||
if providerName == Aws { | ||
return &aws.Aws{} | ||
} | ||
|
||
// TODO remove this provider in #1041 | ||
if providerName == Local { | ||
return &LocalProvider{} | ||
} | ||
|
||
panic(fmt.Sprintf("unknown provider \"%v\"", providerName)) | ||
} | ||
|
||
// TODO remove this provider in #1041 | ||
type LocalProvider struct { | ||
} | ||
|
||
func (l *LocalProvider) Provision() (kube.KubeCtx, error) { | ||
return kube.New(os.Getenv("KUBE_CONFIG_PATH"), ""), nil | ||
} |
This file was deleted.
Oops, something went wrong.