operator: Add watch for the object storage secret (#8978)

pull/9036/head^2
Mohamed-Amine Bouqsimi 2 years ago committed by GitHub
parent 09ecc843f5
commit c7584bea37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      operator/CHANGELOG.md
  2. 37
      operator/controllers/loki/lokistack_controller.go
  3. 17
      operator/controllers/loki/lokistack_controller_test.go

@ -1,5 +1,6 @@
## Main
- [8978](https://github.com/grafana/loki/pull/8978) **aminesnow**: Add watch for the object storage secret
- [8958](https://github.com/grafana/loki/pull/8958) **periklis**: Align common instance addr with memberlist advertise addr
- [8998](https://github.com/grafana/loki/pull/8998) **periklis**: Remove static placeholder suffix for openshift bundle
- [8930](https://github.com/grafana/loki/pull/8930) **periklis**: Fix makefile target operatorhub

@ -96,7 +96,11 @@ var (
})
createUpdateOrDeletePred = builder.WithPredicates(predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return (e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration()) ||
if e.ObjectOld.GetGeneration() == 0 && len(e.ObjectOld.GetAnnotations()) == 0 {
return e.ObjectOld.GetResourceVersion() != e.ObjectNew.GetResourceVersion()
}
return e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() ||
cmp.Diff(e.ObjectOld.GetAnnotations(), e.ObjectNew.GetAnnotations()) != ""
},
CreateFunc: func(e event.CreateEvent) bool { return true },
@ -206,7 +210,8 @@ func (r *LokiStackReconciler) buildController(bld k8s.Builder) error {
Owns(&rbacv1.ClusterRoleBinding{}, updateOrDeleteOnlyPred).
Owns(&rbacv1.Role{}, updateOrDeleteOnlyPred).
Owns(&rbacv1.RoleBinding{}, updateOrDeleteOnlyPred).
Watches(&source.Kind{Type: &corev1.Service{}}, r.enqueueForAlertManagerServices(), createUpdateOrDeletePred)
Watches(&source.Kind{Type: &corev1.Service{}}, r.enqueueForAlertManagerServices(), createUpdateOrDeletePred).
Watches(&source.Kind{Type: &corev1.Secret{}}, r.enqueueForStorageSecret(), createUpdateOrDeletePred)
if r.FeatureGates.LokiStackAlerts {
bld = bld.Owns(&monitoringv1.PrometheusRule{}, updateOrDeleteOnlyPred)
@ -298,3 +303,31 @@ func (r *LokiStackReconciler) enqueueForAlertManagerServices() handler.EventHand
return requests
})
}
func (r *LokiStackReconciler) enqueueForStorageSecret() handler.EventHandler {
ctx := context.TODO()
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
lokiStacks := &lokiv1.LokiStackList{}
if err := r.Client.List(ctx, lokiStacks); err != nil {
r.Log.Error(err, "Error getting LokiStack resources in event handler")
return nil
}
var requests []reconcile.Request
for _, stack := range lokiStacks.Items {
if obj.GetName() == stack.Spec.Storage.Secret.Name && obj.GetNamespace() == stack.Namespace {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: stack.Namespace,
Name: stack.Name,
},
})
r.Log.Info("Enqueued requests for LokiStack because of Storage Secret resource change", "LokiStack", stack.Name, "Secret", obj.GetName())
return requests
}
}
return requests
})
}

@ -203,8 +203,8 @@ func TestLokiStackController_RegisterWatchedResources(t *testing.T) {
table := []test{
{
src: &source.Kind{Type: &openshiftconfigv1.APIServer{}},
index: 1,
watchesCallsCount: 2,
index: 2,
watchesCallsCount: 3,
featureGates: configv1.FeatureGates{
OpenShift: configv1.OpenShiftFeatureGates{
ClusterTLSPolicy: true,
@ -214,8 +214,8 @@ func TestLokiStackController_RegisterWatchedResources(t *testing.T) {
},
{
src: &source.Kind{Type: &openshiftconfigv1.Proxy{}},
index: 1,
watchesCallsCount: 2,
index: 2,
watchesCallsCount: 3,
featureGates: configv1.FeatureGates{
OpenShift: configv1.OpenShiftFeatureGates{
ClusterProxy: true,
@ -226,7 +226,14 @@ func TestLokiStackController_RegisterWatchedResources(t *testing.T) {
{
src: &source.Kind{Type: &corev1.Service{}},
index: 0,
watchesCallsCount: 1,
watchesCallsCount: 2,
featureGates: configv1.FeatureGates{},
pred: createUpdateOrDeletePred,
},
{
src: &source.Kind{Type: &corev1.Secret{}},
index: 1,
watchesCallsCount: 2,
featureGates: configv1.FeatureGates{},
pred: createUpdateOrDeletePred,
},

Loading…
Cancel
Save