Skip to content

Commit ebe949b

Browse files
authored
🌱 e2e tests: Log conditions of wl-cluster. (#1672)
1 parent 8d80956 commit ebe949b

File tree

5 files changed

+141
-38
lines changed

5 files changed

+141
-38
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/bramvdbogaerde/go-scp v1.5.0
88
github.com/go-logr/logr v1.4.2
99
github.com/go-logr/zapr v1.3.0
10-
github.com/guettli/check-conditions v0.0.9
10+
github.com/guettli/check-conditions v0.0.20
1111
github.com/hetznercloud/hcloud-go/v2 v2.19.1
1212
github.com/mitchellh/copystructure v1.2.0
1313
github.com/onsi/ginkgo/v2 v2.23.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
129129
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
130130
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
131131
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
132-
github.com/guettli/check-conditions v0.0.9 h1:RWIVVxIxWUNWe+KfIFBAEmI+iHGTRRMfZxCMFtV2Xq8=
133-
github.com/guettli/check-conditions v0.0.9/go.mod h1:6NifCTWJHcTBVv/0BvsF4ed3K/UOQsw7Pfp7kiRKNww=
132+
github.com/guettli/check-conditions v0.0.20 h1:veRmfngRayW5BZWNU5HkPgp4Y09sfHs3bLrqZvU3ulU=
133+
github.com/guettli/check-conditions v0.0.20/go.mod h1:6NifCTWJHcTBVv/0BvsF4ed3K/UOQsw7Pfp7kiRKNww=
134134
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
135135
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
136136
github.com/hetznercloud/hcloud-go/v2 v2.19.1 h1:UU/7h3uc/rdgspM8xkQF7wokmwZXePWDXcLqrQRRzzY=

test/e2e/e2e_suite_test.go

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import (
3030
. "github.com/onsi/ginkgo/v2"
3131
. "github.com/onsi/gomega"
3232
appsv1 "k8s.io/api/apps/v1"
33+
corev1 "k8s.io/api/core/v1"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"k8s.io/apimachinery/pkg/runtime"
3536
restclient "k8s.io/client-go/rest"
37+
"k8s.io/client-go/tools/clientcmd"
3638
"k8s.io/klog/v2"
3739
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3840
"sigs.k8s.io/cluster-api/test/framework"
@@ -254,6 +256,7 @@ func setupBootstrapCluster(config *clusterctl.E2EConfig, scheme *runtime.Scheme,
254256
return clusterProvider, clusterProxy
255257
}
256258

259+
// logStatusContinuously does log the state of the mgt-cluster and the wl-clusters continuously.
257260
func logStatusContinuously(ctx context.Context, restConfig *restclient.Config, c client.Client) {
258261
for {
259262
select {
@@ -269,33 +272,86 @@ func logStatusContinuously(ctx context.Context, restConfig *restclient.Config, c
269272
}
270273
}
271274

275+
// logStatus logs the current state of the mgt-cluster and the wl-clusters once.
276+
// It gets called again and again by logStatusContinuously.
272277
func logStatus(ctx context.Context, restConfig *restclient.Config, c client.Client) error {
273-
log("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ <<< Start logging status")
278+
log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
279+
log(fmt.Sprintf("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ %s <<< Start logging status", time.Now().Format("2006-01-02 15:04:05")))
274280

275281
if err := logCaphDeployment(ctx, c); err != nil {
276282
return err
277283
}
284+
278285
if err := logBareMetalHostStatus(ctx, c); err != nil {
279286
return err
280287
}
288+
281289
if err := logHCloudMachineStatus(ctx, c); err != nil {
282290
return err
283291
}
284-
if err := logConditions(ctx, restConfig); err != nil {
292+
293+
// Log the unhealthy conditions of the mgt-cluster
294+
if err := logConditions(ctx, "mgt-cluster", restConfig); err != nil {
285295
return err
286296
}
287-
log("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ End logging status >>>")
297+
298+
// log the unhealthy conditions of the wl-clusters.
299+
clusterList := &clusterv1.ClusterList{}
300+
err := c.List(ctx, clusterList)
301+
if err != nil {
302+
return fmt.Errorf("failed to list clusters: %w", err)
303+
}
304+
305+
for _, cluster := range clusterList.Items {
306+
// get the secret containing the kubeconfig.
307+
secretName := cluster.Name + "-kubeconfig"
308+
secret := &corev1.Secret{
309+
ObjectMeta: metav1.ObjectMeta{
310+
Name: secretName,
311+
Namespace: cluster.Namespace,
312+
},
313+
}
314+
315+
err := c.Get(ctx, client.ObjectKeyFromObject(secret), secret)
316+
if err != nil {
317+
log(fmt.Sprintf("Failed to get Secret %s/%s: %v", cluster.Namespace, secretName, err))
318+
continue
319+
}
320+
321+
data := secret.Data["value"]
322+
if len(data) == 0 {
323+
log(fmt.Sprintf("Failed to get Secret %s/%s: content is empty", cluster.Namespace, secretName))
324+
continue
325+
}
326+
327+
// create restConfig from kubeconfig.
328+
restConfig, err := clientcmd.RESTConfigFromKubeConfig(data)
329+
if err != nil {
330+
log(fmt.Sprintf("Failed to create REST config from Secret %s/%s: %v", cluster.Namespace, secretName, err))
331+
continue
332+
}
333+
334+
// log the conditions of this wl-cluster
335+
err = logConditions(ctx, "wl-cluster "+cluster.Name, restConfig)
336+
if err != nil {
337+
log(fmt.Sprintf("Failed to log Conditions %s/%s: %v", cluster.Namespace, secretName, err))
338+
continue
339+
}
340+
}
341+
342+
log(fmt.Sprintf("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ %s End logging status >>>", time.Now().Format("2006-01-02 15:04:05")))
288343

289344
return nil
290345
}
291346

292-
func logConditions(ctx context.Context, restConfig *restclient.Config) error {
347+
func logConditions(ctx context.Context, clusterName string, restConfig *restclient.Config) error {
293348
restConfig.QPS = -1 // Since Kubernetes 1.29 "API Priority and Fairness" handles that.
294-
counter, err := checkconditions.RunAndGetCounter(ctx, restConfig, checkconditions.Arguments{})
349+
counter, err := checkconditions.RunAndGetCounter(ctx, restConfig, &checkconditions.Arguments{})
295350
if err != nil {
296-
return fmt.Errorf("failed to get check conditions: %w", err)
351+
return fmt.Errorf("check conditions: %w", err)
297352
}
298-
log(fmt.Sprintf("--------------------------------------------------- Unhealthy Conditions: %d",
353+
log(fmt.Sprintf("----------------------------------------------- %s ---- Unhealthy Conditions: %d",
354+
clusterName,
299355
len(counter.Lines)))
300356

301357
for _, line := range counter.Lines {
@@ -417,13 +473,18 @@ func logBareMetalHostStatus(ctx context.Context, c client.Client) error {
417473
if hbmh.Spec.Status.ProvisioningState == "" {
418474
continue
419475
}
420-
log("BareMetalHost: " + hbmh.Name + " " + fmt.Sprint(hbmh.Spec.ServerID))
421-
log(" ProvisioningState: " + string(hbmh.Spec.Status.ProvisioningState))
476+
477+
// log infos about that hbmh.
478+
log("BareMetalHost: " + hbmh.Name + " " + fmt.Sprint(hbmh.Spec.ServerID) +
479+
" | IPv4: " + hbmh.Spec.Status.IPv4)
480+
481+
// Show an Error, if set.
422482
eMsg := string(hbmh.Spec.Status.ErrorType) + " " + hbmh.Spec.Status.ErrorMessage
423483
eMsg = strings.TrimSpace(eMsg)
424484
if eMsg != "" {
425485
log(" Error: " + eMsg)
426486
}
487+
427488
readyC := conditions.Get(hbmh, clusterv1.ReadyCondition)
428489
msg := ""
429490
reason := ""
@@ -433,7 +494,7 @@ func logBareMetalHostStatus(ctx context.Context, c client.Client) error {
433494
reason = readyC.Reason
434495
state = string(readyC.Status)
435496
}
436-
log(" Ready Condition: " + state + " " + reason + " " + msg)
497+
log(" ProvisioningState: " + string(hbmh.Spec.Status.ProvisioningState) + " | Ready Condition: " + state + " " + reason + " " + msg)
437498
}
438499
return nil
439500
}

vendor/github.com/guettli/check-conditions/pkg/checkconditions/checkconditions.go

Lines changed: 66 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ github.com/google/uuid
245245
github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule
246246
github.com/grpc-ecosystem/grpc-gateway/v2/runtime
247247
github.com/grpc-ecosystem/grpc-gateway/v2/utilities
248-
# github.com/guettli/check-conditions v0.0.9
248+
# github.com/guettli/check-conditions v0.0.20
249249
## explicit; go 1.20
250250
github.com/guettli/check-conditions/pkg/checkconditions
251251
# github.com/hashicorp/hcl v1.0.0

0 commit comments

Comments
 (0)