Skip to content

Commit

Permalink
Add tests for checking propagation of custom args
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Baungard Hansen <[email protected]>
  • Loading branch information
jacobbaungard committed Jan 5, 2024
1 parent c3e0fda commit 3c3182f
Showing 1 changed file with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package multiclusterobservability
import (
"bytes"
"context"
"reflect"
"testing"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -313,3 +314,122 @@ config:
}
}
}

func TestObservatoriumCustomArgs(t *testing.T) {
testArgs := []string{"--arg1", "--arg2", "--args3"}
mco := &mcov1beta2.MultiClusterObservability{
TypeMeta: metav1.TypeMeta{Kind: "MultiClusterObservability"},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Annotations: map[string]string{
mcoconfig.AnnotationKeyImageRepository: "quay.io:443/acm-d",
mcoconfig.AnnotationKeyImageTagSuffix: "tag",
},
},
Spec: mcov1beta2.MultiClusterObservabilitySpec{
StorageConfig: &mcov1beta2.StorageConfig{
MetricObjectStorage: &mcoshared.PreConfiguredStorage{
Key: "key",
Name: "name",
TLSSecretName: "secret",
},
WriteStorage: []*mcoshared.PreConfiguredStorage{
{
Key: "write_key",
Name: "write_name",
},
},
StorageClass: storageClassName,
AlertmanagerStorageSize: "1Gi",
CompactStorageSize: "1Gi",
RuleStorageSize: "1Gi",
ReceiveStorageSize: "1Gi",
StoreStorageSize: "1Gi",
},
ObservabilityAddonSpec: &mcoshared.ObservabilityAddonSpec{
EnableMetrics: true,
Interval: 300,
},
AdvancedConfig: &mcov1beta2.AdvancedConfig{
Receive: &mcov1beta2.ReceiveSpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
Store: &mcov1beta2.StoreSpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
Query: &mcov1beta2.QuerySpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
Rule: &mcov1beta2.RuleSpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
Compact: &mcov1beta2.CompactSpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
QueryFrontend: &mcov1beta2.QueryFrontendSpec{
Containers: []corev1.Container{
{
Args: testArgs,
},
},
},
},
},
}

writeStorageS := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "write_name",
Namespace: mcoconfig.GetDefaultNamespace(),
},
Type: "Opaque",
Data: map[string][]byte{
"write_key": []byte(`url: http://remotewrite/endpoint
`),
},
}

objs := []runtime.Object{mco, writeStorageS}
// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()

obs, _ := newDefaultObservatoriumSpec(cl, mco, storageClassName, "")
if !reflect.DeepEqual(obs.Thanos.Receivers.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to Receive Observatorium spec")
}
if !reflect.DeepEqual(obs.Thanos.Store.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to Store Observatorium spec")
}
if !reflect.DeepEqual(obs.Thanos.Query.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to Query Observatorium spec")
}
if !reflect.DeepEqual(obs.Thanos.Rule.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to Rule Observatorium spec")
}
if !reflect.DeepEqual(obs.Thanos.Compact.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to Compact Observatorium spec")
}
if !reflect.DeepEqual(obs.Thanos.QueryFrontend.Containers[0].Args, testArgs) {
t.Errorf("Failed to propagate custom args to QueryFrontend Observatorium spec")
}
}

0 comments on commit 3c3182f

Please sign in to comment.