-
Notifications
You must be signed in to change notification settings - Fork 784
/
boot.go
597 lines (509 loc) · 20.9 KB
/
boot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
package boot
import (
"fmt"
"os"
"path/filepath"
"github.com/google/uuid"
"github.com/jenkins-x/jx/v2/pkg/versionstream"
"github.com/jenkins-x/jx/v2/pkg/boot"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/namespace"
"github.com/jenkins-x/jx/v2/pkg/cmd/step/create"
"github.com/jenkins-x/jx/v2/pkg/config"
"github.com/jenkins-x/jx/v2/pkg/gits"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
)
// BootOptions options for the command
type BootOptions struct {
*opts.CommonOptions
Dir string
GitURL string
GitRef string
StartStep string
EndStep string
HelmLogLevel string
// The bootstrap URL for the version stream. Once we have a jx-requirements.yml files, we read that
VersionStreamURL string
// The bootstrap ref for the version stream. Once we have a jx-requirements.yml, we read that
VersionStreamRef string
// RequirementsFile provided by the user to override the default requirements file from repository
RequirementsFile string
AttemptRestore bool
// UpgradeGit if we want to automatically upgrade this boot clone if there have been changes since the current clone
NoUpgradeGit bool
}
var (
bootLong = templates.LongDesc(`
Boots up Jenkins X in a Kubernetes cluster using GitOps and a Jenkins X Pipeline
For more documentation see: [https://jenkins-x.io/docs/getting-started/setup/boot/](https://jenkins-x.io/docs/getting-started/setup/boot/)
`)
bootExample = templates.Examples(`
# create a kubernetes cluster via Terraform or via jx
jx create cluster gke --skip-installation
# now lets boot up Jenkins X installing/upgrading whatever is needed
jx boot
# if we have already booted and just want to apply some environment changes without
# re-applying ingress and so forth we can start at the environment step:
jx boot --start-step install-env
`)
)
// NewCmdBoot creates the command
func NewCmdBoot(commonOpts *opts.CommonOptions) *cobra.Command {
options := &BootOptions{
CommonOptions: commonOpts,
}
cmd := &cobra.Command{
Use: "boot",
Aliases: []string{"bootstrap"},
Short: "Boots up Jenkins X in a Kubernetes cluster using GitOps and a Jenkins X Pipeline",
Long: bootLong,
Example: bootExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
cmd.Flags().StringVarP(&options.Dir, "dir", "d", ".", "the directory to look for the Jenkins X Pipeline, requirements and charts")
cmd.Flags().StringVarP(&options.GitURL, "git-url", "u", "", "override the Git clone URL for the JX Boot source to start from, ignoring the versions stream. Normally specified with git-ref as well")
cmd.Flags().StringVarP(&options.GitRef, "git-ref", "", "", "override the Git ref for the JX Boot source to start from, ignoring the versions stream. Normally specified with git-url as well")
cmd.Flags().StringVarP(&options.VersionStreamURL, "versions-repo", "", config.DefaultVersionsURL, "the bootstrap URL for the versions repo. Once the boot config is cloned, the repo will be then read from the jx-requirements.yml")
cmd.Flags().StringVarP(&options.VersionStreamRef, "versions-ref", "", config.DefaultVersionsRef, "the bootstrap ref for the versions repo. Once the boot config is cloned, the repo will be then read from the jx-requirements.yml")
cmd.Flags().StringVarP(&options.StartStep, "start-step", "s", "", "the step in the pipeline to start from")
cmd.Flags().StringVarP(&options.EndStep, "end-step", "e", "", "the step in the pipeline to end at")
cmd.Flags().StringVarP(&options.HelmLogLevel, "helm-log", "v", "", "sets the helm logging level from 0 to 9. Passed into the helm CLI via the '-v' argument. Useful to diagnose helm related issues")
cmd.Flags().StringVarP(&options.RequirementsFile, "requirements", "r", "", "requirements file which will overwrite the default requirements file")
cmd.Flags().BoolVarP(&options.AttemptRestore, "attempt-restore", "a", false, "attempt to boot from an existing dev environment repository")
cmd.Flags().BoolVarP(&options.NoUpgradeGit, "no-update-git", "", false, "disables any attempt to update the local git clone if its old")
return cmd
}
// Run runs this command
func (o *BootOptions) Run() error {
err := o.verifyClusterConnection()
if err != nil {
return err
}
o.overrideSteps()
if o.AttemptRestore {
err := o.restoreFromDevEnvRepo()
if err != nil {
return errors.Wrapf(err, "unable tp restore dev environment repo")
}
}
gitURL, gitRef := o.determineGitURLAndRef()
if gitURL == "" {
return util.MissingOption("git-url")
}
isBootClone, err := existingBootClone(o.Dir)
if err != nil {
return errors.Wrapf(err, "failed to check if this is an existing boot clone")
}
isGitRepo := o.isGitRepo(o.Dir)
if isGitRepo && !isBootClone {
return errors.Errorf("trying to execute 'jx boot' from a non requirements repo")
}
if !isBootClone {
gitInfo, err := gits.ParseGitURL(gitURL)
if err != nil {
return errors.Wrapf(err, "failed to parse git URL %s", gitURL)
}
dir := filepath.Join(o.Dir, gitInfo.Name)
cloneDir, err := o.createBootClone(gitURL, gitRef, dir)
if err != nil {
return errors.Wrapf(err, "unable to clone %s", gitURL)
}
o.Dir = cloneDir
}
requirements, requirementsFile, err := config.LoadRequirementsConfig(o.Dir, config.DefaultFailOnValidationError)
if err != nil {
return errors.Wrapf(err, "unable to load %s", config.RequirementsConfigFileName)
}
err = o.ConfigureCommonOptions(requirements)
if err != nil {
return err
}
// lets report errors parsing this file after the check we are outside of a git clone
o.defaultVersionStream(requirements)
resolver, err := o.CreateVersionResolver(requirements.VersionStream.URL, requirements.VersionStream.Ref)
if err != nil {
return errors.Wrapf(err, "there was a problem creating a version resolver from versions stream repository %s and ref %s", requirements.VersionStream.URL, requirements.VersionStream.Ref)
}
// lets avoid trying to reset the current git clone to master if using NoUpgradeGit
if o.GitRef == "" && !o.NoUpgradeGit {
gitRef, err = o.determineGitRef(resolver, requirements, gitURL)
if err != nil {
return errors.Wrapf(err, "failed to determine git ref")
}
}
projectConfig, pipelineFile, err := config.LoadProjectConfig(o.Dir)
if err != nil {
return err
}
if err := o.overrideRequirements(gitURL); err != nil {
return errors.Wrap(err, "overwriting the default requirements")
}
// only update boot if the a GitRef has not been supplied
if o.GitRef == "" && !o.NoUpgradeGit {
err = o.updateBootCloneIfOutOfDate(gitRef)
if err != nil {
return err
}
}
err = o.verifyRequirements(requirements, requirementsFile)
if err != nil {
return err
}
log.Logger().Infof("Booting Jenkins X")
// now lets really boot
_, so := create.NewCmdStepCreateTaskAndOption(o.CommonOptions)
so.CloneDir = o.Dir
so.CloneDir = o.Dir
so.InterpretMode = true
so.NoReleasePrepare = true
so.StartStep = o.StartStep
so.EndStep = o.EndStep
so.AdditionalEnvVars = map[string]string{
"JX_NO_TILLER": "true",
boot.ConfigRepoURLEnvVarName: gitURL,
boot.ConfigBaseRefEnvVarName: gitRef,
boot.VersionsRepoURLEnvVarName: requirements.VersionStream.URL,
boot.VersionsRepoBaseRefEnvVarName: requirements.VersionStream.Ref,
}
if o.NoUpgradeGit {
so.AdditionalEnvVars[boot.DisablePushUpdatesToDevEnvironment] = "true"
}
if requirements.Cluster.HelmMajorVersion == "3" {
so.AdditionalEnvVars["JX_HELM3"] = "true"
} else {
so.AdditionalEnvVars["JX_NO_TILLER"] = "true"
}
if o.HelmLogLevel != "" {
so.AdditionalEnvVars["JX_HELM_VERBOSE"] = o.HelmLogLevel
}
// Set the namespace in the pipeline
so.CommonOptions.SetDevNamespace(requirements.Cluster.Namespace)
// lets ensure the namespace is set in the jenkins-x.yml file
envVars := make([]v1.EnvVar, 0)
for _, e := range projectConfig.PipelineConfig.Pipelines.Release.Pipeline.Environment {
if e.Name == "DEPLOY_NAMESPACE" {
envVars = append(envVars, v1.EnvVar{
Name: "DEPLOY_NAMESPACE",
Value: requirements.Cluster.Namespace,
})
} else {
envVars = append(envVars, e)
}
}
projectConfig.PipelineConfig.Pipelines.Release.Pipeline.Environment = envVars
err = projectConfig.SaveConfig(pipelineFile)
if err != nil {
return errors.Wrapf(err, "setting namespace in jenkins-x.yml")
}
so.VersionResolver = resolver
if o.BatchMode {
so.AdditionalEnvVars["JX_BATCH_MODE"] = "true"
}
err = so.Run()
if err != nil {
return errors.Wrapf(err, "failed to interpret pipeline file %s", pipelineFile)
}
log.Logger().Debugf("Using additional vars: %+v", so.AdditionalEnvVars)
// lets switch kubernetes context to it so the user can use `jx` commands immediately
no := &namespace.NamespaceOptions{}
no.CommonOptions = o.CommonOptions
no.Args = []string{requirements.Cluster.Namespace}
return no.Run()
}
func (o *BootOptions) isGitRepo(dir string) bool {
_, _, err := gits.GetGitInfoFromDirectory(dir, o.Git())
if err == nil {
return true
}
return false
}
func (o *BootOptions) determineGitURLAndRef() (string, string) {
gitURL, gitRef, err := gits.GetGitInfoFromDirectory(o.Dir, o.Git())
if err != nil {
log.Logger().Info("Creating boot config with defaults, as not in an existing boot directory with a git repository.")
gitURL = config.DefaultBootRepository
gitRef = config.DefaultVersionsRef
}
if o.GitURL != "" {
log.Logger().Infof("GitURL provided, overriding the current value: %s with %s", util.ColorInfo(gitURL), util.ColorInfo(o.GitURL))
gitURL = o.GitURL
}
if o.GitRef != "" {
log.Logger().Infof("GitRef provided, overriding the current value: %s with %s", util.ColorInfo(gitRef), util.ColorInfo(o.GitRef))
gitRef = o.GitRef
}
return gitURL, gitRef
}
func (o *BootOptions) createBootClone(bootConfigGitURL string, bootConfigGitRef string, cloneDir string) (string, error) {
info := util.ColorInfo
log.Logger().Infof("No Jenkins X pipeline file %s or no jx boot requirements file %s found. You are not running this command from inside a "+
"Jenkins X Boot git clone", info(config.ProjectConfigFileName), info(config.RequirementsConfigFileName))
if !o.BatchMode {
log.Logger().Infof("To continue we will clone %s @ %s to %s", info(bootConfigGitURL), info(bootConfigGitRef), info(cloneDir))
help := "A git clone of a Jenkins X Boot source repository is required for 'jx boot'"
message := "Do you want to clone the Jenkins X Boot Git repository?"
if answer, err := util.Confirm(message, true, help, o.GetIOFileHandles()); err != nil {
return "", errors.Wrapf(err, "unable to process user input")
} else if !answer {
return "", fmt.Errorf("please run this command again inside a git clone from a Jenkins X Boot repository")
}
}
bootCloneExists, err := util.DirExists(cloneDir)
if err != nil {
return "", errors.Wrapf(err, "unable to check whether directory %s exists", cloneDir)
}
if bootCloneExists {
return "", fmt.Errorf("cannot clone git repository to %s as the dir already exists", cloneDir)
}
log.Logger().Infof("Cloning %s @ %s to %s\n", info(bootConfigGitURL), info(bootConfigGitRef), info(cloneDir))
err = os.MkdirAll(cloneDir, util.DefaultWritePermissions)
if err != nil {
return "", errors.Wrapf(err, "failed to create directory: %s", cloneDir)
}
err = o.Git().Clone(bootConfigGitURL, cloneDir)
if err != nil {
return "", errors.Wrapf(err, "failed to clone git URL %s to directory: %s", bootConfigGitURL, cloneDir)
}
commitish, err := gits.FindTagForVersion(cloneDir, bootConfigGitRef, o.Git())
if err != nil {
log.Logger().Debugf(errors.Wrapf(err, "finding tag for %s", bootConfigGitRef).Error())
}
if commitish != "" {
err = o.Git().Reset(cloneDir, commitish, true)
if err != nil {
return "", errors.Wrapf(err, "setting HEAD to %s", commitish)
}
} else {
log.Logger().Debugf("fetching branch %s", bootConfigGitRef)
err = o.Git().FetchBranch(cloneDir, "origin", bootConfigGitRef)
if err != nil {
return "", errors.Wrapf(err, "fetching branch %s", bootConfigGitRef)
}
branchName := uuid.New().String()
err = o.Git().CreateBranchFrom(cloneDir, branchName, bootConfigGitRef)
if err != nil {
return "", errors.Wrapf(err, "create branch %s from %s", branchName, bootConfigGitRef)
}
err = o.Git().Checkout(cloneDir, branchName)
if err != nil {
return "", errors.Wrapf(err, "checkout branch %s", branchName)
}
}
cloneDir, err = filepath.Abs(cloneDir)
if err != nil {
return "", errors.Wrapf(err, "unable to determine absolute path for %s", cloneDir)
}
return cloneDir, nil
}
func (o *BootOptions) restoreFromDevEnvRepo() error {
url := o.determineDevEnvironmentUrl()
if url != "" {
cloned, dir, err := o.cloneDevEnvironment(url)
if err != nil {
return err
}
if cloned {
err = os.Chdir(dir)
if err != nil {
return errors.Wrapf(err, "failed to change into new directory: %s", dir)
}
} else {
log.Logger().Infof("failed to clone dev environment booting from %s", o.GitURL)
}
} else {
log.Logger().Infof("cannot determine dev environment url booting from %s", o.GitURL)
}
return nil
}
func (o *BootOptions) determineDevEnvironmentUrl() string {
gitProvider := os.Getenv("JX_VALUE_GITPROVIDER")
gitOwner := os.Getenv(config.RequirementEnvGitOwner)
clusterName := os.Getenv(config.RequirementClusterName)
if gitProvider != "" && gitOwner != "" && clusterName != "" {
repo := fmt.Sprintf("environment-%s-dev", clusterName)
repoName := o.Git().RepoName(gitOwner, repo)
url := fmt.Sprintf("https://%s.com/%s", gitProvider, repoName)
log.Logger().Infof("dev environment url is %s", url)
return url
}
return ""
}
func (o *BootOptions) cloneDevEnvironment(gitURL string) (bool, string, error) {
log.Logger().Infof("dev environment url specified %t ", o.AttemptRestore)
gitInfo, err := gits.ParseGitURL(gitURL)
if err != nil {
return false, "", errors.Wrapf(err, "failed to parse git URL %s", gitURL)
}
repo := gitInfo.Name
cloneDir := filepath.Join(o.Dir, repo)
err = os.MkdirAll(cloneDir, util.DefaultWritePermissions)
if err != nil {
return false, "", errors.Wrapf(err, "failed to create directory: %s", cloneDir)
}
err = o.Git().Clone(gitURL, cloneDir)
if err != nil {
log.Logger().Infof("failed to clone git URL %s to directory: %s", gitURL, cloneDir)
rmErr := os.RemoveAll(cloneDir)
if rmErr != nil {
log.Logger().Warnf("Unable to remove dev env directory")
}
return false, "", nil
}
return true, cloneDir, nil
}
func (o *BootOptions) updateBootCloneIfOutOfDate(gitRef string) error {
// Get the tag corresponding to the git ref.
commitish, err := gits.FindTagForVersion(o.Dir, gitRef, o.Git())
if err != nil {
log.Logger().Debugf(errors.Wrapf(err, "finding tag for %s", gitRef).Error())
commitish = fmt.Sprintf("%s/%s", "origin", gitRef)
}
// Check if the current HEAD is an ancestor of the tag.
isAncestor, err := o.Git().IsAncestor(o.Dir, "HEAD", commitish)
if err != nil {
log.Logger().Debugf(errors.Wrapf(err, "couldn't determine whether HEAD is an ancestor of %s", commitish).Error())
}
// Get the tag on the current boot clone HEAD, if any.
resolved, _, err := o.Git().Describe(o.Dir, true, "HEAD", "0", true)
if err != nil {
return errors.Wrap(err, "could not describe boot clone HEAD to find its tag with git describe HEAD --abbrev=0 --contains --always")
}
if resolved != commitish {
if isAncestor {
log.Logger().Infof("Local boot clone is out of date. It is based on %s, but the version stream is using %s. The clone will now be updated to %s.",
resolved, commitish, commitish)
log.Logger().Info("Stashing any changes made in local boot clone.")
err = o.Git().StashPush(o.Dir)
if err != nil {
return errors.WithStack(err)
}
err = o.Git().Reset(o.Dir, commitish, true)
if err != nil {
return errors.Wrapf(err, "Could not reset local boot clone to %s", commitish)
}
err = o.Git().StashPop(o.Dir)
if err != nil && !gits.IsNoStashEntriesError(err) { // Ignore no stashes as that's just because there was nothing to stash
return fmt.Errorf("Could not update local boot clone due to conflicts between local changes and %s.\n"+
"To fix this, resolve the conflicts listed below manually, run 'git reset HEAD', and run 'jx boot' again.\n%s",
commitish, gits.GetSimpleIndentedStashPopErrorMessage(err))
}
} else {
log.Logger().Infof("Current HEAD %s in %s is not an ancestor of %s, the boot config version from the version stream.\n"+
"Proceeding with current HEAD.", resolved, o.Dir, commitish)
return nil
}
}
return nil
}
func existingBootClone(dir string) (bool, error) {
pipelineExists, err := util.FileExists(filepath.Join(dir, config.ProjectConfigFileName))
if err != nil {
return false, err
}
requirementsExist, err := util.FileExists(filepath.Join(dir, config.RequirementsConfigFileName))
if err != nil {
return false, err
}
return requirementsExist && pipelineExists, nil
}
func (o *BootOptions) overrideRequirements(defaultBootConfigURL string) error {
requirements, requirementsFile, err := config.LoadRequirementsConfig(o.Dir, config.DefaultFailOnValidationError)
if err != nil {
return errors.Wrapf(err, "loading requirements from dir %q", o.Dir)
}
// overwrite the default requirements with provided requirements
if o.RequirementsFile != "" {
providedRequirements, err := config.LoadRequirementsConfigFile(o.RequirementsFile, config.DefaultFailOnValidationError)
if err != nil {
return errors.Wrapf(err, "loading requirements from file %q", o.RequirementsFile)
}
*requirements = *providedRequirements
}
o.defaultVersionStream(requirements)
if requirements.BootConfigURL == "" {
requirements.BootConfigURL = defaultBootConfigURL
}
if err := requirements.SaveConfig(requirementsFile); err != nil {
return errors.Wrapf(err, "saving the requirements into file %q", requirementsFile)
}
return nil
}
func (o *BootOptions) determineGitRef(resolver *versionstream.VersionResolver, requirements *config.RequirementsConfig, gitURL string) (string, error) {
// If the GitRef is not overridden and is set to it's default value then look up the version number
log.Logger().Infof("Attempting to resolve version for boot config %s from %s", util.ColorInfo(gitURL), util.ColorInfo(requirements.VersionStream.URL))
gitRef, err := resolver.ResolveGitVersion(gitURL)
if err != nil {
return "", errors.Wrapf(err, fmt.Sprintf("failed to resolve version for %s in version stream %s",
gitURL, requirements.VersionStream.URL))
}
if gitRef == "" {
log.Logger().Infof("no version for %s found in version stream %s, defaulting to %s",
util.ColorInfo(gitURL), util.ColorInfo(requirements.VersionStream.URL), util.ColorInfo("master"))
gitRef = "master"
}
return gitRef, nil
}
func (o *BootOptions) defaultVersionStream(requirements *config.RequirementsConfig) {
if requirements.VersionStream.URL == "" && requirements.VersionStream.Ref == "" {
requirements.VersionStream.URL = o.VersionStreamURL
requirements.VersionStream.Ref = o.VersionStreamRef
}
// If we still don't have a complete version stream ref then we better set to a default
if requirements.VersionStream.URL == "" || requirements.VersionStream.Ref == "" {
log.Logger().Warnf("Incomplete version stream reference %s @ %s", requirements.VersionStream.URL, requirements.VersionStream.Ref)
o.VersionStreamRef = config.DefaultVersionsRef
o.VersionStreamURL = config.DefaultVersionsURL
requirements.VersionStream.URL = o.VersionStreamURL
requirements.VersionStream.Ref = o.VersionStreamRef
log.Logger().Infof("Setting version stream reference to default %s @ %s", requirements.VersionStream.URL, requirements.VersionStream.Ref)
}
}
func (o *BootOptions) verifyRequirements(requirements *config.RequirementsConfig, requirementsFile string) error {
provider := requirements.Cluster.Provider
if provider == "" {
return config.MissingRequirement("provider", requirementsFile)
}
if requirements.Cluster.Namespace == "" {
return config.MissingRequirement("namespace", requirementsFile)
}
return nil
}
func (o *BootOptions) verifyClusterConnection() error {
client, ns, err := o.KubeClientAndNamespace()
if err == nil {
_, err = client.CoreV1().Pods(ns).List(metav1.ListOptions{})
}
if err != nil {
return fmt.Errorf("You are not currently connected to a cluster, please connect to the cluster that you intend to %s\n"+
"Alternatively create a new cluster using %s", util.ColorInfo("jx boot"), util.ColorInfo("jx create cluster"))
}
return nil
}
func (o *BootOptions) overrideSteps() {
if o.StartStep == "" {
startStep := os.Getenv("JX_BOOT_START_STEP")
if startStep != "" {
log.Logger().Debugf("Overriding start-step with env var: '%s'", startStep)
o.StartStep = startStep
}
}
if o.EndStep == "" {
endStep := os.Getenv("JX_BOOT_END_STEP")
if endStep != "" {
log.Logger().Debugf("Overriding end-step with env var: '%s'", endStep)
o.EndStep = endStep
}
}
}