Skip to content

Commit a8a0439

Browse files
pengzhoumlPeng Zhou
andauthored
MLE-22946: Fix the bug of cluster level labels propagate (#94)
* MLE-22946: Fix the bug of cluster level labels propagate from other cluster. * Update pkg/k8sutil/service.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/k8sutil/context.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/k8sutil/context.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * revert copilot changes * Fix bug MLE-23487: Log Collection Default Value Override * MLE-23487 default values for LogCollection * MLE-23484: Fix Log Collection Test Failure * add retry for the Loki Grafana query --------- Co-authored-by: Peng Zhou <peng.zhou@progress.com>
1 parent 643f3ee commit a8a0439

14 files changed

+231
-109
lines changed

api/v1/common_types.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ type AdminAuth struct {
5757
}
5858

5959
type LogCollection struct {
60-
Enabled bool `json:"enabled,omitempty"`
60+
// +kubebuilder:default:=false
61+
Enabled bool `json:"enabled,omitempty"`
62+
// +kubebuilder:default:="fluent/fluent-bit:3.2.5"
6163
Image string `json:"image,omitempty"`
6264
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
63-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
64-
Files LogFilesConfig `json:"files,omitempty"`
65-
Outputs string `json:"outputs,omitempty"`
65+
// +kubebuilder:default:={"requests":{"cpu":"100m","memory":"200Mi"},"limits":{"cpu":"200m","memory":"500Mi"}}
66+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
67+
// +kubebuilder:default:={errorLogs: true, accessLogs: true, requestLogs: true, crashLogs: true, auditLogs: true}
68+
Files LogFilesConfig `json:"files,omitempty"`
69+
// +kubebuilder:default:="[OUTPUT]\n name loki\n match *\n host loki.default.svc.cluster.local\n port 3100\n labels job=fluent-bit\n http_user admin\n http_passwd admin"
70+
Outputs string `json:"outputs,omitempty"`
6671
}
6772

6873
type LogFilesConfig struct {

config/crd/bases/marklogic.progress.com_marklogicclusters.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,8 +4639,15 @@ spec:
46394639
memory: 200Mi
46404640
properties:
46414641
enabled:
4642+
default: false
46424643
type: boolean
46434644
files:
4645+
default:
4646+
accessLogs: true
4647+
auditLogs: true
4648+
crashLogs: true
4649+
errorLogs: true
4650+
requestLogs: true
46444651
properties:
46454652
accessLogs:
46464653
type: boolean
@@ -4654,6 +4661,7 @@ spec:
46544661
type: boolean
46554662
type: object
46564663
image:
4664+
default: fluent/fluent-bit:3.2.5
46574665
type: string
46584666
imagePullSecrets:
46594667
items:
@@ -4674,8 +4682,24 @@ spec:
46744682
x-kubernetes-map-type: atomic
46754683
type: array
46764684
outputs:
4685+
default: |-
4686+
[OUTPUT]
4687+
name loki
4688+
match *
4689+
host loki.default.svc.cluster.local
4690+
port 3100
4691+
labels job=fluent-bit
4692+
http_user admin
4693+
http_passwd admin
46774694
type: string
46784695
resources:
4696+
default:
4697+
limits:
4698+
cpu: 200m
4699+
memory: 500Mi
4700+
requests:
4701+
cpu: 100m
4702+
memory: 200Mi
46794703
description: ResourceRequirements describes the compute resource
46804704
requirements.
46814705
properties:
@@ -9367,8 +9391,15 @@ spec:
93679391
logCollection:
93689392
properties:
93699393
enabled:
9394+
default: false
93709395
type: boolean
93719396
files:
9397+
default:
9398+
accessLogs: true
9399+
auditLogs: true
9400+
crashLogs: true
9401+
errorLogs: true
9402+
requestLogs: true
93729403
properties:
93739404
accessLogs:
93749405
type: boolean
@@ -9382,6 +9413,7 @@ spec:
93829413
type: boolean
93839414
type: object
93849415
image:
9416+
default: fluent/fluent-bit:3.2.5
93859417
type: string
93869418
imagePullSecrets:
93879419
items:
@@ -9402,8 +9434,24 @@ spec:
94029434
x-kubernetes-map-type: atomic
94039435
type: array
94049436
outputs:
9437+
default: |-
9438+
[OUTPUT]
9439+
name loki
9440+
match *
9441+
host loki.default.svc.cluster.local
9442+
port 3100
9443+
labels job=fluent-bit
9444+
http_user admin
9445+
http_passwd admin
94059446
type: string
94069447
resources:
9448+
default:
9449+
limits:
9450+
cpu: 200m
9451+
memory: 500Mi
9452+
requests:
9453+
cpu: 100m
9454+
memory: 200Mi
94079455
description: ResourceRequirements describes the compute
94089456
resource requirements.
94099457
properties:

config/crd/bases/marklogic.progress.com_marklogicgroups.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,8 +3382,15 @@ spec:
33823382
memory: 200Mi
33833383
properties:
33843384
enabled:
3385+
default: false
33853386
type: boolean
33863387
files:
3388+
default:
3389+
accessLogs: true
3390+
auditLogs: true
3391+
crashLogs: true
3392+
errorLogs: true
3393+
requestLogs: true
33873394
properties:
33883395
accessLogs:
33893396
type: boolean
@@ -3397,6 +3404,7 @@ spec:
33973404
type: boolean
33983405
type: object
33993406
image:
3407+
default: fluent/fluent-bit:3.2.5
34003408
type: string
34013409
imagePullSecrets:
34023410
items:
@@ -3417,8 +3425,24 @@ spec:
34173425
x-kubernetes-map-type: atomic
34183426
type: array
34193427
outputs:
3428+
default: |-
3429+
[OUTPUT]
3430+
name loki
3431+
match *
3432+
host loki.default.svc.cluster.local
3433+
port 3100
3434+
labels job=fluent-bit
3435+
http_user admin
3436+
http_passwd admin
34203437
type: string
34213438
resources:
3439+
default:
3440+
limits:
3441+
cpu: 200m
3442+
memory: 500Mi
3443+
requests:
3444+
cpu: 100m
3445+
memory: 200Mi
34223446
description: ResourceRequirements describes the compute resource
34233447
requirements.
34243448
properties:

pkg/k8sutil/common.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import (
99
"sigs.k8s.io/controller-runtime/pkg/client"
1010
)
1111

12-
var CustomLabels = map[string]string{}
13-
var CustomAnnotations = map[string]string{}
14-
1512
// generateTypeMeta generates the TyeMeta
1613
func generateTypeMeta(resourceKind string, apiVersion string) metav1.TypeMeta {
1714
return metav1.TypeMeta{
@@ -49,15 +46,6 @@ func LabelSelectors(labels map[string]string) *metav1.LabelSelector {
4946
return &metav1.LabelSelector{MatchLabels: labels}
5047
}
5148

52-
func SetCommonLabels(labels map[string]string) {
53-
CustomLabels = labels
54-
}
55-
56-
func SetCommonAnnotations(annotations map[string]string) {
57-
delete(annotations, "kubectl.kubernetes.io/last-applied-configuration")
58-
CustomAnnotations = annotations
59-
}
60-
6149
func getSelectorLabels(name string) map[string]string {
6250
selectorLabels := map[string]string{
6351
"app.kubernetes.io/name": "marklogic",
@@ -78,46 +66,6 @@ func getHAProxySelectorLabels(name string) map[string]string {
7866
return selectorLabels
7967
}
8068

81-
func getHAProxyLabels(name string) map[string]string {
82-
defaultHaproxyLabels := getHAProxySelectorLabels(name)
83-
mergedLabels := map[string]string{}
84-
if len(CustomLabels) > 0 {
85-
for k, v := range defaultHaproxyLabels {
86-
mergedLabels[k] = v
87-
}
88-
for k, v := range CustomLabels {
89-
if _, ok := defaultHaproxyLabels[k]; !ok {
90-
mergedLabels[k] = v
91-
}
92-
}
93-
} else {
94-
return defaultHaproxyLabels
95-
}
96-
return mergedLabels
97-
}
98-
99-
func getCommonLabels(name string) map[string]string {
100-
defaultLabels := getSelectorLabels(name)
101-
mergedLabels := map[string]string{}
102-
if len(CustomLabels) > 0 {
103-
for k, v := range defaultLabels {
104-
mergedLabels[k] = v
105-
}
106-
for k, v := range CustomLabels {
107-
if _, ok := defaultLabels[k]; !ok {
108-
mergedLabels[k] = v
109-
}
110-
}
111-
} else {
112-
return defaultLabels
113-
}
114-
return mergedLabels
115-
}
116-
117-
func getCommonAnnotations() map[string]string {
118-
return CustomAnnotations
119-
}
120-
12169
func getFluentBitLabels(name string) map[string]string {
12270
return map[string]string{
12371
"app.kubernetes.io/name": "fluent-bit",

pkg/k8sutil/configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func (oc *OperatorContext) ReconcileConfigMap() result.ReconcileResult {
1919
cr := oc.MarklogicGroup
2020

2121
logger.Info("Reconciling MarkLogic ConfigMap")
22-
labels := getCommonLabels(cr.Spec.Name)
23-
annotations := getCommonAnnotations()
22+
labels := oc.GetOperatorLabels(cr.Spec.Name)
23+
annotations := oc.GetOperatorAnnotations()
2424
configMapName := cr.Spec.Name + "-scripts"
2525
objectMeta := generateObjectMeta(configMapName, cr.Namespace, labels, annotations)
2626
nsName := types.NamespacedName{Name: objectMeta.Name, Namespace: objectMeta.Namespace}

0 commit comments

Comments
 (0)