Skip to content

Commit 9abd918

Browse files
committed
test: fix kind image in go tests, improve test debug
Signed-off-by: Peter Wilcsinszky <[email protected]>
1 parent c21548f commit 9abd918

File tree

9 files changed

+84
-47
lines changed

9 files changed

+84
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ GOLANGCI_LINT_VERSION := v1.51.2
3535

3636
KIND := ${BIN}/kind
3737
KIND_VERSION := v0.19.0
38-
KIND_IMAGE := v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff
38+
KIND_IMAGE := kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff
3939

4040
KUBEBUILDER := ${BIN}/kubebuilder
4141
KUBEBUILDER_VERSION = v3.1.0

e2e/common/cluster.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"emperror.dev/errors"
2626
"github.com/spf13/cast"
2727
"github.com/stretchr/testify/assert"
28-
"github.com/stretchr/testify/require"
2928
"k8s.io/client-go/rest"
3029
"k8s.io/client-go/tools/clientcmd"
3130
"sigs.k8s.io/controller-runtime/pkg/cluster"
@@ -49,18 +48,18 @@ type PrintLogConfig struct {
4948

5049
func WithCluster(name string, t *testing.T, fn func(*testing.T, Cluster), beforeCleanup func(*testing.T, Cluster) error, opts ...cluster.Option) {
5150
cluster, err := GetTestCluster(name, opts...)
52-
require.NoError(t, err)
51+
RequireNoError(t, err)
5352

5453
ctx, cancel := context.WithCancel(context.Background())
5554
go func() {
56-
require.NoError(t, cluster.Start(ctx))
55+
RequireNoError(t, cluster.Start(ctx))
5756
}()
5857

5958
defer func() {
6059
assert.NoError(t, beforeCleanup(t, cluster))
6160
assert.NoError(t, cluster.Cleanup())
6261
cancel()
63-
require.NoError(t, DeleteTestCluster(name))
62+
RequireNoError(t, DeleteTestCluster(name))
6463
}()
6564

6665
fn(t, cluster)

e2e/common/helpers.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright © 2023 Kube logging authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package common
16+
17+
import (
18+
"fmt"
19+
"testing"
20+
21+
"emperror.dev/errors"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func RequireNoError(t *testing.T, err error) {
26+
if err != nil {
27+
assert.Fail(t, fmt.Sprintf("Received unexpected error:\n%#v %+v", err, errors.GetDetails(err)))
28+
t.FailNow()
29+
}
30+
}

e2e/common/kind/commands.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ func CreateCluster(options CreateClusterOptions) error {
3939
options.Image = KindImage
4040
}
4141
args = options.AppendToArgs(args)
42-
_, err := exec.Command(KindPath, args...).Output()
42+
cmd := exec.Command(KindPath, args...)
43+
cmd.Stderr = os.Stderr
44+
o, err := cmd.Output()
45+
if err != nil {
46+
fmt.Println(o)
47+
}
4348
return err
4449
}
4550

e2e/common/setup/logconsumer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626

27+
"github.com/kube-logging/logging-operator/e2e/common"
2728
"github.com/kube-logging/logging-operator/e2e/common/cond"
2829
)
2930

@@ -142,8 +143,8 @@ func LogConsumer(t *testing.T, c client.Client, opts ...LogConsumerOption) LogCo
142143
},
143144
}
144145
ctx := context.Background()
145-
require.NoError(t, c.Create(ctx, &logConsumerPod))
146-
require.NoError(t, c.Create(ctx, &logConsumerSvc))
146+
common.RequireNoError(t, c.Create(ctx, &logConsumerPod))
147+
common.RequireNoError(t, c.Create(ctx, &logConsumerSvc))
147148
require.Eventually(t, cond.PodShouldBeRunning(t, c, client.ObjectKeyFromObject(&logConsumerPod)), 5*time.Minute, 5*time.Second)
148149
return LogConsumerResult{
149150
PodKey: client.ObjectKeyFromObject(&logConsumerPod),

e2e/common/setup/loggingoperator.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ import (
2525
"github.com/cisco-open/operator-tools/pkg/utils"
2626
"github.com/go-logr/logr"
2727
logrtesting "github.com/go-logr/logr/testing"
28-
"github.com/kube-logging/logging-operator/pkg/sdk/resourcebuilder"
2928
"github.com/stretchr/testify/require"
3029
corev1 "k8s.io/api/core/v1"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
3231

32+
"github.com/kube-logging/logging-operator/pkg/sdk/resourcebuilder"
33+
3334
"github.com/kube-logging/logging-operator/e2e/common"
3435
)
3536

@@ -50,7 +51,7 @@ func LoggingOperator(t *testing.T, c common.Cluster, opts ...LoggingOperatorOpti
5051
}
5152

5253
if img := os.Getenv("LOGGING_OPERATOR_IMAGE"); img != "" {
53-
require.NoError(t, c.LoadImages(img))
54+
common.RequireNoError(t, c.LoadImages(img))
5455

5556
if options.Config.ContainerOverrides == nil {
5657
options.Config.ContainerOverrides = new(types.ContainerBase)
@@ -69,9 +70,9 @@ func LoggingOperator(t *testing.T, c common.Cluster, opts ...LoggingOperatorOpti
6970
})
7071
for _, rb := range resourceBuilders {
7172
obj, ds, err := rb()
72-
require.NoError(t, err)
73+
common.RequireNoError(t, err)
7374
res, err := reconciler.ReconcileResource(obj, ds)
74-
require.NoError(t, err)
75+
common.RequireNoError(t, err)
7576
require.Nil(t, res)
7677
}
7778

e2e/common/setup/logproducer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/labels"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929

30+
"github.com/kube-logging/logging-operator/e2e/common"
3031
"github.com/kube-logging/logging-operator/e2e/common/cond"
3132
)
3233

@@ -75,7 +76,7 @@ func LogProducer(t *testing.T, c client.Client, opts ...LogProducerOption) {
7576
},
7677
},
7778
}
78-
require.NoError(t, c.Create(context.Background(), &logProducerDeployment))
79+
common.RequireNoError(t, c.Create(context.Background(), &logProducerDeployment))
7980
require.Eventually(t, cond.AnyPodShouldBeRunning(t, c, client.MatchingLabels(lbls)), 2*time.Minute, 5*time.Second)
8081
}
8182

