generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for alloy-events in events-logger-config (#277)
* add tests for alloy-events in events-logger-config * changelog * create alloy-events tests golden files
- Loading branch information
1 parent
fa22e3e
commit 44084d8
Showing
4 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
pkg/resource/events-logger-config/alloy-events-config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package eventsloggerconfig | ||
|
||
import ( | ||
_ "embed" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
capi "sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
||
loggedcluster "github.com/giantswarm/logging-operator/pkg/logged-cluster" | ||
"github.com/giantswarm/logging-operator/pkg/logged-cluster/capicluster" | ||
) | ||
|
||
func TestGenerateAlloyEventsConfig(t *testing.T) { | ||
testCases := []struct { | ||
goldenFile string | ||
defaultNamespaces []string | ||
installationName string | ||
clusterName string | ||
}{ | ||
{ | ||
goldenFile: "alloy/test/events-logger-config.alloy.MC.yaml", | ||
installationName: "test-installation", | ||
clusterName: "test-installation", | ||
}, | ||
{ | ||
goldenFile: "alloy/test/events-logger-config.alloy.WC.yaml", | ||
installationName: "test-installation", | ||
clusterName: "test-cluster", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(filepath.Base(tc.goldenFile), func(t *testing.T) { | ||
golden, err := os.ReadFile(tc.goldenFile) | ||
if err != nil { | ||
t.Fatalf("Failed to read golden file: %v", err) | ||
} | ||
|
||
loggedCluster := &capicluster.Object{ | ||
Object: &capi.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: tc.clusterName, | ||
}, | ||
}, | ||
Options: loggedcluster.Options{ | ||
InstallationName: tc.installationName, | ||
KubeEventsLogger: "alloy", | ||
}, | ||
} | ||
|
||
config, err := generateAlloyEventsConfig(loggedCluster, []string{"kube-system", "giantswarm"}) | ||
if err != nil { | ||
t.Fatalf("Failed to generate alloy config: %v", err) | ||
} | ||
|
||
if string(golden) != config { | ||
t.Logf("Generated config differs from %s, diff:\n%s", tc.goldenFile, cmp.Diff(string(golden), config)) | ||
t.Fail() | ||
if *update { | ||
//nolint:gosec | ||
if err := os.WriteFile(tc.goldenFile, []byte(config), 0644); err != nil { | ||
t.Fatalf("Failed to update golden file: %v", err) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
pkg/resource/events-logger-config/alloy/test/events-logger-config.alloy.MC.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This file was generated by logging-operator. | ||
# It configures Alloy to be used as events logger. | ||
# - configMap is generated from events-logger.alloy.template and passed as a string | ||
# here and will be created by Alloy's chart. | ||
# - Alloy runs as a deployment, with only 1 replica. | ||
alloy: | ||
alloy: | ||
configMap: | ||
create: true | ||
content: |- | ||
loki.source.kubernetes_events "local" { | ||
namespaces = [] | ||
forward_to = [loki.write.default.receiver] | ||
} | ||
// Loki target configuration | ||
loki.write "default" { | ||
endpoint { | ||
url = env("LOKI_URL") | ||
max_backoff_period = "10m" | ||
tenant_id = env("TENANT_ID") | ||
basic_auth { | ||
username = env("BASIC_AUTH_USERNAME") | ||
password = env("BASIC_AUTH_PASSWORD") | ||
} | ||
tls_config { | ||
insecure_skip_verify = false | ||
} | ||
} | ||
external_labels = { | ||
cluster_id = "test-installation", | ||
installation = "test-installation", | ||
scrape_job = "kubernetes-events", | ||
} | ||
} | ||
logging { | ||
level = "info" | ||
format = "logfmt" | ||
} | ||
envFrom: | ||
- secretRef: | ||
name: alloy-events | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
capabilities: | ||
drop: | ||
- ALL | ||
readOnlyRootFilesystem: false | ||
runAsUser: 10 | ||
runAsGroup: 10 | ||
runAsNonRoot: true | ||
seccompProfile: | ||
type: RuntimeDefault | ||
controller: | ||
type: deployment | ||
replicas: 1 | ||
crds: | ||
create: false |
62 changes: 62 additions & 0 deletions
62
pkg/resource/events-logger-config/alloy/test/events-logger-config.alloy.WC.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This file was generated by logging-operator. | ||
# It configures Alloy to be used as events logger. | ||
# - configMap is generated from events-logger.alloy.template and passed as a string | ||
# here and will be created by Alloy's chart. | ||
# - Alloy runs as a deployment, with only 1 replica. | ||
alloy: | ||
alloy: | ||
configMap: | ||
create: true | ||
content: |- | ||
loki.source.kubernetes_events "local" { | ||
namespaces = ["kube-system", "giantswarm"] | ||
forward_to = [loki.write.default.receiver] | ||
} | ||
// Loki target configuration | ||
loki.write "default" { | ||
endpoint { | ||
url = env("LOKI_URL") | ||
max_backoff_period = "10m" | ||
tenant_id = env("TENANT_ID") | ||
basic_auth { | ||
username = env("BASIC_AUTH_USERNAME") | ||
password = env("BASIC_AUTH_PASSWORD") | ||
} | ||
tls_config { | ||
insecure_skip_verify = false | ||
} | ||
} | ||
external_labels = { | ||
cluster_id = "test-cluster", | ||
installation = "test-installation", | ||
scrape_job = "kubernetes-events", | ||
} | ||
} | ||
logging { | ||
level = "info" | ||
format = "logfmt" | ||
} | ||
envFrom: | ||
- secretRef: | ||
name: alloy-events | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
capabilities: | ||
drop: | ||
- ALL | ||
readOnlyRootFilesystem: false | ||
runAsUser: 10 | ||
runAsGroup: 10 | ||
runAsNonRoot: true | ||
seccompProfile: | ||
type: RuntimeDefault | ||
controller: | ||
type: deployment | ||
replicas: 1 | ||
crds: | ||
create: false |