-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: stabilize case single_prometheus_replica_has_no_pdb (#425)
* test: stalize monitoringstack cases Refactor code and also enhance the following cases TestMonitoringStackController/single_prometheus_replica_has_no_pdb TestMonitoringStackController/Alertmanager_disabled TestMonitoringStackController/Verify_ability_to_scale_down_Prometheus * test: fixed review comments
- Loading branch information
1 parent
cd91a5f
commit 463f767
Showing
2 changed files
with
53 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package framework | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
stack "github.com/rhobs/observability-operator/pkg/apis/monitoring/v1alpha1" | ||
"gotest.tools/v3/assert" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/util/retry" | ||
) | ||
|
||
type MonitoringStackConfig func(monitoringStack *stack.MonitoringStack) | ||
|
||
func SetPrometheusReplicas(replicas int32) MonitoringStackConfig { | ||
return func(ms *stack.MonitoringStack) { | ||
ms.Spec.PrometheusConfig.Replicas = &replicas | ||
} | ||
} | ||
|
||
func SetResourceSelector(resourceSelector *v1.LabelSelector) MonitoringStackConfig { | ||
return func(ms *stack.MonitoringStack) { | ||
ms.Spec.ResourceSelector = resourceSelector | ||
} | ||
} | ||
|
||
func SetAlertmanagerDisabled(disabled bool) MonitoringStackConfig { | ||
return func(ms *stack.MonitoringStack) { | ||
ms.Spec.AlertmanagerConfig.Disabled = disabled | ||
} | ||
} | ||
|
||
// 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) | ||
assert.NilError(t, err, "failed to get a monitoring stack") | ||
for _, fn := range fns { | ||
fn(ms) | ||
} | ||
err = f.K8sClient.Update(context.Background(), ms) | ||
return err | ||
}) | ||
return err | ||
} |
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