mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 10:19:54 +00:00
feat: Install goldpinger daemonset if one does not exist when running goldpinger collector (#1619)
* feat: Install goldpinger if one does not exist when running goldpinger collector - Deploy golpinger daemonset if one is not detected in the cluster - Clean up all deployed resources - Add delay to allow users to wait for goldpinger to perform checks Signed-off-by: Evans Mungai <evans@replicated.com> * Add missing test data file Signed-off-by: Evans Mungai <evans@replicated.com> * Better naming of create resource functions Signed-off-by: Evans Mungai <evans@replicated.com> --------- Signed-off-by: Evans Mungai <evans@replicated.com>
This commit is contained in:
@@ -10,19 +10,12 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/replicatedhq/troubleshoot/internal/testutils"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/convert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/e2e-framework/klient/wait"
|
||||
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
|
||||
"sigs.k8s.io/e2e-framework/pkg/envconf"
|
||||
"sigs.k8s.io/e2e-framework/pkg/features"
|
||||
"sigs.k8s.io/e2e-framework/third_party/helm"
|
||||
)
|
||||
|
||||
var specTemplate = `
|
||||
@@ -38,43 +31,13 @@ spec:
|
||||
exclude: true
|
||||
- goldpinger:
|
||||
namespace: $NAMESPACE
|
||||
collectDelay: 20s
|
||||
analyzers:
|
||||
- goldpinger: {}
|
||||
`
|
||||
|
||||
func Test_GoldpingerCollector(t *testing.T) {
|
||||
releaseName := "goldpinger"
|
||||
|
||||
feature := features.New("Goldpinger collector and analyser").
|
||||
Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
|
||||
cluster := getClusterFromContext(t, ctx, ClusterName)
|
||||
|
||||
manager := helm.New(cluster.GetKubeconfig())
|
||||
err := manager.RunInstall(
|
||||
helm.WithName(releaseName),
|
||||
helm.WithNamespace(c.Namespace()),
|
||||
helm.WithChart(testutils.TestFixtureFilePath(t, "charts/goldpinger-6.0.1.tgz")),
|
||||
helm.WithWait(),
|
||||
helm.WithTimeout("2m"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
client, err := c.NewClient()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Lets wait for the goldpinger pods to be running
|
||||
ds := &appsv1.DaemonSet{ObjectMeta: metav1.ObjectMeta{Name: "goldpinger", Namespace: c.Namespace()}}
|
||||
err = wait.For(
|
||||
conditions.New(client.Resources()).DaemonSetReady(ds),
|
||||
wait.WithTimeout(time.Second*30),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// HACK: wait for goldpinger to do its thing
|
||||
time.Sleep(time.Second * 30)
|
||||
|
||||
return ctx
|
||||
}).
|
||||
Assess("collect and analyse goldpinger pings", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
|
||||
var out bytes.Buffer
|
||||
var stdErr bytes.Buffer
|
||||
@@ -107,8 +70,8 @@ func Test_GoldpingerCollector(t *testing.T) {
|
||||
|
||||
// Check that we analysed collected goldpinger results.
|
||||
// We should expect a single analysis result for goldpinger.
|
||||
assert.Equal(t, 1, len(analysisResults))
|
||||
assert.True(t, strings.HasPrefix(analysisResults[0].Name, "pings.to.goldpinger."))
|
||||
require.Equal(t, 1, len(analysisResults))
|
||||
assert.True(t, strings.HasPrefix(analysisResults[0].Name, "pings.to.ts.goldpinger."))
|
||||
if t.Failed() {
|
||||
t.Logf("Analysis results: %s\n", analysisJSON)
|
||||
t.Logf("Stdout: %s\n", out.String())
|
||||
@@ -117,14 +80,6 @@ func Test_GoldpingerCollector(t *testing.T) {
|
||||
}
|
||||
|
||||
return ctx
|
||||
}).
|
||||
Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
|
||||
cluster := getClusterFromContext(t, ctx, ClusterName)
|
||||
manager := helm.New(cluster.GetKubeconfig())
|
||||
err := manager.RunUninstall(helm.WithName(releaseName), helm.WithNamespace(c.Namespace()))
|
||||
require.NoError(t, err)
|
||||
return ctx
|
||||
}).
|
||||
Feature()
|
||||
}).Feature()
|
||||
testenv.Test(t, feature)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user