Fix: kubectl check err (#3779)

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
(cherry picked from commit 3bbcbe0e6f)

Co-authored-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
github-actions[bot]
2022-04-28 16:33:28 +08:00
committed by GitHub
parent 7c3a35ae87
commit 8f5eaefd89
5 changed files with 38 additions and 4 deletions

View File

@@ -18,8 +18,9 @@ package cmd
import (
"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/term"
cmdutil "github.com/oam-dev/kubevela/pkg/cmd/util"
)
// Builder build command with factory

View File

@@ -17,8 +17,9 @@ limitations under the License.
package cmd
import (
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/controller-runtime/pkg/client"
cmdutil "github.com/oam-dev/kubevela/pkg/cmd/util"
)
// Factory client factory for running command

32
pkg/cmd/util/helpers.go Normal file
View File

@@ -0,0 +1,32 @@
/*
Copyright 2022 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"github.com/pkg/errors"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)
// CheckErr wraps the kubectl CheckErr func by preventing inappropriate type conversion and panic
func CheckErr(err error) {
defer func() {
if r := recover(); r != nil {
cmdutil.CheckErr(errors.New(err.Error()))
}
}()
cmdutil.CheckErr(err)
}

View File

@@ -18,9 +18,9 @@ package cmd
import (
"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"github.com/oam-dev/kubevela/apis/types"
cmdutil "github.com/oam-dev/kubevela/pkg/cmd/util"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/pkg/utils/env"
)