Enable promote command to support AA
Signed-off-by: lonelyCZ <531187475@qq.com>
This commit is contained in:
parent
a35672271f
commit
aae6d087d0
|
@ -832,8 +832,6 @@ type ClusterInfo struct {
|
||||||
Context string
|
Context string
|
||||||
|
|
||||||
APIEndpoint string
|
APIEndpoint string
|
||||||
BearerToken string
|
|
||||||
CAData string
|
|
||||||
ClusterSyncMode clusterv1alpha1.ClusterSyncMode
|
ClusterSyncMode clusterv1alpha1.ClusterSyncMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,16 +863,10 @@ func getFactory(clusterName string, clusterInfos map[string]*ClusterInfo) cmduti
|
||||||
// Build member cluster kubeConfigFlags
|
// Build member cluster kubeConfigFlags
|
||||||
kubeConfigFlags.APIServer = stringptr(clusterInfos[clusterName].APIEndpoint)
|
kubeConfigFlags.APIServer = stringptr(clusterInfos[clusterName].APIEndpoint)
|
||||||
|
|
||||||
if clusterInfos[clusterName].KubeConfig != "" {
|
// Use kubeconfig to access member cluster
|
||||||
// Use kubeconfig to access member cluster
|
kubeConfigFlags.KubeConfig = stringptr(clusterInfos[clusterName].KubeConfig)
|
||||||
kubeConfigFlags.KubeConfig = stringptr(clusterInfos[clusterName].KubeConfig)
|
kubeConfigFlags.Context = stringptr(clusterInfos[clusterName].Context)
|
||||||
kubeConfigFlags.Context = stringptr(clusterInfos[clusterName].Context)
|
kubeConfigFlags.usePersistentConfig = true
|
||||||
kubeConfigFlags.usePersistentConfig = true
|
|
||||||
} else {
|
|
||||||
// Use BearerToken to access member cluster
|
|
||||||
kubeConfigFlags.BearerToken = stringptr(clusterInfos[clusterName].BearerToken)
|
|
||||||
kubeConfigFlags.CaBundle = stringptr(clusterInfos[clusterName].CAData)
|
|
||||||
}
|
|
||||||
|
|
||||||
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
|
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
|
||||||
return cmdutil.NewFactory(matchVersionKubeConfigFlags)
|
return cmdutil.NewFactory(matchVersionKubeConfigFlags)
|
||||||
|
|
|
@ -17,12 +17,10 @@ import (
|
||||||
"k8s.io/cli-runtime/pkg/printers"
|
"k8s.io/cli-runtime/pkg/printers"
|
||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/kubernetes"
|
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||||
|
|
||||||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
|
||||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||||
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
|
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
|
||||||
|
@ -82,10 +80,10 @@ func promoteExample(parentCommand string) string {
|
||||||
# Promote secret(default/default-token) from cluster1 to Karmada` + "\n" +
|
# Promote secret(default/default-token) from cluster1 to Karmada` + "\n" +
|
||||||
fmt.Sprintf("%s promote secret default-token -n default -c cluster1", parentCommand) + `
|
fmt.Sprintf("%s promote secret default-token -n default -c cluster1", parentCommand) + `
|
||||||
|
|
||||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' to specify the configuration` + "\n" +
|
# Support to use '--cluster-kubeconfig' to specify the configuration of member cluster` + "\n" +
|
||||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH>", parentCommand) + `
|
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH>", parentCommand) + `
|
||||||
|
|
||||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' and '--cluster-context' to specify the configuration` + "\n" +
|
# Support to use '--cluster-kubeconfig' and '--cluster-context' to specify the configuration of member cluster` + "\n" +
|
||||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --cluster-context=<CLUSTER_CONTEXT>", parentCommand)
|
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --cluster-context=<CLUSTER_CONTEXT>", parentCommand)
|
||||||
return example
|
return example
|
||||||
}
|
}
|
||||||
|
@ -209,10 +207,7 @@ func RunPromote(_ io.Writer, karmadaConfig KarmadaConfig, opts CommandPromoteOpt
|
||||||
|
|
||||||
f = cmdutil.NewFactory(kubeConfigFlags)
|
f = cmdutil.NewFactory(kubeConfigFlags)
|
||||||
} else {
|
} else {
|
||||||
if err := opts.getSecretTokenInKarmada(controlPlaneRestConfig, opts.Cluster, clusterInfos); err != nil {
|
opts.setClusterProxyInfo(controlPlaneRestConfig, opts.Cluster, clusterInfos)
|
||||||
return fmt.Errorf("failed to get Secret info in karmada control plane. err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
f = getFactory(opts.Cluster, clusterInfos)
|
f = getFactory(opts.Cluster, clusterInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,19 +337,19 @@ func (o *CommandPromoteOption) getObjInfo(f cmdutil.Factory, cluster string, arg
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSecretTokenInKarmada get token ca in karmada cluster
|
// setClusterProxyInfo set proxy information of cluster
|
||||||
func (o *CommandPromoteOption) getSecretTokenInKarmada(client *rest.Config, name string, clusterInfos map[string]*ClusterInfo) error {
|
func (o *CommandPromoteOption) setClusterProxyInfo(karmadaRestConfig *rest.Config, name string, clusterInfos map[string]*ClusterInfo) {
|
||||||
clusterClient, err := kubernetes.NewForConfig(client)
|
clusterInfos[name].APIEndpoint = karmadaRestConfig.Host + fmt.Sprintf(proxyURL, name)
|
||||||
if err != nil {
|
clusterInfos[name].KubeConfig = o.KubeConfig
|
||||||
return err
|
clusterInfos[name].Context = o.KarmadaContext
|
||||||
|
if clusterInfos[name].KubeConfig == "" {
|
||||||
|
env := os.Getenv("KUBECONFIG")
|
||||||
|
if env != "" {
|
||||||
|
clusterInfos[name].KubeConfig = env
|
||||||
|
} else {
|
||||||
|
clusterInfos[name].KubeConfig = defaultKubeConfig
|
||||||
|
}
|
||||||
}
|
}
|
||||||
secret, err := clusterClient.CoreV1().Secrets(o.ClusterNamespace).Get(context.TODO(), name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
clusterInfos[name].BearerToken = string(secret.Data[clusterv1alpha1.SecretTokenKey])
|
|
||||||
clusterInfos[name].CAData = string(secret.Data[clusterv1alpha1.SecretCADataKey])
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// printObjectAndPolicy print the converted resource
|
// printObjectAndPolicy print the converted resource
|
||||||
|
|
Loading…
Reference in New Issue