-
Notifications
You must be signed in to change notification settings - Fork 1
/
crds.go
85 lines (74 loc) · 2.7 KB
/
crds.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
package kube
import (
jenkinsio "github.com/jenkins-x/jx/pkg/apis/jenkins.io"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// RegisterEnvironmentCRD ensures that the CRD is registered for Environments
func RegisterEnvironmentCRD(apiClient *apiextensionsclientset.Clientset) error {
name := "environments." + jenkinsio.GroupName
names := &v1beta1.CustomResourceDefinitionNames{
Kind: "Environment",
ListKind: "EnvironmentList",
Plural: "environments",
Singular: "environment",
ShortNames: []string{"env"},
}
return registerCRD(apiClient, name, names)
}
// RegisterGitServiceCRD ensures that the CRD is registered for GitServices
func RegisterGitServiceCRD(apiClient *apiextensionsclientset.Clientset) error {
name := "gitservices." + jenkinsio.GroupName
names := &v1beta1.CustomResourceDefinitionNames{
Kind: "GitService",
ListKind: "GitServiceList",
Plural: "gitservices",
Singular: "gitservice",
ShortNames: []string{"gits"},
}
return registerCRD(apiClient, name, names)
}
// RegisterPipelineActivityCRD ensures that the CRD is registered for PipelineActivity
func RegisterPipelineActivityCRD(apiClient *apiextensionsclientset.Clientset) error {
name := "pipelineactivities." + jenkinsio.GroupName
names := &v1beta1.CustomResourceDefinitionNames{
Kind: "PipelineActivity",
ListKind: "PipelineActivityList",
Plural: "pipelineactivities",
Singular: "pipelineactivity",
ShortNames: []string{"activity", "act"},
}
return registerCRD(apiClient, name, names)
}
// RegisterReleaseCRD ensures that the CRD is registered for Release
func RegisterReleaseCRD(apiClient *apiextensionsclientset.Clientset) error {
name := "releases." + jenkinsio.GroupName
names := &v1beta1.CustomResourceDefinitionNames{
Kind: "Release",
ListKind: "ReleaseList",
Plural: "releases",
Singular: "release",
ShortNames: []string{"rel"},
}
return registerCRD(apiClient, name, names)
}
func registerCRD(apiClient *apiextensionsclientset.Clientset, name string, names *v1beta1.CustomResourceDefinitionNames) error {
_, err := apiClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(name, metav1.GetOptions{})
if err == nil {
return nil
}
crd := &v1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1beta1.CustomResourceDefinitionSpec{
Group: jenkinsio.GroupName,
Version: jenkinsio.Version,
Scope: v1beta1.NamespaceScoped,
Names: *names,
},
}
_, err = apiClient.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
return err
}