forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teams.go
66 lines (59 loc) · 1.79 KB
/
teams.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
package kube
import (
"sort"
"strings"
"github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
// GetAdminNamespace tries to find the namespace which is annotated as the global admin namespace for the cluster
// or returns the current namespace
func GetAdminNamespace(kubeClient kubernetes.Interface, ns string) (string, error) {
// TODO find the admin namespace via a label on the current dev namespace - or use current?
return ns, nil
}
// GetPendingTeams returns the pending teams with the sorted order of names
func GetPendingTeams(jxClient versioned.Interface, ns string) (map[string]*v1.Team, []string, error) {
m := map[string]*v1.Team{}
names := []string{}
teamList, err := jxClient.JenkinsV1().Teams(ns).List(metav1.ListOptions{})
if err != nil {
return m, names, err
}
for _, team := range teamList.Items {
n := team.Name
copy := team
m[n] = ©
if n != "" {
names = append(names, n)
}
}
sort.Strings(names)
return m, names, nil
}
// CreateTeam creates a new default Team
func CreateTeam(ns string, name string, members []string) *v1.Team {
kind := v1.TeamKindTypeCD
team := &v1.Team{
ObjectMeta: metav1.ObjectMeta{
Name: ToValidName(name),
Namespace: ns,
},
Spec: v1.TeamSpec{
Label: strings.Title(name),
Members: members,
Kind: kind,
},
}
return team
}
// DeleteTeam deletes the team resource but does not uninstall the underlying namespaces
func DeleteTeam(jxClient versioned.Interface, ns string, teamName string) error {
teamInterface := jxClient.JenkinsV1().Teams(ns)
_, err := teamInterface.Get(teamName, metav1.GetOptions{})
if err == nil {
err = teamInterface.Delete(teamName, nil)
}
return err
}