Skip to content

Commit

Permalink
Merge pull request #134 from JoaoBraveCoding/backport-pr-9433-6
Browse files Browse the repository at this point in the history
[release-5.6] Backport PR grafana#9433
  • Loading branch information
openshift-merge-robot authored May 10, 2023
2 parents 6a3b438 + b13ac1e commit 26d20ce
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 98 deletions.
9 changes: 4 additions & 5 deletions operator/internal/manifests/compactor_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package manifests_test
package manifests

import (
"testing"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/stretchr/testify/require"
)

Expand All @@ -15,7 +14,7 @@ func TestNewCompactorStatefulSet_SelectorMatchesLabels(t *testing.T) {
// 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
sts := manifests.NewCompactorStatefulSet(manifests.Options{
sts := NewCompactorStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Expand All @@ -36,7 +35,7 @@ func TestNewCompactorStatefulSet_SelectorMatchesLabels(t *testing.T) {
}

func TestNewCompactorStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
ss := manifests.NewCompactorStatefulSet(manifests.Options{
ss := NewCompactorStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
ConfigSHA1: "deadbeef",
Expand All @@ -56,7 +55,7 @@ func TestNewCompactorStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
}

func TestNewCompactorStatefulSet_HasTemplateCertRotationRequiredAtAnnotation(t *testing.T) {
ss := manifests.NewCompactorStatefulSet(manifests.Options{
ss := NewCompactorStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
CertRotationRequiredAt: "deadbeef",
Expand Down
53 changes: 26 additions & 27 deletions operator/internal/manifests/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package manifests_test
package manifests

import (
"encoding/json"
Expand All @@ -8,7 +8,6 @@ import (
"github.com/google/uuid"
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/apis/loki/v1beta1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/grafana/loki/operator/internal/manifests/internal/config"
"github.com/grafana/loki/operator/internal/manifests/openshift"
"github.com/stretchr/testify/assert"
Expand All @@ -20,17 +19,17 @@ import (
func TestConfigMap_ReturnsSHA1OfBinaryContents(t *testing.T) {
opts := randomConfigOptions()

_, sha1C, err := manifests.LokiConfigMap(opts)
_, sha1C, err := LokiConfigMap(opts)
require.NoError(t, err)
require.NotEmpty(t, sha1C)
}

func TestConfigOptions_UserOptionsTakePrecedence(t *testing.T) {
// regardless of what is provided by the default sizing parameters we should always prefer
// the user-defined values. This creates an all-inclusive manifests.Options and then checks
// the user-defined values. This creates an all-inclusive Options and then checks
// that every value is present in the result
opts := randomConfigOptions()
res := manifests.ConfigOptions(opts)
res := ConfigOptions(opts)

expected, err := json.Marshal(opts.Stack)
require.NoError(t, err)
Expand All @@ -41,8 +40,8 @@ func TestConfigOptions_UserOptionsTakePrecedence(t *testing.T) {
assert.JSONEq(t, string(expected), string(actual))
}

func randomConfigOptions() manifests.Options {
return manifests.Options{
func randomConfigOptions() Options {
return Options{
Name: uuid.New().String(),
Namespace: uuid.New().String(),
Image: uuid.New().String(),
Expand Down Expand Up @@ -250,12 +249,12 @@ func TestConfigOptions_GossipRingConfig(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

inOpt := manifests.Options{
inOpt := Options{
Name: "my-stack",
Namespace: "my-ns",
Stack: tc.spec,
}
options := manifests.ConfigOptions(inOpt)
options := ConfigOptions(inOpt)
require.Equal(t, tc.wantOptions, options.GossipRing)
})
}
Expand Down Expand Up @@ -358,10 +357,10 @@ func TestConfigOptions_RetentionConfig(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

inOpt := manifests.Options{
inOpt := Options{
Stack: tc.spec,
}
options := manifests.ConfigOptions(inOpt)
options := ConfigOptions(inOpt)
require.Equal(t, tc.wantOptions, options.Retention)
})
}
Expand All @@ -370,12 +369,12 @@ func TestConfigOptions_RetentionConfig(t *testing.T) {
func TestConfigOptions_RulerAlertManager(t *testing.T) {
tt := []struct {
desc string
opts manifests.Options
opts Options
wantOptions *config.AlertManagerConfig
}{
{
desc: "static mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.Static,
Expand All @@ -386,7 +385,7 @@ func TestConfigOptions_RulerAlertManager(t *testing.T) {
},
{
desc: "dynamic mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.Dynamic,
Expand All @@ -397,7 +396,7 @@ func TestConfigOptions_RulerAlertManager(t *testing.T) {
},
{
desc: "openshift-logging mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.OpenshiftLogging,
Expand All @@ -418,7 +417,7 @@ func TestConfigOptions_RulerAlertManager(t *testing.T) {
},
{
desc: "openshift-network mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.OpenshiftNetwork,
Expand All @@ -444,8 +443,8 @@ func TestConfigOptions_RulerAlertManager(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

cfg := manifests.ConfigOptions(tc.opts)
err := manifests.ConfigureOptionsForMode(&cfg, tc.opts)
cfg := ConfigOptions(tc.opts)
err := ConfigureOptionsForMode(&cfg, tc.opts)

require.Nil(t, err)
require.Equal(t, tc.wantOptions, cfg.Ruler.AlertManager)
Expand All @@ -456,12 +455,12 @@ func TestConfigOptions_RulerAlertManager(t *testing.T) {
func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
tt := []struct {
desc string
opts manifests.Options
opts Options
wantOptions *config.AlertManagerConfig
}{
{
desc: "static mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.Static,
Expand All @@ -472,7 +471,7 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
},
{
desc: "dynamic mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.Dynamic,
Expand All @@ -483,7 +482,7 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
},
{
desc: "openshift-logging mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.OpenshiftLogging,
Expand All @@ -492,7 +491,7 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
Enabled: true,
},
},
Ruler: manifests.Ruler{
Ruler: Ruler{
Spec: &v1beta1.RulerConfigSpec{
AlertManagerSpec: &v1beta1.AlertManagerSpec{
EnableV2: false,
Expand All @@ -519,7 +518,7 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
},
{
desc: "openshift-network mode",
opts: manifests.Options{
opts: Options{
Stack: lokiv1.LokiStackSpec{
Tenants: &lokiv1.TenantsSpec{
Mode: lokiv1.OpenshiftNetwork,
Expand All @@ -528,7 +527,7 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
Enabled: true,
},
},
Ruler: manifests.Ruler{
Ruler: Ruler{
Spec: &v1beta1.RulerConfigSpec{
AlertManagerSpec: &v1beta1.AlertManagerSpec{
EnableV2: false,
Expand Down Expand Up @@ -560,8 +559,8 @@ func TestConfigOptions_RulerAlertManager_UserOverride(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

cfg := manifests.ConfigOptions(tc.opts)
err := manifests.ConfigureOptionsForMode(&cfg, tc.opts)
cfg := ConfigOptions(tc.opts)
err := ConfigureOptionsForMode(&cfg, tc.opts)
require.Nil(t, err)
require.Equal(t, tc.wantOptions, cfg.Ruler.AlertManager)
})
Expand Down
9 changes: 4 additions & 5 deletions operator/internal/manifests/distributor_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package manifests_test
package manifests

import (
"testing"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/stretchr/testify/require"
)

func TestNewDistributorDeployment_SelectorMatchesLabels(t *testing.T) {
dpl := manifests.NewDistributorDeployment(manifests.Options{
dpl := NewDistributorDeployment(Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Expand All @@ -29,7 +28,7 @@ func TestNewDistributorDeployment_SelectorMatchesLabels(t *testing.T) {
}

func TestNewDistributorDeployment_HasTemplateConfigHashAnnotation(t *testing.T) {
ss := manifests.NewDistributorDeployment(manifests.Options{
ss := NewDistributorDeployment(Options{
Name: "abcd",
Namespace: "efgh",
ConfigSHA1: "deadbeef",
Expand All @@ -49,7 +48,7 @@ func TestNewDistributorDeployment_HasTemplateConfigHashAnnotation(t *testing.T)
}

func TestNewDistributorDeployment_HasTemplateCertRotationRequiredAtAnnotation(t *testing.T) {
ss := manifests.NewDistributorDeployment(manifests.Options{
ss := NewDistributorDeployment(Options{
Name: "abcd",
Namespace: "efgh",
CertRotationRequiredAt: "deadbeef",
Expand Down
9 changes: 4 additions & 5 deletions operator/internal/manifests/indexgateway_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package manifests_test
package manifests

import (
"testing"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/stretchr/testify/require"
)

func TestNewIndexGatewayStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
ss := manifests.NewIndexGatewayStatefulSet(manifests.Options{
ss := NewIndexGatewayStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
ConfigSHA1: "deadbeef",
Expand All @@ -30,7 +29,7 @@ func TestNewIndexGatewayStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T
}

func TestNewIndexGatewayStatefulSet_HasTemplateCertRotationRequiredAtAnnotation(t *testing.T) {
ss := manifests.NewIndexGatewayStatefulSet(manifests.Options{
ss := NewIndexGatewayStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
CertRotationRequiredAt: "deadbeef",
Expand All @@ -56,7 +55,7 @@ func TestNewIndexGatewayStatefulSet_SelectorMatchesLabels(t *testing.T) {
// 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{
ss := NewIndexGatewayStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Expand Down
9 changes: 4 additions & 5 deletions operator/internal/manifests/ingester_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package manifests_test
package manifests

import (
"testing"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/stretchr/testify/require"
)

func TestNewIngesterStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
ss := manifests.NewIngesterStatefulSet(manifests.Options{
ss := NewIngesterStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
ConfigSHA1: "deadbeef",
Expand All @@ -30,7 +29,7 @@ func TestNewIngesterStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
}

func TestNewIngesterStatefulSet_HasTemplateCertRotationRequiredAtAnnotation(t *testing.T) {
ss := manifests.NewIngesterStatefulSet(manifests.Options{
ss := NewIngesterStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
CertRotationRequiredAt: "deadbeef",
Expand All @@ -56,7 +55,7 @@ func TestNewIngesterStatefulSet_SelectorMatchesLabels(t *testing.T) {
// 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
sts := manifests.NewIngesterStatefulSet(manifests.Options{
sts := NewIngesterStatefulSet(Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Expand Down
Loading

0 comments on commit 26d20ce

Please sign in to comment.