e2e/syslog-ng-aggregator/syslog_ng_aggregator_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestSyslogNGIsRunningAndForwardingLogs(t *testing.T) {
117117
},
118118
},
119119
}
120-
require.NoError(t, c.GetClient().Create(ctx, &logging))
120+
common.RequireNoError(t, c.GetClient().Create(ctx, &logging))
121121
output := v1beta1.SyslogNGOutput{
122122
ObjectMeta: metav1.ObjectMeta{
123123
Name: "test-output",
@@ -134,7 +134,7 @@ func TestSyslogNGIsRunningAndForwardingLogs(t *testing.T) {
134134
},
135135
},
136136
}
137-
require.NoError(t, c.GetClient().Create(ctx, &output))
137+
common.RequireNoError(t, c.GetClient().Create(ctx, &output))
138138
flow := v1beta1.SyslogNGFlow{
139139
ObjectMeta: metav1.ObjectMeta{
140140
Name: "test-flow",
@@ -151,7 +151,7 @@ func TestSyslogNGIsRunningAndForwardingLogs(t *testing.T) {
151151
LocalOutputRefs: []string{output.Name},
152152
},
153153
}
154-
require.NoError(t, c.GetClient().Create(ctx, &flow))
154+
common.RequireNoError(t, c.GetClient().Create(ctx, &flow))
155155

156156
meta := logging.SyslogNGObjectMeta(syslogng.StatefulSetName, syslogng.ComponentSyslogNG)
157157
aggergatorPodName := meta.Name + "-0"
@@ -186,11 +186,11 @@ func TestSyslogNGIsRunningAndForwardingLogs(t *testing.T) {
186186
if o.Scheme == nil {
187187
o.Scheme = runtime.NewScheme()
188188
}
189-
require.NoError(t, v1beta1.AddToScheme(o.Scheme))
190-
require.NoError(t, apiextensionsv1.AddToScheme(o.Scheme))
191-
require.NoError(t, appsv1.AddToScheme(o.Scheme))
192-
require.NoError(t, batchv1.AddToScheme(o.Scheme))
193-
require.NoError(t, corev1.AddToScheme(o.Scheme))
194-
require.NoError(t, rbacv1.AddToScheme(o.Scheme))
189+
common.RequireNoError(t, v1beta1.AddToScheme(o.Scheme))
190+
common.RequireNoError(t, apiextensionsv1.AddToScheme(o.Scheme))
191+
common.RequireNoError(t, appsv1.AddToScheme(o.Scheme))
192+
common.RequireNoError(t, batchv1.AddToScheme(o.Scheme))
193+
common.RequireNoError(t, corev1.AddToScheme(o.Scheme))
194+
common.RequireNoError(t, rbacv1.AddToScheme(o.Scheme))
195195
})
196196
}

