Skip to content

Commit

Permalink
NETOBSERV-1647: Do not load loki cert when loki disabled (#669)
Browse files Browse the repository at this point in the history
* Do not load loki cert when loki disabled

* Remove duplicated code adding volumes
  • Loading branch information
jotak committed Jun 6, 2024
1 parent bf5f147 commit bc0bcef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
12 changes: 0 additions & 12 deletions controllers/consoleplugin/consoleplugin_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ func (b *builder) podTemplate(cmDigest string) *corev1.PodTemplateSpec {
})
}

// ensure volumes are up to date
loki := b.info.Loki
if loki.TLS.Enable && !loki.TLS.InsecureSkipVerify {
b.volumes.AddCACertificate(&loki.TLS, "loki-certs")
}
if loki.StatusTLS.Enable && !loki.StatusTLS.InsecureSkipVerify {
b.volumes.AddMutualTLSCertificates(&loki.StatusTLS, "loki-status-certs")
}
if loki.UseHostToken() {
b.volumes.AddToken(constants.PluginName)
}

return &corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: b.labels,
Expand Down
16 changes: 9 additions & 7 deletions controllers/consoleplugin/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
return err
}

// Watch for Loki certificates if necessary; we'll ignore in that case the returned digest, as we don't need to restart pods on cert rotation
// because certificate is always reloaded from file
if _, err = r.Watcher.ProcessCACert(ctx, r.Client, &r.Loki.TLS, r.Namespace); err != nil {
return err
}
if _, _, err = r.Watcher.ProcessMTLSCerts(ctx, r.Client, &r.Loki.StatusTLS, r.Namespace); err != nil {
return err
if helper.UseLoki(&desired.Spec) {
// Watch for Loki certificates if necessary; we'll ignore in that case the returned digest, as we don't need to restart pods on cert rotation
// because certificate is always reloaded from file
if _, err = r.Watcher.ProcessCACert(ctx, r.Client, &r.Loki.TLS, r.Namespace); err != nil {
return err
}
if _, _, err = r.Watcher.ProcessMTLSCerts(ctx, r.Client, &r.Loki.StatusTLS, r.Namespace); err != nil {
return err
}
}
} else {
// delete any existing owned object
Expand Down
4 changes: 3 additions & 1 deletion controllers/consoleplugin/consoleplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func getAutoScalerSpecs() (ascv2.HorizontalPodAutoscaler, flowslatest.FlowCollec

func getBuilder(spec *flowslatest.FlowCollectorSpec, lk *helper.LokiConfig) builder {
info := reconcilers.Common{Namespace: testNamespace, Loki: lk}
return newBuilder(info.NewInstance(testImage, status.Instance{}), spec)
b := newBuilder(info.NewInstance(testImage, status.Instance{}), spec)
_, _, _ = b.configMap(context.Background()) // build configmap to update builder's volumes
return b
}

func TestContainerUpdateCheck(t *testing.T) {
Expand Down

0 comments on commit bc0bcef

Please sign in to comment.