-
Notifications
You must be signed in to change notification settings - Fork 786
/
common_environments.go
40 lines (36 loc) · 1.2 KB
/
common_environments.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
package cmd
import (
"fmt"
jenkinsv1 "github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/client/clientset/versioned"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/pkg/errors"
)
func (o *CommonOptions) registerEnvironmentCRD() error {
apisClient, err := o.ApiExtensionsClient()
if err != nil {
return err
}
err = kube.RegisterEnvironmentCRD(apisClient)
return err
}
// modifyDevEnvironment performs some mutation on the Development environemnt to modify team settings
func (o *CommonOptions) modifyDevEnvironment(jxClient versioned.Interface, ns string,
fn func(env *jenkinsv1.Environment) error) error {
env, err := kube.EnsureDevEnvironmentSetup(jxClient, ns)
if err != nil {
return errors.Wrapf(err, "failed to ensure that dev environment is setup for namespace '%s'", ns)
}
if env == nil {
return fmt.Errorf("No Development environment found in namespace %s", ns)
}
err = fn(env)
if err != nil {
return errors.Wrap(err, "failed to call the callback function for dev environment")
}
_, err = jxClient.JenkinsV1().Environments(ns).Update(env)
if err != nil {
return fmt.Errorf("Failed to update Development environment in namespace %s: %s", ns, err)
}
return nil
}