e2e/volumedrain/volumedrain_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestVolumeDrain_Downscale(t *testing.T) {
109109
},
110110
},
111111
}
112-
require.NoError(t, c.GetClient().Create(ctx, &logging))
112+
common.RequireNoError(t, c.GetClient().Create(ctx, &logging))
113113
tags := "time"
114114
output := v1beta1.Output{
115115
ObjectMeta: metav1.ObjectMeta{
@@ -128,7 +128,7 @@ func TestVolumeDrain_Downscale(t *testing.T) {
128128
},
129129
},
130130
}
131-
require.NoError(t, c.GetClient().Create(ctx, &output))
131+
common.RequireNoError(t, c.GetClient().Create(ctx, &output))
132132
flow := v1beta1.Flow{
133133
ObjectMeta: metav1.ObjectMeta{
134134
Name: "test-flow",
@@ -147,7 +147,7 @@ func TestVolumeDrain_Downscale(t *testing.T) {
147147
LocalOutputRefs: []string{output.Name},
148148
},
149149
}
150-
require.NoError(t, c.GetClient().Create(ctx, &flow))
150+
common.RequireNoError(t, c.GetClient().Create(ctx, &flow))
151151

152152
fluentdReplicaName := logging.Name + "-fluentd-1"
153153
require.Eventually(t, cond.PodShouldBeRunning(t, c.GetClient(), client.ObjectKey{Namespace: ns, Name: fluentdReplicaName}), 5*time.Minute, 5*time.Second)
@@ -169,7 +169,7 @@ func TestVolumeDrain_Downscale(t *testing.T) {
169169
}, 5*time.Minute, 2*time.Second)
170170

171171
cmd := common.CmdEnv(exec.Command("kubectl", "-n", consumer.PodKey.Namespace, "exec", consumer.PodKey.Name, "--", "curl", "-sS", "http://localhost:8082/off"), c)
172-
require.NoError(t, cmd.Run())
172+
common.RequireNoError(t, cmd.Run())
173173

