/
nats_types.go
92 lines (78 loc) · 3.01 KB
/
nats_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
package v1beta1
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +kubebuilder:validation:Enum=password;nkey
type NatsAuthMethod string
const (
NatsAuthPassword NatsAuthMethod = "password"
NatsAuthNkey NatsAuthMethod = "nkey"
)
type NatsClusterState string
const (
NatsClusterStateError NatsClusterState = "Error"
NatsClusterStateWorking NatsClusterState = "Working"
NatsClusterStateReady NatsClusterState = "Ready"
)
type PVCSource struct {
StorageClassName *string `json:"storageClass,omitempty"`
AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"`
}
type JetStreamPersistenceSpec struct {
PVC *PVCSource `json:"pvc,omitempty"`
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
}
type FileStorageSpec struct {
JetStreamPersistenceSpec `json:",inline"`
Enabled *bool `json:"enabled,omitempty"`
Size resource.Quantity `json:"size,omitempty"`
}
type JetStreamSpec struct {
Enabled *bool `json:"enabled,omitempty"`
MemoryStorageSize resource.Quantity `json:"memoryStorageSize,omitempty"`
FileStorage FileStorageSpec `json:"fileStorage,omitempty"`
}
type NatsSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:default:=password
AuthMethod NatsAuthMethod `json:"authMethod,omitempty"`
// Username to use for authentication, if username auth is specified in
// AuthMethod. If empty, defaults to "nats-user". If AuthMethod is "nkey",
// this field is ignored.
Username string `json:"username,omitempty"`
// Number of nats server replicas. If not set, defaults to 3.
Replicas *int32 `json:"replicas,omitempty"`
// A secret containing a "password" item. This secret must already exist
// if specified.
PasswordFrom *corev1.SecretKeySelector `json:"passwordFrom,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
JetStream JetStreamSpec `json:"jetStream,omitempty"`
}
type NatsStatus struct {
State NatsClusterState `json:"state,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
AuthSecretKeyRef *corev1.SecretKeySelector `json:"authSecretKeyRef,omitempty"`
NKeyUser string `json:"nkeyUser,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type NatsCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NatsSpec `json:"spec,omitempty"`
Status NatsStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
type NatsClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NatsCluster `json:"items"`
}
func init() {
SchemeBuilder.Register(
&NatsCluster{}, &NatsClusterList{},
)
}