-
Notifications
You must be signed in to change notification settings - Fork 53
/
meta.go
126 lines (107 loc) · 3.14 KB
/
meta.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
// +kubebuilder:object:generate=true
// meta package contains generic kubernetes type implementations for Opni.
package meta
import (
"fmt"
"path"
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
)
const (
OpensearchFinalizer = "opni.io/opensearch"
)
type LogLevel string
const (
LogLevelDebug LogLevel = "debug"
LogLevelInfo LogLevel = "info"
LogLevelWarn LogLevel = "warn"
LogLevelError LogLevel = "error"
)
type ImageSpec struct {
Image *string `json:"image,omitempty"`
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}
func (s ImageSpec) GetImagePullPolicy() (_ corev1.PullPolicy) {
if p := s.ImagePullPolicy; p != nil {
return *p
}
return
}
func (s ImageSpec) GetImage() string {
if s.Image == nil {
return ""
}
return *s.Image
}
func (s *ImageSpec) GetImageWithDefault(def string) string {
if s == nil || s.Image == nil {
return def
}
return *s.Image
}
type ImageResolver struct {
Version string
ImageName string
DefaultRepo string
DefaultRepoOverride *string
ImageOverride *ImageSpec
}
func (r ImageResolver) Resolve() (result ImageSpec) {
// If a custom image is specified, use it.
if r.ImageOverride != nil {
if r.ImageOverride.ImagePullPolicy != nil {
result.ImagePullPolicy = r.ImageOverride.ImagePullPolicy
}
if len(r.ImageOverride.ImagePullSecrets) > 0 {
result.ImagePullSecrets = r.ImageOverride.ImagePullSecrets
}
if r.ImageOverride.Image != nil {
// If image is set, nothing else needs to be done
result.Image = r.ImageOverride.Image
return
}
}
// If a different image repo is requested, use that with the default image
// name and version tag.
defaultRepo := r.DefaultRepo
if r.DefaultRepoOverride != nil {
defaultRepo = *r.DefaultRepoOverride
}
version := r.Version
if r.Version == "" {
version = "latest"
}
result.Image = lo.ToPtr(fmt.Sprintf("%s:%s",
path.Join(defaultRepo, r.ImageName), version))
return
}
type PrometheusReference struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
type PersistenceSpec struct {
Enabled bool `json:"enabled,omitempty"`
StorageClassName *string `json:"storageClass,omitempty"`
AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"`
// Storage size request. Defaults to 10Gi.
Request resource.Quantity `json:"request,omitempty"`
}
type ExtraVolumeMount struct {
Name string `json:"name,omitempty"`
MountPath string `json:"mountPath,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
corev1.VolumeSource `json:",inline"`
}
type OpensearchClusterRef struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
func (o *OpensearchClusterRef) ObjectKeyFromRef() types.NamespacedName {
return types.NamespacedName{
Name: o.Name,
Namespace: o.Namespace,
}
}