Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/operator/reconciler_logs.go
4093 views
1
package operator
2
3
import (
4
"context"
5
"fmt"
6
7
"github.com/go-kit/log"
8
"github.com/go-kit/log/level"
9
gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1"
10
"github.com/grafana/agent/pkg/operator/clientutil"
11
"github.com/grafana/agent/pkg/operator/config"
12
apps_v1 "k8s.io/api/apps/v1"
13
"k8s.io/apimachinery/pkg/types"
14
)
15
16
// createLogsConfigurationSecret creates the Grafana Agent logs configuration
17
// and stores it into a secret.
18
func (r *reconciler) createLogsConfigurationSecret(
19
ctx context.Context,
20
l log.Logger,
21
d gragent.Deployment,
22
) error {
23
24
name := fmt.Sprintf("%s-logs-config", d.Agent.Name)
25
return r.createTelemetryConfigurationSecret(ctx, l, name, d, config.LogsType)
26
}
27
28
// createLogsDaemonSet creates a DaemonSet for logs.
29
func (r *reconciler) createLogsDaemonSet(
30
ctx context.Context,
31
l log.Logger,
32
d gragent.Deployment,
33
) error {
34
35
name := fmt.Sprintf("%s-logs", d.Agent.Name)
36
ds, err := generateLogsDaemonSet(r.config, name, d)
37
if err != nil {
38
return fmt.Errorf("failed to generate DaemonSet: %w", err)
39
}
40
key := types.NamespacedName{Namespace: ds.Namespace, Name: ds.Name}
41
42
if len(d.Logs) == 0 {
43
// There's nothing to deploy; delete anything that might've been deployed
44
// from a previous reconcile.
45
var ds apps_v1.DaemonSet
46
return deleteManagedResource(ctx, r.Client, key, &ds)
47
}
48
49
level.Info(l).Log("msg", "reconciling logs daemonset", "ds", key)
50
err = clientutil.CreateOrUpdateDaemonSet(ctx, r.Client, ds, l)
51
if err != nil {
52
return fmt.Errorf("failed to reconcile statefulset governing service: %w", err)
53
}
54
return nil
55
}
56
57