Skip to content

Commit 926a4c7

Browse files
authored
🌱 add check-conditions to e2e tests. (#1579)
1 parent a947b40 commit 926a4c7

File tree

8 files changed

+818
-197
lines changed

8 files changed

+818
-197
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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
1011
github.com/hetznercloud/hcloud-go/v2 v2.19.1
1112
github.com/onsi/ginkgo/v2 v2.23.0
1213
github.com/onsi/gomega v1.36.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +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=
132134
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
133135
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
134136
github.com/hetznercloud/hcloud-go/v2 v2.19.1 h1:UU/7h3uc/rdgspM8xkQF7wokmwZXePWDXcLqrQRRzzY=

test/e2e/basic_baremetal_test.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,94 +18,15 @@ package e2e
1818

1919
import (
2020
"context"
21-
"fmt"
22-
"strings"
23-
"time"
2421

2522
. "github.com/onsi/ginkgo/v2"
26-
appsv1 "k8s.io/api/apps/v1"
27-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29-
"sigs.k8s.io/cluster-api/util/conditions"
30-
"sigs.k8s.io/controller-runtime/pkg/client"
31-
"sigs.k8s.io/controller-runtime/pkg/log"
32-
33-
infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
3423
)
3524

36-
func logBareMetalHostStatusContinously(ctx context.Context, c client.Client) {
37-
for {
38-
t := time.After(30 * time.Second)
39-
select {
40-
case <-ctx.Done():
41-
return
42-
case <-t:
43-
err := logBareMetalHostStatus(ctx, c)
44-
if err != nil {
45-
log := log.FromContext(ctx)
46-
log.Info("Error logging BareMetalHost status", "error", err)
47-
}
48-
}
49-
}
50-
}
51-
52-
func logBareMetalHostStatus(ctx context.Context, c client.Client) error {
53-
hbmhList := &infrav1.HetznerBareMetalHostList{}
54-
err := c.List(ctx, hbmhList)
55-
if err != nil {
56-
return err
57-
}
58-
59-
if len(hbmhList.Items) == 0 {
60-
return nil
61-
}
62-
63-
caphDeployment := appsv1.Deployment{
64-
ObjectMeta: metav1.ObjectMeta{
65-
Name: "caph-controller-manager",
66-
Namespace: "caph-system",
67-
},
68-
}
69-
err = c.Get(ctx, client.ObjectKeyFromObject(&caphDeployment), &caphDeployment)
70-
if err != nil {
71-
return fmt.Errorf("failed to get caph-controller-manager deployment: %w", err)
72-
}
73-
74-
By(fmt.Sprintf("--------------------------------------------------- BareMetalHosts %s",
75-
caphDeployment.Spec.Template.Spec.Containers[0].Image))
76-
77-
for i := range hbmhList.Items {
78-
hbmh := &hbmhList.Items[i]
79-
if hbmh.Spec.Status.ProvisioningState == "" {
80-
continue
81-
}
82-
By("BareMetalHost: " + hbmh.Name + " " + fmt.Sprint(hbmh.Spec.ServerID))
83-
By(" ProvisioningState: " + string(hbmh.Spec.Status.ProvisioningState))
84-
eMsg := string(hbmh.Spec.Status.ErrorType) + " " + hbmh.Spec.Status.ErrorMessage
85-
eMsg = strings.TrimSpace(eMsg)
86-
if eMsg != "" {
87-
By(" Error: " + eMsg)
88-
}
89-
readyC := conditions.Get(hbmh, clusterv1.ReadyCondition)
90-
msg := ""
91-
reason := ""
92-
state := "?"
93-
if readyC != nil {
94-
msg = readyC.Message
95-
reason = readyC.Reason
96-
state = string(readyC.Status)
97-
}
98-
By(" Ready Condition: " + state + " " + reason + " " + msg)
99-
}
100-
return nil
101-
}
102-
10325
var _ = Describe("[Baremetal] Testing Cluster 1x control-planes 1x worker ", func() {
10426
ctx := context.TODO()
10527

10628
Context("Running the CaphClusterDeploymentSpec in Hetzner Baremetal", func() {
10729
CaphClusterDeploymentSpec(ctx, func() CaphClusterDeploymentSpecInput {
108-
go logBareMetalHostStatusContinously(ctx, bootstrapClusterProxy.GetClient())
10930
return CaphClusterDeploymentSpecInput{
11031
E2EConfig: e2eConfig,
11132
ClusterctlConfigPath: clusterctlConfigPath,

test/e2e/caph.go

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,14 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24-
"strings"
25-
"time"
2624

2725
"github.com/onsi/ginkgo/v2"
2826
"github.com/onsi/gomega"
29-
appsv1 "k8s.io/api/apps/v1"
3027
corev1 "k8s.io/api/core/v1"
31-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3228
"k8s.io/utils/ptr"
33-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3429
"sigs.k8s.io/cluster-api/test/framework"
3530
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
3631
"sigs.k8s.io/cluster-api/util"
37-
"sigs.k8s.io/cluster-api/util/conditions"
38-
"sigs.k8s.io/controller-runtime/pkg/client"
39-
"sigs.k8s.io/controller-runtime/pkg/log"
40-
41-
infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
4232
)
4333

4434
// CaphClusterDeploymentSpecInput is the input for CaphClusterDeploymentSpec.
@@ -53,87 +43,6 @@ type CaphClusterDeploymentSpecInput struct {
5343
ControlPlaneMachineCount int64
5444
}
5545

56-
func logHCloudMachineStatusContinously(ctx context.Context, c client.Client) {
57-
for {
58-
t := time.After(30 * time.Second)
59-
select {
60-
case <-ctx.Done():
61-
return
62-
case <-t:
63-
err := logHCloudMachineStatus(ctx, c)
64-
if err != nil {
65-
logger := log.FromContext(ctx)
66-
logger.Info("Error logging HCloudMachine status", "error", err)
67-
}
68-
}
69-
}
70-
}
71-
72-
func logHCloudMachineStatus(ctx context.Context, c client.Client) error {
73-
hmList := &infrav1.HCloudMachineList{}
74-
err := c.List(ctx, hmList)
75-
if err != nil {
76-
return err
77-
}
78-
79-
if len(hmList.Items) == 0 {
80-
return nil
81-
}
82-
83-
caphDeployment := appsv1.Deployment{
84-
ObjectMeta: metav1.ObjectMeta{
85-
Name: "caph-controller-manager",
86-
Namespace: "caph-system",
87-
},
88-
}
89-
err = c.Get(ctx, client.ObjectKeyFromObject(&caphDeployment), &caphDeployment)
90-
if err != nil {
91-
return fmt.Errorf("failed to get caph-controller-manager deployment: %w", err)
92-
}
93-
94-
ginkgo.By(fmt.Sprintf("--------------------------------------------------- HCloudMachines %s",
95-
caphDeployment.Spec.Template.Spec.Containers[0].Image))
96-
97-
for i := range hmList.Items {
98-
hm := &hmList.Items[i]
99-
if hm.Status.InstanceState == nil || *hm.Status.InstanceState == "" {
100-
continue
101-
}
102-
addresses := make([]string, 0)
103-
for _, a := range hm.Status.Addresses {
104-
addresses = append(addresses, a.Address)
105-
}
106-
107-
id := ""
108-
if *hm.Spec.ProviderID != "" {
109-
id = *hm.Spec.ProviderID
110-
}
111-
ginkgo.By("HCloudMachine: " + hm.Name + " " + id + " " + strings.Join(addresses, " "))
112-
ginkgo.By(" ProvisioningState: " + string(*hm.Status.InstanceState))
113-
l := make([]string, 0)
114-
if hm.Status.FailureMessage != nil {
115-
l = append(l, *hm.Status.FailureMessage)
116-
}
117-
if hm.Status.FailureMessage != nil {
118-
l = append(l, *hm.Status.FailureMessage)
119-
}
120-
if len(l) > 0 {
121-
ginkgo.By(" Error: " + strings.Join(l, ", "))
122-
}
123-
readyC := conditions.Get(hm, clusterv1.ReadyCondition)
124-
msg := ""
125-
reason := ""
126-
state := "?"
127-
if readyC != nil {
128-
msg = readyC.Message
129-
reason = readyC.Reason
130-
state = string(readyC.Status)
131-
}
132-
ginkgo.By(" Ready Condition: " + state + " " + reason + " " + msg)
133-
}
134-
return nil
135-
}
136-
13746
// CaphClusterDeploymentSpec implements a test that verifies that MachineDeployment rolling updates are successful.
13847
func CaphClusterDeploymentSpec(ctx context.Context, inputGetter func() CaphClusterDeploymentSpecInput) {
13948
var (
@@ -164,7 +73,6 @@ func CaphClusterDeploymentSpec(ctx context.Context, inputGetter func() CaphClust
16473

16574
ginkgo.It("Should successfully create a cluster with three control planes", func() {
16675
ginkgo.By("Creating a workload cluster")
167-
go logHCloudMachineStatusContinously(ctx, input.BootstrapClusterProxy.GetClient())
16876
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
16977
ClusterProxy: input.BootstrapClusterProxy,
17078
ConfigCluster: clusterctl.ConfigClusterInput{

0 commit comments

Comments
 (0)