Skip to content

Commit

Permalink
Fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lihongyan1 committed Feb 28, 2024
1 parent 7aa4e6c commit 9ed6838
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions test/e2e/framework/monitoring_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ import (
"k8s.io/client-go/util/retry"
)

type StackFn func(monitoringStack *stack.MonitoringStack)
type MonitoringStackConfig func(monitoringStack *stack.MonitoringStack)

func SetPrometheusReplicas(replicas *int32) StackFn {
func SetPrometheusReplicas(replicas int32) MonitoringStackConfig {
return func(ms *stack.MonitoringStack) {
ms.Spec.PrometheusConfig.Replicas = replicas
ms.Spec.PrometheusConfig.Replicas = &replicas
}
}
func SetResourceSelector(resourceSelector *v1.LabelSelector) StackFn {

func SetResourceSelector(resourceSelector *v1.LabelSelector) MonitoringStackConfig {
return func(ms *stack.MonitoringStack) {
ms.Spec.ResourceSelector = resourceSelector
}
}
func SetAlertmanagerDisabled(disabled bool) StackFn {

func SetAlertmanagerDisabled(disabled bool) MonitoringStackConfig {
return func(ms *stack.MonitoringStack) {
ms.Spec.AlertmanagerConfig.Disabled = disabled
}
}

// Update monitoringstack with retry
func (f *Framework) UpdateWithRetry(t *testing.T, ms *stack.MonitoringStack, fns ...StackFn) error {
// UpdateWithRetry updates monitoringstack with retry
func (f *Framework) UpdateWithRetry(t *testing.T, ms *stack.MonitoringStack, fns ...MonitoringStackConfig) error {
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
key := types.NamespacedName{Name: ms.Name, Namespace: ms.Namespace}
err := f.K8sClient.Get(context.Background(), key, ms)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/monitoring_stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func singlePrometheusReplicaHasNoPDB(t *testing.T) {
f.AssertResourceEventuallyExists(pdbName, ms.Namespace, &pdb)(t)

// Update replica count to 1
err = f.UpdateWithRetry(t, ms, framework.SetPrometheusReplicas(intPtr(1)))
err = f.UpdateWithRetry(t, ms, framework.SetPrometheusReplicas(1))
assert.NilError(t, err, "failed to update monitoring stack")

// ensure there is no pdb
Expand Down Expand Up @@ -568,7 +568,7 @@ func prometheusScaleDown(t *testing.T) {

assert.Equal(t, prom.Status.Replicas, int32(1))

err = f.UpdateWithRetry(t, ms, framework.SetPrometheusReplicas(intPtr(0)))
err = f.UpdateWithRetry(t, ms, framework.SetPrometheusReplicas(0))
key := types.NamespacedName{Name: ms.Name, Namespace: ms.Namespace}
assert.NilError(t, err, "failed to update a monitoring stack")
err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, framework.DefaultTestTimeout, true, func(ctx context.Context) (bool, error) {
Expand Down

0 comments on commit 9ed6838

Please sign in to comment.