Skip to content

Commit b832782

Browse files
pepovcsatib02
andcommitted
add watch labels to all managed secrets
Signed-off-by: Peter Wilcsinszky <[email protected]> Co-authored-by: Bence Csati <[email protected]>
1 parent 72c8810 commit b832782

File tree

7 files changed

+58
-9
lines changed

7 files changed

+58
-9
lines changed

pkg/resources/fluentbit/configsecret.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,13 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
448448
}
449449

450450
r.configs = confs
451-
451+
meta := r.FluentbitObjectMeta(fluentBitSecretConfigName)
452+
meta.Labels = utils.MergeLabels(
453+
meta.Labels,
454+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
455+
)
452456
return &corev1.Secret{
453-
ObjectMeta: r.FluentbitObjectMeta(fluentBitSecretConfigName),
457+
ObjectMeta: meta,
454458
Data: confs,
455459
}, reconciler.StatePresent, nil
456460
}

pkg/resources/fluentd/appconfigmap.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"emperror.dev/errors"
2323
"github.com/cisco-open/operator-tools/pkg/reconciler"
24+
"github.com/cisco-open/operator-tools/pkg/utils"
2425
"github.com/spf13/cast"
2526
corev1 "k8s.io/api/core/v1"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -49,9 +50,11 @@ func (r *Reconciler) appConfigSecret() (runtime.Object, reconciler.DesiredState,
4950
} else {
5051
data[AppConfigKey] = []byte(*r.config)
5152
}
53+
meta := r.FluentdObjectMeta(AppSecretConfigName, ComponentFluentd)
54+
meta.Labels = utils.MergeLabels(meta.Labels, map[string]string{"logging.banzaicloud.io/watch": "enabled"})
5255

5356
return &corev1.Secret{
54-
ObjectMeta: r.FluentdObjectMeta(AppSecretConfigName, ComponentFluentd),
57+
ObjectMeta: meta,
5558
Data: data,
5659
}, reconciler.StatePresent, nil
5760
}
@@ -214,8 +217,11 @@ func (r *Reconciler) newCheckSecret(hashKey string, fluentdSpec v1beta1.FluentdS
214217
data[ConfigCheckKey] = []byte(*r.config)
215218
}
216219
data["fluent.conf"] = []byte(fluentdConfigCheckTemplate)
220+
meta := r.FluentdObjectMeta(fmt.Sprintf("fluentd-configcheck-%s", hashKey), ComponentConfigCheck)
221+
meta.Labels = utils.MergeLabels(meta.Labels, map[string]string{"logging.banzaicloud.io/watch": "enabled"})
222+
217223
return &corev1.Secret{
218-
ObjectMeta: r.FluentdObjectMeta(fmt.Sprintf("fluentd-configcheck-%s", hashKey), ComponentConfigCheck),
224+
ObjectMeta: meta,
219225
Data: data,
220226
}, nil
221227
}
@@ -229,8 +235,11 @@ func (r *Reconciler) newCheckSecretAppConfig(hashKey string, fluentdSpec v1beta1
229235
} else {
230236
data[ConfigCheckKey] = []byte(*r.config)
231237
}
238+
meta := r.FluentdObjectMeta(fmt.Sprintf("fluentd-configcheck-app-%s", hashKey), ComponentConfigCheck)
239+
meta.Labels = utils.MergeLabels(meta.Labels, map[string]string{"logging.banzaicloud.io/watch": "enabled"})
240+
232241
return &corev1.Secret{
233-
ObjectMeta: r.FluentdObjectMeta(fmt.Sprintf("fluentd-configcheck-app-%s", hashKey), ComponentConfigCheck),
242+
ObjectMeta: meta,
234243
Data: data,
235244
}, nil
236245
}
@@ -242,6 +251,10 @@ func (r *Reconciler) newCheckOutputSecret(hashKey string) (*corev1.Secret, error
242251
}
243252
if secret, ok := obj.(*corev1.Secret); ok {
244253
secret.ObjectMeta = r.FluentdObjectMeta(fmt.Sprintf("fluentd-configcheck-output-%s", hashKey), ComponentConfigCheck)
254+
secret.ObjectMeta.Labels = utils.MergeLabels(
255+
secret.ObjectMeta.Labels,
256+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
257+
)
245258
return secret, nil
246259
}
247260
return nil, errors.New("output secret is invalid, unable to create output secret for config check")

pkg/resources/fluentd/configsecret.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121

2222
"emperror.dev/errors"
2323
"github.com/cisco-open/operator-tools/pkg/reconciler"
24-
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
24+
"github.com/cisco-open/operator-tools/pkg/utils"
2525
corev1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/runtime"
27+
28+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
2729
)
2830

