-
Notifications
You must be signed in to change notification settings - Fork 2
/
corsproxy_types.go
174 lines (154 loc) · 6.72 KB
/
corsproxy_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
/*
Copyright 2021.
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 (
"github.com/3scale-ops/basereconciler/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
var (
corsproxyDefaultReplicas int32 = 2
corsproxyDefaultImage defaultImageSpec = defaultImageSpec{
Name: util.Pointer("quay.io/3scale/cors-proxy"),
Tag: util.Pointer("latest"),
PullPolicy: (*corev1.PullPolicy)(util.Pointer(string(corev1.PullIfNotPresent))),
}
corsproxyDefaultResources defaultResourceRequirementsSpec = defaultResourceRequirementsSpec{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("75m"),
corev1.ResourceMemory: resource.MustParse("64Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("150m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
}
corsproxyDefaultHPA defaultHorizontalPodAutoscalerSpec = defaultHorizontalPodAutoscalerSpec{
MinReplicas: util.Pointer[int32](2),
MaxReplicas: util.Pointer[int32](4),
ResourceUtilization: util.Pointer[int32](90),
ResourceName: util.Pointer("cpu"),
}
corsproxyDefaultProbe defaultProbeSpec = defaultProbeSpec{
InitialDelaySeconds: util.Pointer[int32](3),
TimeoutSeconds: util.Pointer[int32](1),
PeriodSeconds: util.Pointer[int32](10),
SuccessThreshold: util.Pointer[int32](1),
FailureThreshold: util.Pointer[int32](3),
}
corsproxyDefaultPDB defaultPodDisruptionBudgetSpec = defaultPodDisruptionBudgetSpec{
MaxUnavailable: util.Pointer(intstr.FromInt(1)),
}
corsproxyDefaultGrafanaDashboard defaultGrafanaDashboardSpec = defaultGrafanaDashboardSpec{
SelectorKey: util.Pointer("monitoring-key"),
SelectorValue: util.Pointer("middleware"),
}
)
// CORSProxySpec defines the desired state of CORSProxy
type CORSProxySpec struct {
// Image specification for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Image *ImageSpec `json:"image,omitempty"`
// Pod Disruption Budget for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
PDB *PodDisruptionBudgetSpec `json:"pdb,omitempty"`
// Horizontal Pod Autoscaler for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
HPA *HorizontalPodAutoscalerSpec `json:"hpa,omitempty"`
// Number of replicas (ignored if hpa is enabled) for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Resource requirements for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
Resources *ResourceRequirementsSpec `json:"resources,omitempty"`
// Liveness probe for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
LivenessProbe *ProbeSpec `json:"livenessProbe,omitempty"`
// Readiness probe for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
ReadinessProbe *ProbeSpec `json:"readinessProbe,omitempty"`
// Configures the Grafana Dashboard for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
GrafanaDashboard *GrafanaDashboardSpec `json:"grafanaDashboard,omitempty"`
// Application specific configuration options for the component
// +operator-sdk:csv:customresourcedefinitions:type=spec
Config CORSProxyConfig `json:"config"`
// Describes node affinity scheduling rules for the pod.
// +optional
NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty" protobuf:"bytes,1,opt,name=nodeAffinity"`
// If specified, the pod's tolerations.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,22,opt,name=tolerations"`
}
// Default implements defaulting for CORSProxySpec
func (spec *CORSProxySpec) Default() {
spec.Image = InitializeImageSpec(spec.Image, corsproxyDefaultImage)
spec.HPA = InitializeHorizontalPodAutoscalerSpec(spec.HPA, corsproxyDefaultHPA)
spec.Replicas = intOrDefault(spec.Replicas, &corsproxyDefaultReplicas)
spec.PDB = InitializePodDisruptionBudgetSpec(spec.PDB, corsproxyDefaultPDB)
spec.Resources = InitializeResourceRequirementsSpec(spec.Resources, corsproxyDefaultResources)
spec.LivenessProbe = InitializeProbeSpec(spec.LivenessProbe, corsproxyDefaultProbe)
spec.ReadinessProbe = InitializeProbeSpec(spec.ReadinessProbe, corsproxyDefaultProbe)
spec.GrafanaDashboard = InitializeGrafanaDashboardSpec(spec.GrafanaDashboard, corsproxyDefaultGrafanaDashboard)
spec.Config.Default()
}
// CORSProxyConfig defines configuration options for the component
type CORSProxyConfig struct {
// External Secret common configuration
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
ExternalSecret ExternalSecret `json:"externalSecret,omitempty"`
// System database connection string
// +operator-sdk:csv:customresourcedefinitions:type=spec
SystemDatabaseDSN SecretReference `json:"systemDatabaseDSN"`
}
// Default sets default values for any value not specifically set in the CORSProxyConfig struct
func (cfg *CORSProxyConfig) Default() {
cfg.ExternalSecret.SecretStoreRef = InitializeExternalSecretSecretStoreReferenceSpec(cfg.ExternalSecret.SecretStoreRef, defaultExternalSecretSecretStoreReference)
cfg.ExternalSecret.RefreshInterval = durationOrDefault(cfg.ExternalSecret.RefreshInterval, &defaultExternalSecretRefreshInterval)
}
// CORSProxyStatus defines the observed state of CORSProxy
type CORSProxyStatus struct{}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// CORSProxy is the Schema for the corsproxies API
type CORSProxy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CORSProxySpec `json:"spec,omitempty"`
Status CORSProxyStatus `json:"status,omitempty"`
}
// Default implements defaulting for the CORSProxy resource
func (c *CORSProxy) Default() {
c.Spec.Default()
}
// +kubebuilder:object:root=true
// CORSProxyList contains a list of CORSProxy
type CORSProxyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CORSProxy `json:"items"`
}
func init() {
SchemeBuilder.Register(&CORSProxy{}, &CORSProxyList{})
}