Skip to content

Commit 27867d5

Browse files
authored
Generate operator resources for production (#774)
* mage: Add crd target for prod * Add operator target for prod
1 parent 9de5594 commit 27867d5

File tree

6 files changed

+54767
-26310
lines changed

6 files changed

+54767
-26310
lines changed

magefiles/operator.go

+31-39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/observatorium/observatorium/configuration_go/kubegen/openshift"
88
templatev1 "github.com/openshift/api/template/v1"
9+
"github.com/philipgough/mimic"
910
"github.com/philipgough/mimic/encoding"
1011

1112
appsv1 "k8s.io/api/apps/v1"
@@ -20,52 +21,35 @@ import (
2021
)
2122

2223
const (
24+
crdTemplateDir = "bundle"
25+
2326
CRDMain = "refs/heads/main"
27+
CRDRefProd = "b58f3ec98a62b904950148bd5aea906a2c6a519e"
2428
CRDRefStage = "b58f3ec98a62b904950148bd5aea906a2c6a519e"
2529
)
2630

2731
// CRDS Generates the CRDs for the Thanos operator.
28-
// This is synced from the latest upstream main at:
32+
// This is synced from the latest upstream ref at:
2933
// https://github.com/thanos-community/thanos-operator/tree/main/config/crd/bases
30-
func (s Stage) CRDS() error {
31-
const (
32-
templateDir = "bundle"
33-
)
34-
gen := s.generator(templateDir)
35-
36-
objs, err := crds(CRDRefStage)
37-
if err != nil {
38-
return err
39-
}
34+
func (p Production) CRDS() error {
35+
return crds(p.generator(crdTemplateDir), CRDRefProd)
36+
}
4037

41-
template := openshift.WrapInTemplate(objs, metav1.ObjectMeta{Name: "thanos-operator-crds"}, []templatev1.Parameter{})
42-
encoder := encoding.GhodssYAML(template)
43-
gen.Add("thanos-operator-crds.yaml", encoder)
44-
gen.Generate()
45-
return nil
38+
// CRDS Generates the CRDs for the Thanos operator.
39+
// This is synced from the latest upstream ref at:
40+
// https://github.com/thanos-community/thanos-operator/tree/main/config/crd/bases
41+
func (s Stage) CRDS() error {
42+
return crds(s.generator(crdTemplateDir), CRDRefStage)
4643
}
4744

4845
// CRDS Generates the CRDs for the Thanos operator for a local environment.
4946
// This is synced from the latest upstream main at:
5047
// https://github.com/thanos-community/thanos-operator/tree/main/config/crd/bases
5148
func (l Local) CRDS() error {
52-
const (
53-
templateDir = "bundle"
54-
)
55-
gen := l.generator(templateDir)
56-
57-
objs, err := crds(CRDRefStage)
58-
if err != nil {
59-
return err
60-
}
61-
62-
encoder := encoding.GhodssYAML(objs[0], objs[1], objs[2], objs[3], objs[4])
63-
gen.Add("thanos-operator-crds.yaml", encoder)
64-
gen.Generate()
65-
return nil
49+
return crds(l.generator(crdTemplateDir), CRDRefStage)
6650
}
6751

68-
func crds(ref string) ([]runtime.Object, error) {
52+
func crds(gen *mimic.Generator, ref string) error {
6953
const (
7054
compact = "thanoscompacts.yaml"
7155
queries = "thanosqueries.yaml"
@@ -81,36 +65,44 @@ func crds(ref string) ([]runtime.Object, error) {
8165
manifest := base + component
8266
resp, err := http.Get(manifest)
8367
if err != nil {
84-
return nil, fmt.Errorf("failed to fetch %s: %w", manifest, err)
68+
return fmt.Errorf("failed to fetch %s: %w", manifest, err)
8569
}
8670

8771
if resp.StatusCode != http.StatusOK {
88-
return nil, fmt.Errorf("failed to fetch %s: %s", manifest, resp.Status)
72+
return fmt.Errorf("failed to fetch %s: %s", manifest, resp.Status)
8973
}
9074

9175
var obj v1.CustomResourceDefinition
9276
decoder := yaml.NewYAMLOrJSONDecoder(resp.Body, 100000)
9377
err = decoder.Decode(&obj)
9478
if err != nil {
95-
return nil, fmt.Errorf("failed to decode %s: %w", manifest, err)
79+
return fmt.Errorf("failed to decode %s: %w", manifest, err)
9680
}
9781

9882
objs = append(objs, &obj)
9983
resp.Body.Close()
10084
}
10185

102-
return objs, nil
86+
encoder := encoding.GhodssYAML(objs[0], objs[1], objs[2], objs[3], objs[4])
87+
gen.Add("thanos-operator-crds.yaml", encoder)
88+
gen.Generate()
89+
return nil
10390
}
10491

10592
// Operator Generates the Thanos Operator Manager resources.
106-
func (s Stage) Operator() {
107-
templateDir := "bundle"
93+
func (p Production) Operator() {
94+
operator(p.namespace(), p.generator(crdTemplateDir), ProductionMaps)
95+
}
10896

109-
gen := s.generator(templateDir)
97+
// Operator Generates the Thanos Operator Manager resources.
98+
func (s Stage) Operator() {
99+
operator(s.namespace(), s.generator(crdTemplateDir), StageMaps)
100+
}
110101

102+
func operator(namespace string, gen *mimic.Generator, m TemplateMaps) {
111103
gen.Add("operator.yaml", encoding.GhodssYAML(
112104
openshift.WrapInTemplate(
113-
operatorResources(s.namespace(), StageMaps),
105+
operatorResources(namespace, m),
114106
metav1.ObjectMeta{Name: "thanos-operator-manager"},
115107
[]templatev1.Parameter{},
116108
),

magefiles/template.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type TemplateMaps struct {
2929
func TemplateFn[T any](param string, m ParamMap[T]) T {
3030
v, ok := m[param]
3131
if !ok {
32-
panic(fmt.Sprintf("param %s not found in stage", param))
32+
panic(fmt.Sprintf("param %s not found", param))
3333
}
3434
return v
3535
}
@@ -338,6 +338,51 @@ var StageObjectStorageBucket = ParamMap[v1alpha1.ObjectStorageConfig]{
338338
},
339339
}
340340

341+
// ProductionImages is a map of production images.
342+
var ProductionImages = ParamMap[string]{
343+
"THANOS_OPERATOR": "quay.io/redhat-user-workloads/rhobs-mco-tenant/rhobs-thanos-operator:" + thanosOperatorStage,
344+
"KUBE_RBAC_PROXY": "registry.redhat.io/openshift4/ose-kube-rbac-proxy@sha256:98455d503b797b6b02edcfd37045c8fab0796b95ee5cf4cfe73b221a07e805f0",
345+
}
346+
347+
// ProductionVersions is a map of production versions.
348+
var ProductionVersions = ParamMap[string]{}
349+
350+
// ProductionLogLevels is a map of production log levels.
351+
var ProductionLogLevels = ParamMap[string]{}
352+
353+
// ProductionStorageSize is a map of production PV storage sizes.
354+
var ProductionStorageSize = ParamMap[v1alpha1.StorageSize]{}
355+
356+
// ProductionReplicas is a map of production replicas.
357+
var ProductionReplicas = ParamMap[int32]{}
358+
359+
// ProductionResourceRequirements is a map of production resource requirements.
360+
var ProductionResourceRequirements = ParamMap[corev1.ResourceRequirements]{
361+
"MANAGER": corev1.ResourceRequirements{
362+
Limits: corev1.ResourceList{
363+
corev1.ResourceCPU: resource.MustParse("1"),
364+
corev1.ResourceMemory: resource.MustParse("2Gi"),
365+
},
366+
Requests: corev1.ResourceList{
367+
corev1.ResourceCPU: resource.MustParse("100m"),
368+
corev1.ResourceMemory: resource.MustParse("512Mi"),
369+
},
370+
},
371+
"KUBE_RBAC_PROXY": corev1.ResourceRequirements{
372+
Limits: corev1.ResourceList{
373+
corev1.ResourceCPU: resource.MustParse("500m"),
374+
corev1.ResourceMemory: resource.MustParse("128Mi"),
375+
},
376+
Requests: corev1.ResourceList{
377+
corev1.ResourceCPU: resource.MustParse("5m"),
378+
corev1.ResourceMemory: resource.MustParse("64Mi"),
379+
},
380+
},
381+
}
382+
383+
// ProductionObjectStorageBucket is a map of production object storage buckets.
384+
var ProductionObjectStorageBucket = ParamMap[v1alpha1.ObjectStorageConfig]{}
385+
341386
// Local images.
342387
var LocalImages = ParamMap[string]{
343388
"STORE02W": CurrentThanosImageStage,
@@ -437,6 +482,16 @@ var StageMaps = TemplateMaps{
437482
ObjectStorageBucket: StageObjectStorageBucket,
438483
}
439484

485+
var ProductionMaps = TemplateMaps{
486+
Images: ProductionImages,
487+
Versions: ProductionVersions,
488+
LogLevels: ProductionLogLevels,
489+
StorageSize: ProductionStorageSize,
490+
Replicas: ProductionReplicas,
491+
ResourceRequirements: ProductionResourceRequirements,
492+
ObjectStorageBucket: ProductionObjectStorageBucket,
493+
}
494+
440495
var LocalMaps = TemplateMaps{
441496
Images: LocalImages,
442497
Versions: LocalVersions,

resources/services/bundle/local/thanos-operator-crds.yaml

+115
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,29 @@ spec:
36743674
enable: true
36753675
description: FeatureGates are feature gates for the compact component.
36763676
properties:
3677+
podDisruptionBudget:
3678+
default:
3679+
enable: true
3680+
description: |-
3681+
PodDisruptionBudgetConfig is the configuration for the PodDisruptionBudget.
3682+
This setting requires the feature gate for PodDisruptionBudget management to be enabled.
3683+
properties:
3684+
enable:
3685+
description: Enabled enables the creation of a PodDisruptionBudget
3686+
for the Thanos component.
3687+
type: boolean
3688+
maxUnavailable:
3689+
description: |-
3690+
MaxUnavailable is the maximum number of pods that can be unavailable during the disruption.
3691+
If neither MaxUnavailable nor MinAvailable is specified, the default is 1.
3692+
format: int32
3693+
type: integer
3694+
minAvailable:
3695+
description: MinAvailable is the minimum number of pods that
3696+
must still be available during the disruption.
3697+
format: int32
3698+
type: integer
3699+
type: object
36773700
prometheusRuleEnabled:
36783701
default: true
36793702
description: |-
@@ -7637,6 +7660,29 @@ spec:
76377660
enable: true
76387661
description: FeatureGates are feature gates for the compact component.
76397662
properties:
7663+
podDisruptionBudget:
7664+
default:
7665+
enable: true
7666+
description: |-
7667+
PodDisruptionBudgetConfig is the configuration for the PodDisruptionBudget.
7668+
This setting requires the feature gate for PodDisruptionBudget management to be enabled.
7669+
properties:
7670+
enable:
7671+
description: Enabled enables the creation of a PodDisruptionBudget
7672+
for the Thanos component.
7673+
type: boolean
7674+
maxUnavailable:
7675+
description: |-
7676+
MaxUnavailable is the maximum number of pods that can be unavailable during the disruption.
7677+
If neither MaxUnavailable nor MinAvailable is specified, the default is 1.
7678+
format: int32
7679+
type: integer
7680+
minAvailable:
7681+
description: MinAvailable is the minimum number of pods that
7682+
must still be available during the disruption.
7683+
format: int32
7684+
type: integer
7685+
type: object
76407686
prometheusRuleEnabled:
76417687
default: true
76427688
description: |-
@@ -11776,6 +11822,29 @@ spec:
1177611822
enable: true
1177711823
description: FeatureGates are feature gates for the compact component.
1177811824
properties:
11825+
podDisruptionBudget:
11826+
default:
11827+
enable: true
11828+
description: |-
11829+
PodDisruptionBudgetConfig is the configuration for the PodDisruptionBudget.
11830+
This setting requires the feature gate for PodDisruptionBudget management to be enabled.
11831+
properties:
11832+
enable:
11833+
description: Enabled enables the creation of a PodDisruptionBudget
11834+
for the Thanos component.
11835+
type: boolean
11836+
maxUnavailable:
11837+
description: |-
11838+
MaxUnavailable is the maximum number of pods that can be unavailable during the disruption.
11839+
If neither MaxUnavailable nor MinAvailable is specified, the default is 1.
11840+
format: int32
11841+
type: integer
11842+
minAvailable:
11843+
description: MinAvailable is the minimum number of pods that
11844+
must still be available during the disruption.
11845+
format: int32
11846+
type: integer
11847+
type: object
1177911848
prometheusRuleEnabled:
1178011849
default: true
1178111850
description: |-
@@ -23041,6 +23110,29 @@ spec:
2304123110
enable: true
2304223111
description: FeatureGates are feature gates for the rule component.
2304323112
properties:
23113+
podDisruptionBudget:
23114+
default:
23115+
enable: true
23116+
description: |-
23117+
PodDisruptionBudgetConfig is the configuration for the PodDisruptionBudget.
23118+
This setting requires the feature gate for PodDisruptionBudget management to be enabled.
23119+
properties:
23120+
enable:
23121+
description: Enabled enables the creation of a PodDisruptionBudget
23122+
for the Thanos component.
23123+
type: boolean
23124+
maxUnavailable:
23125+
description: |-
23126+
MaxUnavailable is the maximum number of pods that can be unavailable during the disruption.
23127+
If neither MaxUnavailable nor MinAvailable is specified, the default is 1.
23128+
format: int32
23129+
type: integer
23130+
minAvailable:
23131+
description: MinAvailable is the minimum number of pods that
23132+
must still be available during the disruption.
23133+
format: int32
23134+
type: integer
23135+
type: object
2304423136
prometheusRuleEnabled:
2304523137
default: true
2304623138
description: |-
@@ -27078,6 +27170,29 @@ spec:
2707827170
enable: true
2707927171
description: FeatureGates are feature gates for the compact component.
2708027172
properties:
27173+
podDisruptionBudget:
27174+
default:
27175+
enable: true
27176+
description: |-
27177+
PodDisruptionBudgetConfig is the configuration for the PodDisruptionBudget.
27178+
This setting requires the feature gate for PodDisruptionBudget management to be enabled.
27179+
properties:
27180+
enable:
27181+
description: Enabled enables the creation of a PodDisruptionBudget
27182+
for the Thanos component.
27183+
type: boolean
27184+
maxUnavailable:
27185+
description: |-
27186+
MaxUnavailable is the maximum number of pods that can be unavailable during the disruption.
27187+
If neither MaxUnavailable nor MinAvailable is specified, the default is 1.
27188+
format: int32
27189+
type: integer
27190+
minAvailable:
27191+
description: MinAvailable is the minimum number of pods that
27192+
must still be available during the disruption.
27193+
format: int32
27194+
type: integer
27195+
type: object
2708127196
prometheusRuleEnabled:
2708227197
default: true
2708327198
description: |-

0 commit comments

Comments
 (0)