2931
type fluentdConfig struct {
@@ -96,10 +98,14 @@ func (r *Reconciler) secretConfig() (runtime.Object, reconciler.DesiredState, er
9698
return nil, nil, err
9799
}
98100
configMap["fluentlog.conf"] = []byte(fmt.Sprintf(fluentLog, r.fluentdSpec.FluentLogDestination))
101+
meta := r.FluentdObjectMeta(SecretConfigName, ComponentFluentd)
102+
meta.Labels = utils.MergeLabels(
103+
meta.Labels,
104+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
105+
)
99106
configs := &corev1.Secret{
100-
ObjectMeta: r.FluentdObjectMeta(SecretConfigName, ComponentFluentd),
107+
ObjectMeta: meta,
101108
Data: configMap,
102109
}
103-
104110
return configs, reconciler.StatePresent, nil
105111
}

pkg/resources/fluentd/outputsecret.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"emperror.dev/errors"
2222
"github.com/cisco-open/operator-tools/pkg/reconciler"
2323
"github.com/cisco-open/operator-tools/pkg/secret"
24+
"github.com/cisco-open/operator-tools/pkg/utils"
2425
corev1 "k8s.io/api/core/v1"
2526
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
@@ -76,6 +77,10 @@ func (r *Reconciler) outputSecret(secrets *secret.MountSecrets, mountPath string
7677
fluentOutputSecret.Data[secret.MappedKey] = secret.Value
7778
}
7879
}
80+
fluentOutputSecret.ObjectMeta.Labels = utils.MergeLabels(
81+
fluentOutputSecret.ObjectMeta.Labels,
82+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
83+
)
7984

8085
return fluentOutputSecret, reconciler.StatePresent, nil
8186
}

pkg/resources/syslogng/configcheck.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"emperror.dev/errors"
2424
"github.com/cisco-open/operator-tools/pkg/merge"
25+
"github.com/cisco-open/operator-tools/pkg/utils"
2526
"github.com/spf13/cast"
2627
corev1 "k8s.io/api/core/v1"
2728
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -163,8 +164,13 @@ func (r *Reconciler) configCheck(ctx context.Context) (*ConfigCheckResult, error
163164
}
164165

165166
func (r *Reconciler) newCheckSecret(hashKey string) (*corev1.Secret, error) {
167+
meta := r.SyslogNGObjectMeta(configCheckResourceName(hashKey), ComponentConfigCheck)
168+
meta.Labels = utils.MergeLabels(
169+
meta.Labels,
170+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
171+
)
166172
return &corev1.Secret{
167-
ObjectMeta: r.SyslogNGObjectMeta(configCheckResourceName(hashKey), ComponentConfigCheck),
173+
ObjectMeta: meta,
168174
Data: map[string][]byte{
169175
configKey: []byte(r.config),
170176
},
@@ -178,6 +184,11 @@ func (r *Reconciler) newCheckOutputSecret(hashKey string) (*corev1.Secret, error
178184
}
179185
if secret, ok := obj.(*corev1.Secret); ok {
180186
secret.ObjectMeta = r.SyslogNGObjectMeta(fmt.Sprintf("syslog-ng-configcheck-output-%s", hashKey), ComponentConfigCheck)
187+
secret.ObjectMeta.Labels = utils.MergeLabels(
188+
secret.ObjectMeta.Labels,
189+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
190+
)
191+
181192
return secret, nil
182193
}
183194
return nil, errors.New("output secret is invalid, unable to create output secret for config check")

pkg/resources/syslogng/configsecret.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package syslogng
1616

1717
import (
1818
"github.com/cisco-open/operator-tools/pkg/reconciler"
19+
"github.com/cisco-open/operator-tools/pkg/utils"
1920
corev1 "k8s.io/api/core/v1"
2021
"k8s.io/apimachinery/pkg/runtime"
2122
)
@@ -27,6 +28,10 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
2728
configKey: []byte(r.config),
2829
},
2930
}
31+
secret.ObjectMeta.Labels = utils.MergeLabels(
32+
secret.ObjectMeta.Labels,
33+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
34+
)
3035

3136
return secret, reconciler.StatePresent, nil
3237
}

pkg/resources/syslogng/outputsecret.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"emperror.dev/errors"
2222
"github.com/cisco-open/operator-tools/pkg/reconciler"
2323
"github.com/cisco-open/operator-tools/pkg/secret"
24+
"github.com/cisco-open/operator-tools/pkg/utils"
2425
corev1 "k8s.io/api/core/v1"
2526
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
@@ -62,6 +63,10 @@ func (r *Reconciler) outputSecret(secrets *secret.MountSecrets, mountPath string
6263
Namespace: r.Logging.Spec.ControlNamespace,
6364
},
6465
}
66+
syslogNGOutputSecret.ObjectMeta.Labels = utils.MergeLabels(
67+
syslogNGOutputSecret.ObjectMeta.Labels,
68+
map[string]string{"logging.banzaicloud.io/watch": "enabled"},
69+
)
6570
if syslogNGOutputSecret.Data == nil {
6671
syslogNGOutputSecret.Data = make(map[string][]byte)
6772
}

0 commit comments

Comments
 (0)