/
exporter_types.go
156 lines (121 loc) · 4.9 KB
/
exporter_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
package v1beta1
import (
"strconv"
harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +k8s:openapi-gen=true
// +resource:path=exporter
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories="goharbor"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.",priority=1
// +kubebuilder:printcolumn:name="Failure",type=string,JSONPath=`.status.conditions[?(@.type=="Failed")].message`,description="Human readable message describing the failure",priority=5
// Exporter is the Schema for the Exporter API.
type Exporter struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ExporterSpec `json:"spec,omitempty"`
Status harbormetav1.ComponentStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// ExporterList contains a list of Exporter.
type ExporterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Exporter `json:"items"`
}
// ExporterSpec defines the desired state of Exporter.
type ExporterSpec struct {
harbormetav1.ComponentSpec `json:",inline"`
// +kubebuilder:validation:Optional
TLS *harbormetav1.ComponentsTLSSpec `json:"tls,omitempty"`
// +kubebuilder:validation:Optional
Log ExporterLogSpec `json:"log,omitempty"`
// +kubebuilder:validation:Optional
Cache ExporterCacheSpec `json:"cache,omitempty"`
// +kubebuilder:validation:Required
Core ExporterCoreSpec `json:"core"`
// +kubebuilder:validation:Required
Database ExporterDatabaseSpec `json:"database"`
// +kubebuilder:validation:Optional
JobService *ExporterJobServiceSpec `json:"jobservice,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=8001
// +kubebuilder:validation:Minimum=1
Port int32 `json:"port,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default="/metrics"
// +kubebuilder:validation:Pattern="/.+"
Path string `json:"path,omitempty"`
// +kubebuilder:validation:Optional
Network *harbormetav1.Network `json:"network,omitempty"`
}
type ExporterCacheSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Type="string"
// +kubebuilder:validation:Pattern="([0-9]+h)?([0-9]+m)?([0-9]+s)?"
// +kubebuilder:default="30s"
// The duration to cache info from the database and core.
Duration *metav1.Duration `json:"duration,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Type="string"
// +kubebuilder:validation:Pattern="([0-9]+h)?([0-9]+m)?([0-9]+s)?"
// +kubebuilder:default="4h"
// The interval to clean the cache info from the database and core.
CleanInterval *metav1.Duration `json:"cleanInterval,omitempty"`
}
const (
defaultCacheDurationSeconds = 30
defaultCacheCleanIntervalSeconds = 4 * 60 * 60 // 4hours
baseInt10 = 10
)
func (spec *ExporterCacheSpec) GetDurationEnvVar() string {
seconds := int64(defaultCacheDurationSeconds)
if spec.Duration != nil {
seconds = int64(spec.Duration.Seconds())
}
return strconv.FormatInt(seconds, baseInt10)
}
func (spec *ExporterCacheSpec) GetCleanIntervalEnvVar() string {
seconds := int64(defaultCacheCleanIntervalSeconds)
if spec.CleanInterval != nil {
seconds = int64(spec.CleanInterval.Seconds())
}
return strconv.FormatInt(seconds, baseInt10)
}
type ExporterCoreSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern="https?://.+"
// The absolute Harbor Core URL.
URL string `json:"url"`
}
type ExporterDatabaseSpec struct {
harbormetav1.PostgresConnectionWithParameters `json:",inline"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=50
MaxIdleConnections *int32 `json:"maxIdleConnections,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=1000
MaxOpenConnections *int32 `json:"maxOpenConnections,omitempty"`
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*"
EncryptionKeyRef string `json:"encryptionKeyRef"`
}
type ExporterJobServiceSpec struct {
// +kubebuilder:validation:Optional
Redis *JobServicePoolRedisSpec `json:"redisPool,omitempty"`
}
type ExporterLogSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default="info"
Level harbormetav1.ExporterLogLevel `json:"level,omitempty"`
}
func init() { // nolint:gochecknoinits
SchemeBuilder.Register(&Exporter{}, &ExporterList{})
}