174174
require.Eventually(t, func() bool {
175175
cmd := common.CmdEnv(exec.Command("kubectl", "-n", ns, "exec", fluentdReplicaName, "-c", "fluentd", "--", "ls", "-1", "/buffers"), c)
@@ -183,7 +183,7 @@ func TestVolumeDrain_Downscale(t *testing.T) {
183183

184184
patch := client.MergeFrom(logging.DeepCopy())
185185
logging.Spec.FluentdSpec.Scaling.Replicas = 1
186-
require.NoError(t, c.GetClient().Patch(ctx, &logging, patch))
186+
common.RequireNoError(t, c.GetClient().Patch(ctx, &logging, patch))
187187

188188
drainerJobName := fluentdReplicaName + "-drainer"
189189
require.Eventually(t, func() bool {
@@ -195,14 +195,14 @@ func TestVolumeDrain_Downscale(t *testing.T) {
195195
require.Eventually(t, cond.PodShouldBeRunning(t, c.GetClient(), client.ObjectKey{Namespace: ns, Name: fluentdReplicaName}), 30*time.Second, time.Second/2)
196196

197197
cmd = common.CmdEnv(exec.Command("kubectl", "-n", consumer.PodKey.Namespace, "exec", consumer.PodKey.Name, "--", "curl", "-sS", "http://localhost:8082/on"), c)
198-
require.NoError(t, cmd.Run())
198+
common.RequireNoError(t, cmd.Run())
199199

200200
require.Eventually(t, cond.ResourceShouldBeAbsent(t, c.GetClient(), common.Resource(new(batchv1.Job), ns, drainerJobName)), 5*time.Minute, 30*time.Second)
201201

202202
require.Eventually(t, cond.ResourceShouldBeAbsent(t, c.GetClient(), common.Resource(new(corev1.Pod), ns, fluentdReplicaName)), 30*time.Second, time.Second/2)
203203

204204
pvc := common.Resource(new(corev1.PersistentVolumeClaim), ns, logging.Name+"-fluentd-buffer-"+fluentdReplicaName)
205-
require.NoError(t, c.GetClient().Get(ctx, client.ObjectKeyFromObject(pvc), pvc))
205+
common.RequireNoError(t, c.GetClient().Get(ctx, client.ObjectKeyFromObject(pvc), pvc))
206206
assert.Equal(t, "drained", pvc.GetLabels()["logging.banzaicloud.io/drain-status"])
207207
}, func(t *testing.T, c common.Cluster) error {
208208
path := filepath.Join(TestTempDir, fmt.Sprintf("cluster-%s.log", t.Name()))
@@ -216,12 +216,12 @@ func TestVolumeDrain_Downscale(t *testing.T) {
216216
if o.Scheme == nil {
217217
o.Scheme = runtime.NewScheme()
218218
}
219-
require.NoError(t, v1beta1.AddToScheme(o.Scheme))
220-
require.NoError(t, apiextensionsv1.AddToScheme(o.Scheme))
221-
require.NoError(t, appsv1.AddToScheme(o.Scheme))
222-
require.NoError(t, batchv1.AddToScheme(o.Scheme))
223-
require.NoError(t, corev1.AddToScheme(o.Scheme))
224-
require.NoError(t, rbacv1.AddToScheme(o.Scheme))
219+
common.RequireNoError(t, v1beta1.AddToScheme(o.Scheme))
220+
common.RequireNoError(t, apiextensionsv1.AddToScheme(o.Scheme))
221+
common.RequireNoError(t, appsv1.AddToScheme(o.Scheme))
222+
common.RequireNoError(t, batchv1.AddToScheme(o.Scheme))
223+
common.RequireNoError(t, corev1.AddToScheme(o.Scheme))
224+
common.RequireNoError(t, rbacv1.AddToScheme(o.Scheme))
225225
})
226226
}
227227

@@ -274,7 +274,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
274274
},
275275
},
276276
}
277-
require.NoError(t, c.GetClient().Create(ctx, &logging))
277+
common.RequireNoError(t, c.GetClient().Create(ctx, &logging))
278278
tags := "time"
279279
output := v1beta1.Output{
280280
ObjectMeta: metav1.ObjectMeta{
@@ -293,7 +293,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
293293
},
294294
},
295295
}
296-
require.NoError(t, c.GetClient().Create(ctx, &output))
296+
common.RequireNoError(t, c.GetClient().Create(ctx, &output))
297297
flow := v1beta1.Flow{
298298
ObjectMeta: metav1.ObjectMeta{
299299
Name: "test-flow",
@@ -312,7 +312,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
312312
LocalOutputRefs: []string{output.Name},
313313
},
314314
}
315-
require.NoError(t, c.GetClient().Create(ctx, &flow))
315+
common.RequireNoError(t, c.GetClient().Create(ctx, &flow))
316316

