@@ -2,12 +2,12 @@ package bootkube
22
33import (
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
3131type 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 {
102105func 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