Skip to content

Commit 6510344

Browse files
committed
Fix smaller issues
1 parent 6f98741 commit 6510344

10 files changed

Lines changed: 111 additions & 108 deletions

File tree

cmd/add.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ type addDeploymentFlags struct {
4949

5050
func init() {
5151
cmd := &AddCmd{
52-
flags: &AddCmdFlags{},
53-
syncFlags: &addSyncCmdFlags{},
54-
portFlags: &addPortCmdFlags{},
55-
packageFlags: &addPackageFlags{},
52+
flags: &AddCmdFlags{},
53+
syncFlags: &addSyncCmdFlags{},
54+
portFlags: &addPortCmdFlags{},
55+
packageFlags: &addPackageFlags{},
56+
deploymentFlags: &addDeploymentFlags{},
5657
}
5758

5859
addCmd := &cobra.Command{

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
134134
}
135135

136136
configutil.Merge(config, &v1.Config{
137-
Version: configutil.String("v1"),
137+
Version: configutil.String(configutil.CurrentConfigVersion),
138138
DevSpace: &v1.DevSpaceConfig{
139139
Deployments: &[]*v1.DeploymentConfig{},
140140
},

cmd/reset.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (cmd *ResetCmd) deleteInternalRegistry() {
8181

8282
if config.InternalRegistry != nil {
8383
shouldRegistryRemoved := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
84-
Question: "Should the internal registry be removed? (y/n)",
84+
Question: "\n\nShould the internal registry be removed? (y/n)",
8585
DefaultValue: "y",
8686
ValidationRegexPattern: "^(y|n)$",
8787
}) == "y"
@@ -112,7 +112,7 @@ func (cmd *ResetCmd) deleteTiller() {
112112

113113
if config.Tiller != nil {
114114
shouldRemoveTiller := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
115-
Question: "Should the tiller server be removed? (y/n)",
115+
Question: "\n\nShould the tiller server be removed? (y/n)",
116116
DefaultValue: "y",
117117
ValidationRegexPattern: "^(y|n)$",
118118
}) == "y"
@@ -143,7 +143,7 @@ func (cmd *ResetCmd) deleteDeploymentFiles() {
143143
_, err := os.Stat(absChartPath)
144144
if os.IsNotExist(err) == false {
145145
deleteChart := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
146-
Question: "Should the Chart (" + *deployConfig.Helm.ChartPath + "/*) be removed? (y/n)",
146+
Question: "\n\nShould the Chart (" + *deployConfig.Helm.ChartPath + "/*) be removed? (y/n)",
147147
DefaultValue: "y",
148148
ValidationRegexPattern: "^(y|n)$",
149149
}) == "y"
@@ -176,7 +176,7 @@ func (cmd *ResetCmd) deleteImageFiles() {
176176
_, err = os.Stat(absDockerfilePath)
177177
if os.IsNotExist(err) == false {
178178
deleteDockerfile := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
179-
Question: "Should " + dockerfilePath + " be removed? (y/n)",
179+
Question: "\n\nShould " + dockerfilePath + " be removed? (y/n)",
180180
DefaultValue: "y",
181181
ValidationRegexPattern: "^(y|n)$",
182182
}) == "y"
@@ -201,7 +201,7 @@ func (cmd *ResetCmd) deleteImageFiles() {
201201
_, err = os.Stat(absDockerIgnorePath)
202202
if os.IsNotExist(err) == false {
203203
deleteDockerIgnore := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
204-
Question: "Should " + absDockerIgnorePath + " be removed? (y/n)",
204+
Question: "\n\nShould " + absDockerIgnorePath + " be removed? (y/n)",
205205
DefaultValue: "y",
206206
ValidationRegexPattern: "^(y|n)$",
207207
}) == "y"
@@ -218,7 +218,7 @@ func (cmd *ResetCmd) deleteClusterRoleBinding() {
218218
_, err := cmd.kubectl.RbacV1beta1().ClusterRoleBindings().Get(clusterRoleBindingName, metav1.GetOptions{})
219219
if err == nil {
220220
deleteRoleBinding := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
221-
Question: "Should the ClusterRoleBinding '" + clusterRoleBindingName + "' be removed? (y/n)",
221+
Question: "\n\nShould the ClusterRoleBinding '" + clusterRoleBindingName + "' be removed? (y/n)",
222222
DefaultValue: "y",
223223
ValidationRegexPattern: "^(y|n)$",
224224
}) == "y"
@@ -239,7 +239,7 @@ func (cmd *ResetCmd) deleteClusterRoleBinding() {
239239

240240
func (cmd *ResetCmd) deleteDevspaceFolder() {
241241
deleteDevspaceFolder := *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
242-
Question: "Should the .devspace folder be removed? (y/n)",
242+
Question: "\n\nShould the .devspace folder be removed? (y/n)",
243243
DefaultValue: "y",
244244
ValidationRegexPattern: "^(y|n)$",
245245
}) == "y"

cmd/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
150150

151151
defer func() {
152152
for _, v := range syncConfigs {
153-
v.Stop()
153+
v.Stop(nil)
154154
}
155155
}()
156156
}

pkg/devspace/config/configutil/get.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const OverwriteConfigPath = "/.devspace/overwrite.yaml"
2828
// DefaultDevspaceDeploymentName is the name of the initial default deployment
2929
const DefaultDevspaceDeploymentName = "devspace-default"
3030

31+
// CurrentConfigVersion has the value of the current config version
32+
const CurrentConfigVersion = "v1alpha1"
33+
3134
// Global config vars
3235
var config *v1.Config
3336
var configRaw *v1.Config
@@ -84,6 +87,10 @@ func GetConfig() *v1.Config {
8487
merge(overwriteConfig, overwriteConfigRaw, unsafe.Pointer(&overwriteConfig), unsafe.Pointer(overwriteConfigRaw))
8588
merge(config, overwriteConfig, unsafe.Pointer(&config), unsafe.Pointer(overwriteConfig))
8689

90+
if config.Version == nil || *config.Version != CurrentConfigVersion {
91+
log.Fatal("Your config is out of date. Please run `devspace init -r` to update your config")
92+
}
93+
8794
SetDefaults(config)
8895
})
8996

pkg/devspace/helm/client.go

Lines changed: 73 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,39 @@ func NewClient(kubectlClient *kubernetes.Clientset, log log.Logger, upgradeTille
4646
var outerError error
4747

4848
getOnce.Do(func() {
49-
config := configutil.GetConfig()
50-
if config.Tiller == nil || config.Tiller.Namespace == nil {
51-
outerError = errors.New("No tiller namespace specified")
52-
return
53-
}
49+
helmClient, outerError = createNewClient(kubectlClient, log, upgradeTiller)
50+
})
5451

55-
tillerNamespace := *config.Tiller.Namespace
56-
kubeconfig, err := kubectl.GetClientConfig()
57-
if err != nil {
58-
outerError = err
59-
return
60-
}
52+
return helmClient, outerError
53+
}
6154

62-
err = ensureTiller(kubectlClient, config, upgradeTiller)
63-
if err != nil {
64-
outerError = err
65-
return
66-
}
55+
func createNewClient(kubectlClient *kubernetes.Clientset, log log.Logger, upgradeTiller bool) (*ClientWrapper, error) {
56+
config := configutil.GetConfig()
57+
if config.Tiller == nil || config.Tiller.Namespace == nil {
58+
return nil, errors.New("No tiller namespace specified")
59+
}
60+
61+
tillerNamespace := *config.Tiller.Namespace
62+
kubeconfig, err := kubectl.GetClientConfig()
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
err = ensureTiller(kubectlClient, config, upgradeTiller)
68+
if err != nil {
69+
return nil, err
70+
}
6771

68-
var tunnel *kube.Tunnel
72+
var tunnel *kube.Tunnel
73+
var client *k8shelm.Client
6974

70-
tunnelWaitTime := 2 * 60 * time.Second
71-
tunnelCheckInterval := 5 * time.Second
75+
tunnelWaitTime := 2 * 60 * time.Second
76+
tunnelCheckInterval := 5 * time.Second
7277

73-
log.StartWait("Waiting for " + tillerNamespace + "/tiller-deploy to become ready")
74-
defer log.StopWait()
78+
log.StartWait("Waiting for " + tillerNamespace + "/tiller-deploy to become ready")
79+
defer log.StopWait()
7580

81+
for true {
7682
// Next we wait till we can establish a tunnel to the running pod
7783
for true {
7884
tunnel, err = portforwarder.New(tillerNamespace, kubectlClient, kubeconfig)
@@ -81,88 +87,77 @@ func NewClient(kubectlClient *kubernetes.Clientset, log log.Logger, upgradeTille
8187
}
8288

8389
if tunnelWaitTime <= 0 {
84-
outerError = err
85-
return
90+
return nil, err
8691
}
8792

8893
tunnelWaitTime = tunnelWaitTime - tunnelCheckInterval
8994
time.Sleep(tunnelCheckInterval)
9095
}
9196

92-
helmWaitTime := 2 * 60 * time.Second
93-
helmCheckInterval := 5 * time.Second
94-
9597
helmOptions := []k8shelm.Option{
9698
k8shelm.Host("127.0.0.1:" + strconv.Itoa(tunnel.Local)),
97-
k8shelm.ConnectTimeout(int64(helmCheckInterval)),
99+
k8shelm.ConnectTimeout(int64(5 * time.Second)),
98100
}
99101

100-
client := k8shelm.NewClient(helmOptions...)
101-
var tillerError error
102+
client = k8shelm.NewClient(helmOptions...)
102103

103-
for helmWaitTime > 0 {
104-
_, tillerError = client.ListReleases(k8shelm.ReleaseListLimit(1))
105-
if tillerError == nil || helmWaitTime < 0 {
106-
break
107-
}
108-
109-
helmWaitTime = helmWaitTime - helmCheckInterval
110-
time.Sleep(helmCheckInterval)
104+
_, err = client.ListReleases(k8shelm.ReleaseListLimit(1))
105+
if err == nil {
106+
break
111107
}
112108

113-
log.StopWait()
109+
tunnel.Close()
114110

115-
if tillerError != nil {
116-
outerError = tillerError
117-
return
118-
}
111+
tunnelWaitTime = tunnelWaitTime - tunnelCheckInterval
112+
time.Sleep(tunnelCheckInterval)
119113

120-
homeDir, err := homedir.Dir()
121-
if err != nil {
122-
outerError = err
123-
return
114+
if tunnelWaitTime < 0 {
115+
return nil, errors.New("Waiting for tiller timed out")
124116
}
117+
}
125118

126-
helmHomePath := homeDir + "/.devspace/helm"
127-
repoPath := helmHomePath + "/repository"
128-
repoFile := repoPath + "/repositories.yaml"
129-
stableRepoCachePathAbs := helmHomePath + "/" + stableRepoCachePath
119+
log.StopWait()
130120

131-
os.MkdirAll(helmHomePath+"/cache", os.ModePerm)
132-
os.MkdirAll(repoPath, os.ModePerm)
133-
os.MkdirAll(filepath.Dir(stableRepoCachePathAbs), os.ModePerm)
121+
homeDir, err := homedir.Dir()
122+
if err != nil {
123+
return nil, err
124+
}
134125

135-
_, repoFileNotFound := os.Stat(repoFile)
136-
if repoFileNotFound != nil {
137-
err = fsutil.WriteToFile([]byte(defaultRepositories), repoFile)
138-
if err != nil {
139-
outerError = err
140-
return
141-
}
142-
}
126+
helmHomePath := homeDir + "/.devspace/helm"
127+
repoPath := helmHomePath + "/repository"
128+
repoFile := repoPath + "/repositories.yaml"
129+
stableRepoCachePathAbs := helmHomePath + "/" + stableRepoCachePath
143130

144-
wrapper := &ClientWrapper{
145-
Client: client,
146-
Settings: &helmenvironment.EnvSettings{
147-
Home: helmpath.Home(helmHomePath),
148-
},
149-
Namespace: tillerNamespace,
150-
kubectl: kubectlClient,
151-
}
131+
os.MkdirAll(helmHomePath+"/cache", os.ModePerm)
132+
os.MkdirAll(repoPath, os.ModePerm)
133+
os.MkdirAll(filepath.Dir(stableRepoCachePathAbs), os.ModePerm)
152134

153-
_, err = os.Stat(stableRepoCachePathAbs)
135+
_, repoFileNotFound := os.Stat(repoFile)
136+
if repoFileNotFound != nil {
137+
err = fsutil.WriteToFile([]byte(defaultRepositories), repoFile)
154138
if err != nil {
155-
err = wrapper.updateRepos()
156-
if err != nil {
157-
outerError = err
158-
return
159-
}
139+
return nil, err
160140
}
141+
}
161142

162-
helmClient = wrapper
163-
})
143+
wrapper := &ClientWrapper{
144+
Client: client,
145+
Settings: &helmenvironment.EnvSettings{
146+
Home: helmpath.Home(helmHomePath),
147+
},
148+
Namespace: tillerNamespace,
149+
kubectl: kubectlClient,
150+
}
164151

165-
return helmClient, outerError
152+
_, err = os.Stat(stableRepoCachePathAbs)
153+
if err != nil {
154+
err = wrapper.updateRepos()
155+
if err != nil {
156+
return nil, err
157+
}
158+
}
159+
160+
return wrapper, nil
166161
}
167162

168163
func (helmClientWrapper *ClientWrapper) updateRepos() error {

pkg/devspace/sync/sync_config.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (s *SyncConfig) Start() error {
165165

166166
err = s.downstream.start()
167167
if err != nil {
168-
s.Stop()
168+
s.Stop(nil)
169169
return errors.Trace(err)
170170
}
171171

@@ -213,12 +213,11 @@ func (s *SyncConfig) mainLoop() {
213213

214214
// Start downstream and do initial sync
215215
go func() {
216-
defer s.Stop()
216+
defer s.Stop(nil)
217217

218218
err := s.initialSync()
219219
if err != nil {
220-
s.Error(err)
221-
log.Fatalf("[Sync] Sync stopped: %v", err)
220+
s.Stop(err)
222221
return
223222
}
224223

@@ -228,13 +227,12 @@ func (s *SyncConfig) mainLoop() {
228227
}
229228

230229
func (s *SyncConfig) startUpstream() {
231-
defer s.Stop()
230+
defer s.Stop(nil)
232231

233232
// Set up a watchpoint listening for events within a directory tree rooted at specified directory
234233
err := notify.Watch(s.WatchPath+"/...", s.upstream.events, notify.All)
235234
if err != nil {
236-
s.Error(err)
237-
log.Fatalf("[Sync] Sync stopped: %v", err)
235+
s.Stop(err)
238236
return
239237
}
240238

@@ -246,18 +244,16 @@ func (s *SyncConfig) startUpstream() {
246244

247245
err = s.upstream.mainLoop()
248246
if err != nil {
249-
s.Error(err)
250-
log.Fatalf("[Sync] Sync stopped: %v", err)
247+
s.Stop(err)
251248
}
252249
}
253250

254251
func (s *SyncConfig) startDownstream() {
255-
defer s.Stop()
252+
defer s.Stop(nil)
256253

257254
err := s.downstream.mainLoop()
258255
if err != nil {
259-
s.Error(err)
260-
log.Fatalf("[Sync] Sync stopped: %v", err)
256+
s.Stop(err)
261257
}
262258
}
263259

@@ -419,7 +415,7 @@ func (s *SyncConfig) sendChangesToUpstream(changes []*fileInformation) {
419415
}
420416

421417
// Stop stops the sync process
422-
func (s *SyncConfig) Stop() {
418+
func (s *SyncConfig) Stop(fatalError error) {
423419
s.stopOnce.Do(func() {
424420
if s.upstream != nil && s.upstream.interrupt != nil {
425421
close(s.upstream.interrupt)
@@ -456,5 +452,10 @@ func (s *SyncConfig) Stop() {
456452
}
457453

458454
s.Logln("[Sync] Sync stopped")
455+
456+
if fatalError != nil {
457+
s.log.Error(fatalError)
458+
log.Fatal(fatalError)
459+
}
459460
})
460461
}

0 commit comments

Comments
 (0)