-
Notifications
You must be signed in to change notification settings - Fork 787
/
common_app.go
73 lines (68 loc) · 2.19 KB
/
common_app.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
package cmd
import (
"fmt"
"github.com/pkg/errors"
jenkinsv1 "github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/extensions"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GetDevEnv gets the Development Enviornment CRD as devEnv,
// and also tells the user whether the development environment is using gitOps
func (o *CommonOptions) GetDevEnv() (gitOps bool, devEnv *jenkinsv1.Environment) {
// We're going to need to know whether the team is using GitOps for the dev env or not,
// and also access the team settings, so load those
jxClient, ns, err := o.JXClientAndDevNamespace()
if err != nil {
if o.Verbose {
log.Errorf("Error loading team settings. %v\n", err)
}
return false, &jenkinsv1.Environment{}
} else {
devEnv, err := kube.GetDevEnvironment(jxClient, ns)
if err != nil {
log.Errorf("Error loading team settings. %v\n", err)
return false, &jenkinsv1.Environment{}
}
gitOps := false
if devEnv.Spec.Source.URL != "" {
gitOps = true
}
return gitOps, devEnv
}
}
// OnAppInstall calls extensions.OnAppInstall for the current cmd, passing app and version
func (o *CommonOptions) OnAppInstall(app string, version string) error {
// Find the app metadata, if any
jxClient, ns, err := o.JXClientAndDevNamespace()
if err != nil {
return err
}
kubeClient, _, err := o.KubeClientAndDevNamespace()
if err != nil {
return err
}
certClient, err := o.CreateCertManagerClient()
if err != nil {
return err
}
selector := fmt.Sprintf("chart=%s-%s", app, version)
appList, err := jxClient.JenkinsV1().Apps(ns).List(metav1.ListOptions{
LabelSelector: selector,
})
if err != nil {
return err
}
if len(appList.Items) > 1 {
return fmt.Errorf("more than one app (%v) was found for %s", appList.Items, selector)
} else if len(appList.Items) == 1 {
versionsDir, err := o.cloneJXVersionsRepo("")
if err != nil {
return errors.Wrapf(err, "failed to clone the Jenkins X versions repository")
}
appName := appList.Items[0].Name
return extensions.OnInstallFromName(appName, jxClient, kubeClient, certClient, ns, o.Helm(), defaultInstallTimeout, versionsDir)
}
return nil
}