317317
fluentdReplicaName := logging.Name + "-fluentd-1"
318318
require.Eventually(t, cond.PodShouldBeRunning(t, c.GetClient(), client.ObjectKey{Namespace: ns, Name: fluentdReplicaName}), 2*time.Minute, 5*time.Second)
@@ -334,7 +334,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
334334
}, 5*time.Minute, 2*time.Second)
335335

336336
cmd := common.CmdEnv(exec.Command("kubectl", "-n", consumer.PodKey.Namespace, "exec", consumer.PodKey.Name, "--", "curl", "-sS", "http://localhost:8082/off"), c)
337-
require.NoError(t, cmd.Run())
337+
common.RequireNoError(t, cmd.Run())
338338

339339
require.Eventually(t, func() bool {
340340
cmd := common.CmdEnv(exec.Command("kubectl", "-n", ns, "exec", fluentdReplicaName, "-c", "fluentd", "--", "ls", "-1", "/buffers"), c)
@@ -348,7 +348,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
348348

349349
patch := client.MergeFrom(logging.DeepCopy())
350350
logging.Spec.FluentdSpec.Scaling.Replicas = 1
351-
require.NoError(t, c.GetClient().Patch(ctx, &logging, patch))
351+
common.RequireNoError(t, c.GetClient().Patch(ctx, &logging, patch))
352352

353353
drainerJobName := fluentdReplicaName + "-drainer"
354354
require.Eventually(t, func() bool {
@@ -360,7 +360,7 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
360360
require.Eventually(t, cond.PodShouldBeRunning(t, c.GetClient(), client.ObjectKey{Namespace: ns, Name: fluentdReplicaName}), 30*time.Second, time.Second/2)
361361

362362
cmd = common.CmdEnv(exec.Command("kubectl", "-n", consumer.PodKey.Namespace, "exec", consumer.PodKey.Name, "--", "curl", "-sS", "http://localhost:8082/on"), c)
363-
require.NoError(t, cmd.Run())
363+
common.RequireNoError(t, cmd.Run())
364364

365365
require.Eventually(t, cond.ResourceShouldBeAbsent(t, c.GetClient(), common.Resource(new(batchv1.Job), ns, drainerJobName)), 5*time.Minute, 30*time.Second)
366366

@@ -379,11 +379,11 @@ func TestVolumeDrain_Downscale_DeleteVolume(t *testing.T) {
379379
if o.Scheme == nil {
380380
o.Scheme = runtime.NewScheme()
381381
}
382-
require.NoError(t, v1beta1.AddToScheme(o.Scheme))
383-
require.NoError(t, apiextensionsv1.AddToScheme(o.Scheme))
384-
require.NoError(t, appsv1.AddToScheme(o.Scheme))
385-
require.NoError(t, batchv1.AddToScheme(o.Scheme))
386-
require.NoError(t, corev1.AddToScheme(o.Scheme))
387-
require.NoError(t, rbacv1.AddToScheme(o.Scheme))
382+
common.RequireNoError(t, v1beta1.AddToScheme(o.Scheme))
383+
common.RequireNoError(t, apiextensionsv1.AddToScheme(o.Scheme))
384+
common.RequireNoError(t, appsv1.AddToScheme(o.Scheme))
385+
common.RequireNoError(t, batchv1.AddToScheme(o.Scheme))
386+
common.RequireNoError(t, corev1.AddToScheme(o.Scheme))
387+
common.RequireNoError(t, rbacv1.AddToScheme(o.Scheme))
388388
})
389389
}

0 commit comments

Comments
 (0)