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

Commit 702d53e

Browse files
authored
Merge pull request #473 from yifan-gu/no_fileutil
pkg/bootkube: Remove dependency on github.com/coreos/etcd/pkg/fileutil.
2 parents ffb3d37 + f69f75f commit 702d53e

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pkg/bootkube/bootkube.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package bootkube
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67
"time"
78

89
"k8s.io/client-go/tools/clientcmd"
910

10-
"github.com/coreos/etcd/pkg/fileutil"
1111
"github.com/kubernetes-incubator/bootkube/pkg/asset"
1212
"github.com/kubernetes-incubator/bootkube/pkg/util/etcdutil"
1313
)
@@ -29,7 +29,6 @@ type Config struct {
2929
}
3030

3131
type bootkube struct {
32-
selfHostedEtcd bool
3332
podManifestPath string
3433
assetDir string
3534
}
@@ -38,7 +37,6 @@ func NewBootkube(config Config) (*bootkube, error) {
3837
return &bootkube{
3938
assetDir: config.AssetDir,
4039
podManifestPath: config.PodManifestPath,
41-
selfHostedEtcd: fileutil.Exist(filepath.Join(config.AssetDir, asset.AssetPathBootstrapEtcd)),
4240
}, nil
4341
}
4442

@@ -72,15 +70,20 @@ func (b *bootkube) Run() error {
7270
return err
7371
}
7472

75-
if b.selfHostedEtcd {
73+
selfHostedEtcd, err := detectSelfHostedEtcd(b.assetDir, asset.AssetPathBootstrapEtcd)
74+
if err != nil {
75+
return err
76+
}
77+
78+
if selfHostedEtcd {
7679
requiredPods = append(requiredPods, "etcd-operator")
7780
}
7881

7982
if err = WaitUntilPodsRunning(requiredPods, assetTimeout); err != nil {
8083
return err
8184
}
8285

83-
if b.selfHostedEtcd {
86+
if selfHostedEtcd {
8487
UserOutput("Migrating to self-hosted etcd cluster...\n")
8588
var etcdServiceIP string
8689
etcdServiceIP, err = detectEtcdIP(b.assetDir)
@@ -102,3 +105,16 @@ func (b *bootkube) Run() error {
102105
func UserOutput(format string, a ...interface{}) {
103106
fmt.Printf(format, a...)
104107
}
108+
109+
// detectSelfHostedEtcd returns true if the asset dir contains assets for bootstrap etcd.
110+
func detectSelfHostedEtcd(assetDir, assetPathBootstrapEtcd string) (bool, error) {
111+
etcdAssetsPath := filepath.Join(assetDir, assetPathBootstrapEtcd)
112+
_, err := os.Stat(etcdAssetsPath)
113+
if err == nil {
114+
return true, nil
115+
}
116+
if os.IsNotExist(err) {
117+
return false, nil
118+
}
119+
return false, err
120+
}

0 commit comments

Comments
 (0)