Skip to content

Commit dbae74f

Browse files
authored
🌱 Fix flaky envTest and add Debug Output (#1551)
1 parent 52007d4 commit dbae74f

19 files changed

+228
-29
lines changed

.github/actions/e2e/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ runs:
8080
run: make ${{ inputs.e2e_make_target }}
8181
- name: Upload artifact
8282
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
83-
if: ${{ always() }}
83+
if: ${{ !cancelled() }}
8484
with:
8585
name: e2e-${{ inputs.e2e_name }}
8686
path: _artifacts

.github/actions/test-release/action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ runs:
2626
run: make test-release
2727
- name: Upload artifact
2828
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
29+
if: ${{ !cancelled() }}
2930
with:
3031
name: test-release
3132
path: out

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ jobs:
142142
# Upload artifact digests
143143
- name: Upload artifact digests
144144
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
145+
if: ${{ !cancelled() }}
145146
with:
146147
name: image-digest caph
147148
path: image-digest
@@ -177,4 +178,4 @@ jobs:
177178
shell: bash
178179
run: |
179180
cd image-digest/
180-
find -type f | sort | xargs -d '\n' cat
181+
find -type f | sort | xargs -d '\n' cat

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
# Upload artifact digests
109109
- name: Upload artifact digests
110110
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
111+
if: ${{ !cancelled() }}
111112
with:
112113
name: image-digest caph
113114
path: image-digest

.github/workflows/report-bin-size.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727

2828
- name: Upload Report
2929
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
30+
if: ${{ !cancelled() }}
3031
with:
3132
name: reports-${{ github.sha }}
3233
path: .reports
33-
retention-days: 90
34+
include-hidden-files: true
35+
retention-days: 90

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,20 @@ jobs:
5858
- name: Create Report
5959
run: make report-cover-html report-cover-treemap
6060

61+
- name: Report Slowest tests
62+
run: hack/tools/bin/gotestsum tool slowest --num 10 --jsonfile .reports/go-test-output.json > .reports/slowest-tests.txt
63+
if: ${{ !cancelled() }}
64+
6165
- name: Test Summary
6266
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
6367
with:
6468
paths: ".coverage/junit.xml"
6569

6670
- name: Upload Report
6771
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
72+
if: ${{ !cancelled() }}
6873
with:
6974
name: reports-${{ steps.name.outputs.name }}
7075
path: .reports
76+
include-hidden-files: true
7177
retention-days: 30

controllers/controllers_suite_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"fmt"
21+
"os"
2022
"sync"
2123
"testing"
2224
"time"
2325

2426
. "github.com/onsi/ginkgo/v2"
2527
. "github.com/onsi/gomega"
28+
"github.com/prometheus/common/expfmt"
2629
corev1 "k8s.io/api/core/v1"
2730
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2831
"k8s.io/apimachinery/pkg/types"
@@ -32,6 +35,7 @@ import (
3235
"sigs.k8s.io/cluster-api/util/conditions"
3336
ctrl "sigs.k8s.io/controller-runtime"
3437
"sigs.k8s.io/controller-runtime/pkg/controller"
38+
"sigs.k8s.io/controller-runtime/pkg/metrics"
3539

3640
infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
3741
hcloudclient "github.com/syself/cluster-api-provider-hetzner/pkg/services/hcloud/client"
@@ -132,7 +136,33 @@ var _ = BeforeSuite(func() {
132136
Expect(testEnv.Create(ctx, ns)).To(Succeed())
133137
})
134138

139+
func dumpMetrics() error {
140+
metricFamilies, err := metrics.Registry.Gather()
141+
if err != nil {
142+
return fmt.Errorf("failed to gather metrics: %w", err)
143+
}
144+
145+
if err := os.MkdirAll("../.reports", 0o750); err != nil {
146+
return fmt.Errorf("Error creating directory: %w", err)
147+
}
148+
f, err := os.Create("../.reports/controller_suite_test-metrics.txt")
149+
if err != nil {
150+
return fmt.Errorf("Error creating file: %w", err)
151+
}
152+
defer f.Close()
153+
154+
// Encode the metrics into text format
155+
encoder := expfmt.NewEncoder(f, expfmt.NewFormat(expfmt.TypeTextPlain))
156+
for _, mf := range metricFamilies {
157+
if err := encoder.Encode(mf); err != nil {
158+
return fmt.Errorf("error encoding metric family: %w", err)
159+
}
160+
}
161+
return nil
162+
}
163+
135164
var _ = AfterSuite(func() {
165+
Expect(dumpMetrics()).To(Succeed())
136166
Expect(testEnv.Stop()).To(Succeed())
137167
wg.Done() // Main manager has been stopped
138168
wg.Wait() // Wait for target cluster manager

controllers/hcloudmachine_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,15 @@ func (r *HCloudMachineReconciler) Reconcile(ctx context.Context, req reconcile.R
7474
hcloudMachine := &infrav1.HCloudMachine{}
7575
err := r.Get(ctx, req.NamespacedName, hcloudMachine)
7676
if err != nil {
77-
if apierrors.IsNotFound(err) {
78-
return reconcile.Result{}, nil
79-
}
80-
return reconcile.Result{}, err
77+
return reconcile.Result{}, client.IgnoreNotFound(err)
8178
}
8279

8380
log = log.WithValues("HCloudMachine", klog.KObj(hcloudMachine))
8481

8582
// Fetch the Machine.
8683
machine, err := util.GetOwnerMachine(ctx, r.Client, hcloudMachine.ObjectMeta)
8784
if err != nil {
88-
return reconcile.Result{}, err
85+
return reconcile.Result{}, fmt.Errorf("failed to get owner machine: %w", err)
8986
}
9087
if machine == nil {
9188
log.Info("Machine Controller has not yet set OwnerRef")

controllers/hcloudmachine_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ var _ = Describe("Hetzner secret", func() {
741741
Eventually(func() bool {
742742
return isPresentAndFalseWithReason(key, hcloudMachine, infrav1.HCloudTokenAvailableCondition, expectedReason)
743743
}, timeout, interval).Should(BeTrue())
744+
Expect(testEnv.Cleanup(ctx, hetznerSecret)).To(Succeed())
744745
},
745746
Entry("no Hetzner secret/wrong reference", func() *corev1.Secret {
746747
return &corev1.Secret{

controllers/hcloudmachinetemplate_controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (r *HCloudMachineTemplateReconciler) Reconcile(ctx context.Context, req rec
6060

6161
machineTemplate := &infrav1.HCloudMachineTemplate{}
6262
if err := r.Get(ctx, req.NamespacedName, machineTemplate); err != nil {
63-
log.Error(err, "unable to fetch HCloudMachineTemplate")
6463
return reconcile.Result{}, client.IgnoreNotFound(err)
6564
}
6665

@@ -110,7 +109,6 @@ func (r *HCloudMachineTemplateReconciler) Reconcile(ctx context.Context, req rec
110109
Name: cluster.Spec.InfrastructureRef.Name,
111110
}
112111
if err := r.Client.Get(ctx, hetznerClusterName, hetznerCluster); err != nil {
113-
log.Info("HetznerCluster is not available yet")
114112
return reconcile.Result{}, nil
115113
}
116114

0 commit comments

Comments
 (0)