Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 56c9534

Browse files
authored
Merge pull request #898 from ericchiang/bootkube-global-var
pkg/bootkube: remove global variable
2 parents 1985d43 + 63aedb6 commit 56c9534

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

pkg/bootkube/bootkube.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
const assetTimeout = 20 * time.Minute
1414

15-
var kubeConfig clientcmd.ClientConfig
16-
1715
var requiredPods = []string{
1816
"pod-checkpointer",
1917
"kube-apiserver",
@@ -41,7 +39,7 @@ func NewBootkube(config Config) (*bootkube, error) {
4139
func (b *bootkube) Run() error {
4240
// TODO(diegs): create and share a single client rather than the kubeconfig once all uses of it
4341
// are migrated to client-go.
44-
kubeConfig = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
42+
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
4543
&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(b.assetDir, asset.AssetPathAdminKubeConfig)},
4644
&clientcmd.ConfigOverrides{})
4745

@@ -66,11 +64,11 @@ func (b *bootkube) Run() error {
6664
return err
6765
}
6866

69-
if err = CreateAssets(filepath.Join(b.assetDir, asset.AssetPathManifests), assetTimeout); err != nil {
67+
if err = CreateAssets(kubeConfig, filepath.Join(b.assetDir, asset.AssetPathManifests), assetTimeout); err != nil {
7068
return err
7169
}
7270

73-
if err = WaitUntilPodsRunning(requiredPods, assetTimeout); err != nil {
71+
if err = WaitUntilPodsRunning(kubeConfig, requiredPods, assetTimeout); err != nil {
7472
return err
7573
}
7674

pkg/bootkube/create.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ const (
2929
crdRolloutTimeout = 2 * time.Minute
3030
)
3131

32-
func CreateAssets(manifestDir string, timeout time.Duration) error {
32+
func CreateAssets(config clientcmd.ClientConfig, manifestDir string, timeout time.Duration) error {
3333
if _, err := os.Stat(manifestDir); os.IsNotExist(err) {
3434
UserOutput(fmt.Sprintf("WARNING: %v does not exist, not creating any self-hosted assets.\n", manifestDir))
3535
return nil
3636
}
3737

3838
upFn := func() (bool, error) {
39-
if err := apiTest(); err != nil {
39+
if err := apiTest(config); err != nil {
4040
glog.Warningf("Unable to determine api-server readiness: %v", err)
4141
return false, nil
4242
}
4343
return true, nil
4444
}
4545

4646
createFn := func() (bool, error) {
47-
err := createAssets(manifestDir)
47+
err := createAssets(config, manifestDir)
4848
if err != nil {
4949
err = fmt.Errorf("Error creating assets: %v", err)
5050
glog.Error(err)
@@ -81,8 +81,8 @@ func CreateAssets(manifestDir string, timeout time.Duration) error {
8181
// we should consider refactoring this. The kubectl code tends to be very verbose and difficult to
8282
// reason about, especially as the behevior of certain functions (e.g. `Visit`) can be difficult to
8383
// predict with regards to error handling.
84-
func createAssets(manifestDir string) error {
85-
f := cmdutil.NewFactory(kubeConfig)
84+
func createAssets(config clientcmd.ClientConfig, manifestDir string) error {
85+
f := cmdutil.NewFactory(config)
8686

8787
shouldValidate := true
8888
schema, err := f.Validator(shouldValidate, fmt.Sprintf("~/%s/%s", clientcmd.RecommendedHomeDir, clientcmd.RecommendedSchemaName))
@@ -205,8 +205,8 @@ func customResourceDefinitionKindURI(apiGroup, version, namespace, plural string
205205
strings.ToLower(plural))
206206
}
207207

208-
func apiTest() error {
209-
config, err := kubeConfig.ClientConfig()
208+
func apiTest(c clientcmd.ClientConfig) error {
209+
config, err := c.ClientConfig()
210210
if err != nil {
211211
return err
212212
}

pkg/bootkube/status.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
"k8s.io/client-go/pkg/api"
1717
"k8s.io/client-go/pkg/api/v1"
1818
"k8s.io/client-go/tools/cache"
19+
"k8s.io/client-go/tools/clientcmd"
1920
)
2021

2122
const (
2223
doesNotExist = "DoesNotExist"
2324
)
2425

25-
func WaitUntilPodsRunning(pods []string, timeout time.Duration) error {
26-
sc, err := NewStatusController(pods)
26+
func WaitUntilPodsRunning(c clientcmd.ClientConfig, pods []string, timeout time.Duration) error {
27+
sc, err := NewStatusController(c, pods)
2728
if err != nil {
2829
return err
2930
}
@@ -44,8 +45,8 @@ type statusController struct {
4445
lastPodPhases map[string]v1.PodPhase
4546
}
4647

47-
func NewStatusController(pods []string) (*statusController, error) {
48-
config, err := kubeConfig.ClientConfig()
48+
func NewStatusController(c clientcmd.ClientConfig, pods []string) (*statusController, error) {
49+
config, err := c.ClientConfig()
4950
if err != nil {
5051
return nil, err
5152
}

0 commit comments

Comments
 (0)