Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/operator/internal/manifests/indexgateway_test.go

105 lines
3.2 KiB

package manifests_test
import (
"testing"
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/stretchr/testify/require"
policyv1 "k8s.io/api/policy/v1"
)
func TestNewIndexGatewayStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
ss := manifests.NewIndexGatewayStatefulSet(manifests.Options{
Name: "abcd",
Namespace: "efgh",
ConfigSHA1: "deadbeef",
Stack: lokiv1.LokiStackSpec{
StorageClassName: "standard",
Template: &lokiv1.LokiTemplateSpec{
IndexGateway: &lokiv1.LokiComponentSpec{
Replicas: 1,
},
},
},
})
expected := "loki.grafana.com/config-hash"
annotations := ss.Spec.Template.Annotations
require.Contains(t, annotations, expected)
require.Equal(t, annotations[expected], "deadbeef")
}
func TestNewIndexGatewayStatefulSet_HasTemplateCertRotationRequiredAtAnnotation(t *testing.T) {
ss := manifests.NewIndexGatewayStatefulSet(manifests.Options{
Name: "abcd",
Namespace: "efgh",
CertRotationRequiredAt: "deadbeef",
Stack: lokiv1.LokiStackSpec{
StorageClassName: "standard",
Template: &lokiv1.LokiTemplateSpec{
IndexGateway: &lokiv1.LokiComponentSpec{
Replicas: 1,
},
},
},
})
expected := "loki.grafana.com/certRotationRequiredAt"
annotations := ss.Spec.Template.Annotations
require.Contains(t, annotations, expected)
require.Equal(t, annotations[expected], "deadbeef")
}
func TestNewIndexGatewayStatefulSet_SelectorMatchesLabels(t *testing.T) {
// You must set the .spec.selector field of a StatefulSet to match the labels of
// its .spec.template.metadata.labels. Prior to Kubernetes 1.8, the
// .spec.selector field was defaulted when omitted. In 1.8 and later versions,
// failing to specify a matching Pod Selector will result in a validation error
// during StatefulSet creation.
// See https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-selector
ss := manifests.NewIndexGatewayStatefulSet(manifests.Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
StorageClassName: "standard",
Template: &lokiv1.LokiTemplateSpec{
IndexGateway: &lokiv1.LokiComponentSpec{
Replicas: 1,
},
},
},
})
l := ss.Spec.Template.GetObjectMeta().GetLabels()
for key, value := range ss.Spec.Selector.MatchLabels {
require.Contains(t, l, key)
require.Equal(t, l[key], value)
}
}
func TestBuildIndexGateway_PodDisruptionBudget(t *testing.T) {
opts := manifests.Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Template: &lokiv1.LokiTemplateSpec{
IndexGateway: &lokiv1.LokiComponentSpec{
Replicas: 1,
},
},
},
}
objs, err := manifests.BuildIndexGateway(opts)
require.NoError(t, err)
require.Len(t, objs, 4)
pdb := objs[3].(*policyv1.PodDisruptionBudget)
require.NotNil(t, pdb)
require.Equal(t, "abcd-index-gateway", pdb.Name)
require.Equal(t, "efgh", pdb.Namespace)
require.NotNil(t, pdb.Spec.MinAvailable.IntVal)
require.Equal(t, int32(1), pdb.Spec.MinAvailable.IntVal)
require.EqualValues(t, manifests.ComponentLabels(manifests.LabelIndexGatewayComponent, opts.Name),
pdb.Spec.Selector.MatchLabels)
}