Skip to content

Commit 3eb0505

Browse files
committed
Configurable cluster name
1 parent 6448f00 commit 3eb0505

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

internal/auditlog/tail.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"google.golang.org/genproto/googleapis/cloud/audit"
1414
)
1515

16-
func Tail(ctx context.Context, projectID string, cb func(*audit.AuditLog) error) error {
16+
func Tail(ctx context.Context, projectID, clusterName string, cb func(*audit.AuditLog) error) error {
1717
client, err := logging.NewClient(ctx)
1818
if err != nil {
1919
return fmt.Errorf("failed to create client: %w", err)
@@ -34,7 +34,7 @@ func Tail(ctx context.Context, projectID string, cb func(*audit.AuditLog) error)
3434
[]string{
3535
`resource.type="k8s_cluster"`,
3636
fmt.Sprintf(`log_name="projects/%s/logs/cloudaudit.googleapis.com%%2Factivity"`, projectID),
37-
`resource.labels.cluster_name="platform"`,
37+
fmt.Sprintf(`resource.labels.cluster_name="%s"`, clusterName),
3838
`protoPayload."@type"="type.googleapis.com/google.cloud.audit.AuditLog"`,
3939
`protoPayload.methodName=~"io\.fluxcd\.toolkit\..*\.patch"`,
4040
`-protoPayload.authenticationInfo.principalEmail=~"system:.*"`,
@@ -43,7 +43,7 @@ func Tail(ctx context.Context, projectID string, cb func(*audit.AuditLog) error)
4343
),
4444
}
4545
if err = stream.Send(req); err != nil {
46-
return fmt.Errorf("stream.Send error: %w", err)
46+
return fmt.Errorf("stream send failed: %w", err)
4747
}
4848

4949
return read(ctx, stream, cb)

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
type Config struct {
1111
GoogleCloudProjectID string `yaml:"googleCloudProjectId"`
12+
GKEClusterName string `yaml:"gkeClusterName"`
1213
BadgerPath string `yaml:"badgerPath"`
1314
KubernetesConfigPath string `yaml:"kubernetesConfigPath,omitempty"`
1415
Notification struct {

internal/watch/watcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
type Watcher struct {
1818
googleCloudProjectID string
19+
gkeClusterName string
1920
k8sClient k8sClient
2021
store store
2122
notifier notifier
@@ -49,7 +50,7 @@ type notifier interface {
4950
}
5051

5152
func (w *Watcher) Watch(ctx context.Context) error {
52-
return auditlog.Tail(ctx, w.googleCloudProjectID, func(logEntry *audit.AuditLog) error {
53+
return auditlog.Tail(ctx, w.googleCloudProjectID, w.gkeClusterName, func(logEntry *audit.AuditLog) error {
5354
if code := logEntry.GetStatus().GetCode(); code != 0 {
5455
slog.Warn("operation appeared to fail", slog.Int("code", int(code)))
5556
return nil

0 commit comments

Comments
 (0)