mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-05 08:57:24 +00:00
Fix: apiserver & vela status use multi-cluster client
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
@@ -17,9 +17,9 @@ limitations under the License.
|
||||
package clients
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
|
||||
apiConfig "github.com/oam-dev/kubevela/pkg/apiserver/config"
|
||||
"github.com/oam-dev/kubevela/pkg/auth"
|
||||
"github.com/oam-dev/kubevela/pkg/multicluster"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
)
|
||||
@@ -75,19 +74,10 @@ func GetKubeClient() (client.Client, error) {
|
||||
return nil, fmt.Errorf("please call SetKubeConfig first")
|
||||
}
|
||||
var err error
|
||||
kubeClient, err = multicluster.Initialize(kubeConfig, false)
|
||||
if err == nil {
|
||||
return kubeClient, nil
|
||||
}
|
||||
if !errors.Is(err, multicluster.ErrDetectClusterGateway) {
|
||||
return nil, err
|
||||
}
|
||||
// create single cluster client
|
||||
kubeClient, err = client.New(kubeConfig, client.Options{Scheme: common.Scheme})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return kubeClient, nil
|
||||
kubeClient, err = pkgmulticluster.NewClient(kubeConfig, pkgmulticluster.ClientOptions{
|
||||
Options: client.Options{Scheme: common.Scheme},
|
||||
})
|
||||
return kubeClient, err
|
||||
}
|
||||
|
||||
// GetKubeConfig create/get kube runtime config
|
||||
|
||||
@@ -222,7 +222,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
|
||||
isUpdate := app.Status.Workflow.Message != "" && workflowInstance.Status.Message == ""
|
||||
workflowInstance.Status.Phase = workflowState
|
||||
app.Status.Workflow = workflow.ConvertWorkflowStatus(workflowInstance.Status, app.Status.Workflow.AppRevision)
|
||||
logCtx.Info("Workflow return state=%s", workflowState)
|
||||
logCtx.Info(fmt.Sprintf("Workflow return state=%s", workflowState))
|
||||
switch workflowState {
|
||||
case workflowv1alpha1.WorkflowStateSuspending:
|
||||
if duration := executor.GetSuspendBackoffWaitTime(); duration > 0 {
|
||||
|
||||
@@ -23,6 +23,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1"
|
||||
"github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1"
|
||||
clustercommon "github.com/oam-dev/cluster-gateway/pkg/common"
|
||||
errors2 "github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -32,12 +36,6 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/config"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1"
|
||||
"github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1"
|
||||
clustercommon "github.com/oam-dev/cluster-gateway/pkg/common"
|
||||
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
@@ -51,7 +49,7 @@ const (
|
||||
|
||||
var (
|
||||
// ClusterGatewaySecretNamespace the namespace where cluster-gateway secret locates
|
||||
ClusterGatewaySecretNamespace string
|
||||
ClusterGatewaySecretNamespace = "vela-system"
|
||||
)
|
||||
|
||||
// ClusterNameInContext extract cluster name from context
|
||||
@@ -174,16 +172,6 @@ func UpgradeExistingClusterSecret(ctx context.Context, c client.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMulticlusterKubernetesClient get client with multicluster function enabled
|
||||
func GetMulticlusterKubernetesClient() (client.Client, *rest.Config, error) {
|
||||
k8sConfig, err := config.GetConfig()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
k8sClient, err := Initialize(k8sConfig, false)
|
||||
return k8sClient, k8sConfig, err
|
||||
}
|
||||
|
||||
// ListExistingClusterSecrets list existing cluster secrets
|
||||
func ListExistingClusterSecrets(ctx context.Context, c client.Client) ([]v1.Secret, error) {
|
||||
secrets := &v1.SecretList{}
|
||||
|
||||
@@ -19,6 +19,7 @@ package common
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
"k8s.io/client-go/discovery"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -86,7 +87,9 @@ func (a *Args) GetClient() (client.Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
newClient, err := client.New(a.config, client.Options{Scheme: a.Schema})
|
||||
newClient, err := pkgmulticluster.NewClient(a.config,
|
||||
pkgmulticluster.ClientOptions{
|
||||
Options: client.Options{Scheme: a.Schema}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"k8s.io/utils/pointer"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1"
|
||||
"github.com/oam-dev/cluster-gateway/pkg/config"
|
||||
|
||||
@@ -66,11 +65,6 @@ func ClusterCommandGroup(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comm
|
||||
},
|
||||
// check if cluster-gateway is ready
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
config, err := c.GetConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config.Wrap(pkgmulticluster.NewTransportWrapper())
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get k8s client")
|
||||
|
||||
@@ -224,15 +224,6 @@ func formatEndpoints(endpoints []types2.ServiceEndpoint) [][]string {
|
||||
}
|
||||
|
||||
func printAppEndpoints(ctx context.Context, appName string, namespace string, f Filter, velaC common.Args, skipEmptyTable bool) error {
|
||||
config, err := velaC.GetConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := multicluster.Initialize(config, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
velaC.SetClient(client)
|
||||
endpoints, err := GetServiceEndpoints(ctx, appName, namespace, velaC, f)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
pkgmulticluster "github.com/kubevela/pkg/multicluster"
|
||||
"github.com/kubevela/workflow/pkg/cue/model/value"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/types"
|
||||
@@ -372,7 +371,6 @@ func QueryValue(ctx context.Context, velaC common.Args, queryView *velaql.QueryV
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Wrap(pkgmulticluster.NewTransportWrapper())
|
||||
client, err := velaC.GetClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user