mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Fix: fix unhandled err (#2423)
* Fix: fix unhandled err refer to https://lift.sonatype.com/result/bhamail/kubevela/01FFT7CSVNCPF6808ZM856V3HN?tab=results * Test: fix panic err
This commit is contained in:
+5
-2
@@ -326,8 +326,11 @@ func waitWebhookSecretVolume(certDir string, timeout, interval time.Duration) er
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
// nolint
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
klog.Error(err, "Failed to close file")
|
||||
}
|
||||
}()
|
||||
// check if dir is empty
|
||||
if _, err := f.Readdir(1); errors.Is(err, io.EOF) {
|
||||
return false
|
||||
|
||||
+7
-1
@@ -100,8 +100,14 @@ func InteractiveExec(cli string, consoleFn func(*expect.Console)) (string, error
|
||||
command.Stdin = console.Tty()
|
||||
|
||||
session, err := gexec.Start(command, console.Tty(), console.Tty())
|
||||
if err != nil {
|
||||
return string(output), err
|
||||
}
|
||||
s := session.Wait(300 * time.Second)
|
||||
console.Tty().Close()
|
||||
err = console.Tty().Close()
|
||||
if err != nil {
|
||||
return string(output), err
|
||||
}
|
||||
<-doneC
|
||||
if err != nil {
|
||||
return string(output), err
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"sigs.k8s.io/kind/pkg/cluster"
|
||||
"sigs.k8s.io/kind/pkg/cluster/nodes"
|
||||
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
|
||||
@@ -137,7 +138,11 @@ func loadImage(imageTarName string, node nodes.Node) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open image")
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
klog.Error(err, "Failed to close file")
|
||||
}
|
||||
}()
|
||||
return nodeutils.LoadImageArchive(node, f)
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ func (r *Reconciler) handleFinalizers(ctx context.Context, envBinding *v1alpha1.
|
||||
func (r *Reconciler) endWithNegativeCondition(ctx context.Context, envBinding *v1alpha1.EnvBinding, cond condition.Condition) (ctrl.Result, error) {
|
||||
envBinding.SetConditions(cond)
|
||||
if err := r.Client.Status().Patch(ctx, envBinding, client.Merge); err != nil {
|
||||
return ctrl.Result{}, errors.WithMessage(err, "cannot update initializer status")
|
||||
return ctrl.Result{}, errors.WithMessage(err, "cannot update envbinding status")
|
||||
}
|
||||
// if any condition is changed, patching status can trigger requeue the resource and we should return nil to
|
||||
// avoid requeue it again
|
||||
|
||||
@@ -663,7 +663,6 @@ var _ = Describe("EnvBinding Normal tests", func() {
|
||||
By("Create envBinding")
|
||||
Expect(k8sClient.Create(ctx, envBinding)).Should(BeNil())
|
||||
|
||||
testutil.ReconcileOnce(&r, req)
|
||||
testutil.ReconcileRetry(&r, req)
|
||||
|
||||
By("Check the Application created by EnvBinding Controller")
|
||||
|
||||
@@ -18,6 +18,7 @@ package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/gomega"
|
||||
@@ -46,16 +47,20 @@ func ReconcileRetryAndExpectErr(r reconcile.Reconciler, req reconcile.Request) {
|
||||
|
||||
// ReconcileOnce will just reconcile once
|
||||
func ReconcileOnce(r reconcile.Reconciler, req reconcile.Request) {
|
||||
//nolint:errcheck
|
||||
r.Reconcile(context.TODO(), req)
|
||||
if _, err := r.Reconcile(context.TODO(), req); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// ReconcileOnceAfterFinalizer will reconcile for finalizer
|
||||
//nolint:errcheck
|
||||
func ReconcileOnceAfterFinalizer(r reconcile.Reconciler, req reconcile.Request) (reconcile.Result, error) {
|
||||
// 1st and 2nd time reconcile to add finalizer
|
||||
r.Reconcile(context.TODO(), req)
|
||||
r.Reconcile(context.TODO(), req)
|
||||
if result, err := r.Reconcile(context.TODO(), req); err != nil {
|
||||
return result, err
|
||||
}
|
||||
if result, err := r.Reconcile(context.TODO(), req); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return r.Reconcile(context.TODO(), req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user