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

Commit

Permalink
Merge pull request #898 from ericchiang/bootkube-global-var
Browse files Browse the repository at this point in the history
pkg/bootkube: remove global variable
  • Loading branch information
ericchiang authored Feb 16, 2018
2 parents 1985d43 + 63aedb6 commit 56c9534
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 3 additions & 5 deletions pkg/bootkube/bootkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (

const assetTimeout = 20 * time.Minute

var kubeConfig clientcmd.ClientConfig

var requiredPods = []string{
"pod-checkpointer",
"kube-apiserver",
Expand Down Expand Up @@ -41,7 +39,7 @@ func NewBootkube(config Config) (*bootkube, error) {
func (b *bootkube) Run() error {
// TODO(diegs): create and share a single client rather than the kubeconfig once all uses of it
// are migrated to client-go.
kubeConfig = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(b.assetDir, asset.AssetPathAdminKubeConfig)},
&clientcmd.ConfigOverrides{})

Expand All @@ -66,11 +64,11 @@ func (b *bootkube) Run() error {
return err
}

if err = CreateAssets(filepath.Join(b.assetDir, asset.AssetPathManifests), assetTimeout); err != nil {
if err = CreateAssets(kubeConfig, filepath.Join(b.assetDir, asset.AssetPathManifests), assetTimeout); err != nil {
return err
}

if err = WaitUntilPodsRunning(requiredPods, assetTimeout); err != nil {
if err = WaitUntilPodsRunning(kubeConfig, requiredPods, assetTimeout); err != nil {
return err
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/bootkube/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ const (
crdRolloutTimeout = 2 * time.Minute
)

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

upFn := func() (bool, error) {
if err := apiTest(); err != nil {
if err := apiTest(config); err != nil {
glog.Warningf("Unable to determine api-server readiness: %v", err)
return false, nil
}
return true, nil
}

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

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

func apiTest() error {
config, err := kubeConfig.ClientConfig()
func apiTest(c clientcmd.ClientConfig) error {
config, err := c.ClientConfig()
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/bootkube/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
)

const (
doesNotExist = "DoesNotExist"
)

func WaitUntilPodsRunning(pods []string, timeout time.Duration) error {
sc, err := NewStatusController(pods)
func WaitUntilPodsRunning(c clientcmd.ClientConfig, pods []string, timeout time.Duration) error {
sc, err := NewStatusController(c, pods)
if err != nil {
return err
}
Expand All @@ -44,8 +45,8 @@ type statusController struct {
lastPodPhases map[string]v1.PodPhase
}

func NewStatusController(pods []string) (*statusController, error) {
config, err := kubeConfig.ClientConfig()
func NewStatusController(c clientcmd.ClientConfig, pods []string) (*statusController, error) {
config, err := c.ClientConfig()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 56c9534

Please sign in to comment.