This repository has been archived by the owner on Jun 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
198 lines (164 loc) · 5.86 KB
/
types.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
/*
Copyright 2019 The GitLab-Controller Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"fmt"
"strconv"
"github.com/crossplaneio/crossplane/pkg/util"
xpcorev1alpha1 "github.com/crossplaneio/crossplane/pkg/apis/core/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ApplicationName gitlab
const ApplicationName = "gitlab"
// GitLabSpec defines the desired state of GitLab
type GitLabSpec struct {
// Domain which will contain records to resolve gitlab, registry, and minio (if enabled) to the appropriate IP
Domain string `json:"domain"`
// HostSuffix appended to domain records, i.e. `gitlab-suffix.domain`, default - no suffix
HostSuffix string `json:"hostSuffix,omitempty"`
// Protocol http or https, default - https
Protocol string `json:"protocol,omitempty"`
// Port gitlab service port, default - none
Port uint `json:"port,omitempty"`
// Email address to register TLS certificates
Email string `json:"email"`
// ProviderRef cloud provider reference
ProviderRef corev1.ObjectReference `json:"providerRef"`
// ReclaimPolicy controls application cleanup
ReclaimPolicy xpcorev1alpha1.ReclaimPolicy `json:"reclaimPolicy,omitempty"`
// ClusterRef to a target kubernetes cluster where a GitLab controller will
// deploy GitLab application components
ClusterRef *corev1.ObjectReference `json:"clusterRef,omitempty"`
// ClusterNamespace
ClusterNamespace string `json:"clusterNamespace,omitempty"`
}
// GitLabStatus defines the observed state of GitLab
type GitLabStatus struct {
xpcorev1alpha1.ConditionedStatus
// Endpoint for GitLab service
Endpoint string `json:"endpoint,omitempty"`
// State of the GitLab service - string representation of the latest active condition
// This is provided for convenience for displaying status gitlab
State xpcorev1alpha1.ConditionType `json:"state,omitempty"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// GitLab is the Schema for the gitlabs API
// +k8s:openapi-gen=true
// +groupName=gitlab
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.state"
// +kubebuilder:printcolumn:name="ENDPOINT",type="string",JSONPath=".status.endpoint"
type GitLab struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec GitLabSpec `json:"spec,omitempty"`
Status GitLabStatus `json:"status,omitempty"`
}
// GetApplicationName returns "gitlab[-suffix]" if host suffix is provided
func (in *GitLab) GetApplicationName() string {
if sfx := in.Spec.HostSuffix; sfx != "" {
return ApplicationName + "-" + sfx
}
return ApplicationName
}
// GetClusterNamespace spec property
func (in *GitLab) GetClusterNamespace() string {
if in.Spec.ClusterNamespace == "" {
return "default"
}
return in.Spec.ClusterNamespace
}
// GetClusterRef spec property
func (in *GitLab) GetClusterRef() *corev1.ObjectReference {
return in.Spec.ClusterRef
}
// GetEndpoint returns a gitlab service endpoint
func (in *GitLab) GetEndpoint() string {
f := func(a, b string) string {
if a == "" {
return b
}
return a
}
protocol := f(in.Spec.Protocol, "https")
suffix := f(in.Spec.HostSuffix, "")
if suffix != "" {
suffix = "-" + suffix
}
port := ""
if in.Spec.Port != 0 {
port = ":" + strconv.Itoa(int(in.Spec.Port))
}
return fmt.Sprintf("%s://gitlab%s.%s%s", protocol, suffix, in.Spec.Domain, port)
}
// GetProviderRef spec property
func (in *GitLab) GetProviderRef() corev1.ObjectReference {
return in.Spec.ProviderRef
}
// IsReclaimDelete tests reclaim delete policy
func (in *GitLab) IsReclaimDelete() bool {
return in.Spec.ReclaimPolicy == xpcorev1alpha1.ReclaimDelete
}
// SetCreating a convenience method to set object status
func (in *GitLab) SetCreating() {
in.Status.SetCreating()
in.Status.State = xpcorev1alpha1.Creating
}
// SetDeleting a convenience method to set object status
func (in *GitLab) SetDeleting() {
in.Status.SetDeleting()
in.Status.State = xpcorev1alpha1.Deleting
}
// SetFailed a convenience method to set object status
func (in *GitLab) SetFailed(reason, msg string) {
in.Status.SetFailed(reason, msg)
in.Status.State = xpcorev1alpha1.Failed
}
// SetPending status with reason and message
func (in *GitLab) SetPending(reason, msg string) {
if !in.Status.IsCondition(xpcorev1alpha1.Pending) {
in.Status.UnsetAllConditions()
in.Status.SetCondition(xpcorev1alpha1.NewCondition(xpcorev1alpha1.Pending, reason, msg))
}
in.Status.State = xpcorev1alpha1.Pending
}
// SetReady a convenience method to set object status
func (in *GitLab) SetReady() {
if !in.Status.IsReady() {
in.Status.UnsetAllConditions()
in.Status.SetReady()
}
in.Status.State = xpcorev1alpha1.Ready
}
// SetEndpoint for this GitLab instance
func (in *GitLab) SetEndpoint(ep string) {
in.Status.Endpoint = ep
}
// ToOwnerReference converts this object metadata to a new owner reference
func (in *GitLab) ToOwnerReference() metav1.OwnerReference {
return metav1.OwnerReference{
APIVersion: util.IfEmptyString(in.APIVersion, APIVersion),
Kind: util.IfEmptyString(in.Kind, GitLabKind),
Name: in.Name,
UID: in.UID,
}
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// GitLabList contains a list of GitLab
type GitLabList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitLab `json:"items"`
}