Package subcommands of karmadactl to make it clearer
Signed-off-by: lonelyCZ <chengzhe@zju.edu.cn>
This commit is contained in:
parent
393fb9d598
commit
faa6b64cd6
|
|
@ -19,8 +19,9 @@ import (
|
|||
secretutil "sigs.k8s.io/cluster-api/util/secret"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/util/apiclient"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/fedinformer"
|
||||
|
|
@ -187,12 +188,12 @@ func (d *ClusterDetector) joinClusterAPICluster(clusterWideKey keys.ClusterWideK
|
|||
if err != nil {
|
||||
klog.Fatalf("Failed to get cluster-api management cluster rest config. kubeconfig: %s, err: %v", kubeconfigPath, err)
|
||||
}
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: options.DefaultKarmadaClusterNamespace,
|
||||
ClusterName: clusterWideKey.Name,
|
||||
}
|
||||
err = karmadactl.JoinCluster(d.ControllerPlaneConfig, clusterRestConfig, opts)
|
||||
err = opts.RunJoinCluster(d.ControllerPlaneConfig, clusterRestConfig)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to join cluster-api's cluster(%s): %v", clusterWideKey.Name, err)
|
||||
return err
|
||||
|
|
@ -204,13 +205,13 @@ func (d *ClusterDetector) joinClusterAPICluster(clusterWideKey keys.ClusterWideK
|
|||
|
||||
func (d *ClusterDetector) unJoinClusterAPICluster(clusterName string) error {
|
||||
klog.Infof("Begin to unJoin cluster-api's Cluster(%s) to karmada", clusterName)
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: options.DefaultKarmadaClusterNamespace,
|
||||
ClusterName: clusterName,
|
||||
Wait: options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.UnJoinCluster(d.ControllerPlaneConfig, nil, opts)
|
||||
err := opts.RunUnJoinCluster(d.ControllerPlaneConfig, nil)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to unJoin cluster-api's cluster(%s): %v", clusterName, err)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ func init() {
|
|||
install.Install()
|
||||
}
|
||||
|
||||
// NewCommandAddons enable or disable Karmada addons on karmada-host cluster
|
||||
func NewCommandAddons(parentCommand string) *cobra.Command {
|
||||
// NewCmdAddons enable or disable Karmada addons on karmada-host cluster
|
||||
func NewCmdAddons(parentCommand string) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "addons",
|
||||
Short: "Enable or disable a Karmada addon",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package apply
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package cordon
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -126,23 +126,58 @@ func (o *CommandCordonOption) Complete(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CordonHelper wraps functionality to cordon/uncordon cluster
|
||||
type CordonHelper struct {
|
||||
// RunCordonOrUncordon exec marks the cluster unschedulable or schedulable according to desired.
|
||||
// if true cordon cluster otherwise uncordon cluster.
|
||||
func RunCordonOrUncordon(desired int, f util.Factory, opts CommandCordonOption) error {
|
||||
cordonOrUncordon := "cordon"
|
||||
if desired == DesiredUnCordon {
|
||||
cordonOrUncordon = "un" + cordonOrUncordon
|
||||
}
|
||||
|
||||
karmadaClient, err := f.KarmadaClientSet()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cluster, err := karmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), opts.ClusterName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cordonHelper := newCordonHelper(cluster)
|
||||
if !cordonHelper.updateIfRequired(desired) {
|
||||
fmt.Printf("%s cluster %s\n", cluster.Name, alreadyStr(desired))
|
||||
return nil
|
||||
}
|
||||
|
||||
if !opts.DryRun {
|
||||
err := cordonHelper.patchOrReplace(karmadaClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%s cluster %sed\n", cluster.Name, cordonOrUncordon)
|
||||
return nil
|
||||
}
|
||||
|
||||
// cordonHelper wraps functionality to cordon/uncordon cluster
|
||||
type cordonHelper struct {
|
||||
cluster *clusterv1alpha1.Cluster
|
||||
desired int
|
||||
}
|
||||
|
||||
// NewCordonHelper returns a new CordonHelper that help execute
|
||||
// newCordonHelper returns a new CordonHelper that help execute
|
||||
// the cordon and uncordon commands
|
||||
func NewCordonHelper(cluster *clusterv1alpha1.Cluster) *CordonHelper {
|
||||
return &CordonHelper{
|
||||
func newCordonHelper(cluster *clusterv1alpha1.Cluster) *cordonHelper {
|
||||
return &cordonHelper{
|
||||
cluster: cluster,
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateIfRequired returns true if unscheduler taint isn't already set,
|
||||
// updateIfRequired returns true if unscheduler taint isn't already set,
|
||||
// or false when no change is needed
|
||||
func (c *CordonHelper) UpdateIfRequired(desired int) bool {
|
||||
func (c *cordonHelper) updateIfRequired(desired int) bool {
|
||||
c.desired = desired
|
||||
|
||||
if desired == DesiredCordon && !c.hasUnschedulerTaint() {
|
||||
|
|
@ -156,7 +191,7 @@ func (c *CordonHelper) UpdateIfRequired(desired int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (c *CordonHelper) hasUnschedulerTaint() bool {
|
||||
func (c *cordonHelper) hasUnschedulerTaint() bool {
|
||||
unschedulerTaint := corev1.Taint{
|
||||
Key: clusterv1alpha1.TaintClusterUnscheduler,
|
||||
Effect: corev1.TaintEffectNoSchedule,
|
||||
|
|
@ -171,10 +206,10 @@ func (c *CordonHelper) hasUnschedulerTaint() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// PatchOrReplace uses given karmada clientset to update the cluster unschedulable scheduler, either by patching or
|
||||
// patchOrReplace uses given karmada clientset to update the cluster unschedulable scheduler, either by patching or
|
||||
// updating the given cluster object; it may return error if the object cannot be encoded as
|
||||
// JSON, or if either patch or update calls fail; it will also return error whenever creating a patch has failed
|
||||
func (c *CordonHelper) PatchOrReplace(karmadaClient karmadaclientset.Interface) error {
|
||||
func (c *cordonHelper) patchOrReplace(karmadaClient karmadaclientset.Interface) error {
|
||||
client := karmadaClient.ClusterV1alpha1().Clusters()
|
||||
oldData, err := json.Marshal(c.cluster)
|
||||
if err != nil {
|
||||
|
|
@ -214,41 +249,6 @@ func (c *CordonHelper) PatchOrReplace(karmadaClient karmadaclientset.Interface)
|
|||
return err
|
||||
}
|
||||
|
||||
// RunCordonOrUncordon exec marks the cluster unschedulable or schedulable according to desired.
|
||||
// if true cordon cluster otherwise uncordon cluster.
|
||||
func RunCordonOrUncordon(desired int, f util.Factory, opts CommandCordonOption) error {
|
||||
cordonOrUncordon := "cordon"
|
||||
if desired == DesiredUnCordon {
|
||||
cordonOrUncordon = "un" + cordonOrUncordon
|
||||
}
|
||||
|
||||
karmadaClient, err := f.KarmadaClientSet()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cluster, err := karmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), opts.ClusterName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cordonHelper := NewCordonHelper(cluster)
|
||||
if !cordonHelper.UpdateIfRequired(desired) {
|
||||
fmt.Printf("%s cluster %s\n", cluster.Name, alreadyStr(desired))
|
||||
return nil
|
||||
}
|
||||
|
||||
if !opts.DryRun {
|
||||
err := cordonHelper.PatchOrReplace(karmadaClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%s cluster %sed\n", cluster.Name, cordonOrUncordon)
|
||||
return nil
|
||||
}
|
||||
|
||||
func alreadyStr(desired int) string {
|
||||
if desired == DesiredCordon {
|
||||
return "already cordoned"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package deinit
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package describe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -49,7 +49,7 @@ var (
|
|||
|
||||
// NewCmdDescribe new describe command.
|
||||
func NewCmdDescribe(f util.Factory, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := &DescribeOptions{
|
||||
o := &CommandDescribeOptions{
|
||||
KubectlDescribeOptions: &kubectldescribe.DescribeOptions{
|
||||
FilenameOptions: &resource.FilenameOptions{},
|
||||
DescriberSettings: &describe.DescriberSettings{
|
||||
|
|
@ -97,15 +97,15 @@ func NewCmdDescribe(f util.Factory, parentCommand string, streams genericcliopti
|
|||
return cmd
|
||||
}
|
||||
|
||||
// DescribeOptions contains the input to the describe command.
|
||||
type DescribeOptions struct {
|
||||
// CommandDescribeOptions contains the input to the describe command.
|
||||
type CommandDescribeOptions struct {
|
||||
// flags specific to describe
|
||||
KubectlDescribeOptions *kubectldescribe.DescribeOptions
|
||||
Cluster string
|
||||
}
|
||||
|
||||
// Complete ensures that options are valid and marshals them if necessary
|
||||
func (o *DescribeOptions) Complete(f util.Factory, cmd *cobra.Command, args []string) error {
|
||||
func (o *CommandDescribeOptions) Complete(f util.Factory, cmd *cobra.Command, args []string) error {
|
||||
if len(o.Cluster) == 0 {
|
||||
return fmt.Errorf("must specify a cluster")
|
||||
}
|
||||
|
|
@ -118,6 +118,6 @@ func (o *DescribeOptions) Complete(f util.Factory, cmd *cobra.Command, args []st
|
|||
}
|
||||
|
||||
// Run describe information of resources
|
||||
func (o *DescribeOptions) Run() error {
|
||||
func (o *CommandDescribeOptions) Run() error {
|
||||
return o.KubectlDescribeOptions.Run()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package exec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -42,7 +42,7 @@ var (
|
|||
|
||||
// NewCmdExec new exec command.
|
||||
func NewCmdExec(f util.Factory, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := &ExecOptions{
|
||||
o := &CommandExecOptions{
|
||||
KubectlExecOptions: &kubectlexec.ExecOptions{
|
||||
StreamOptions: kubectlexec.StreamOptions{
|
||||
IOStreams: streams,
|
||||
|
|
@ -90,15 +90,15 @@ func NewCmdExec(f util.Factory, parentCommand string, streams genericclioptions.
|
|||
return cmd
|
||||
}
|
||||
|
||||
// ExecOptions declare the arguments accepted by the Exec command
|
||||
type ExecOptions struct {
|
||||
// CommandExecOptions declare the arguments accepted by the Exec command
|
||||
type CommandExecOptions struct {
|
||||
// flags specific to exec
|
||||
KubectlExecOptions *kubectlexec.ExecOptions
|
||||
Cluster string
|
||||
}
|
||||
|
||||
// Complete verifies command line arguments and loads data from the command environment
|
||||
func (o *ExecOptions) Complete(f util.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
|
||||
func (o *CommandExecOptions) Complete(f util.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
|
||||
if len(o.Cluster) == 0 {
|
||||
return fmt.Errorf("must specify a cluster")
|
||||
}
|
||||
|
|
@ -110,11 +110,11 @@ func (o *ExecOptions) Complete(f util.Factory, cmd *cobra.Command, argsIn []stri
|
|||
}
|
||||
|
||||
// Validate checks that the provided exec options are specified.
|
||||
func (o *ExecOptions) Validate() error {
|
||||
func (o *CommandExecOptions) Validate() error {
|
||||
return o.KubectlExecOptions.Validate()
|
||||
}
|
||||
|
||||
// Run executes a validated remote execution against a pod.
|
||||
func (o *ExecOptions) Run() error {
|
||||
func (o *CommandExecOptions) Run() error {
|
||||
return o.KubectlExecOptions.Run()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package get
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -168,7 +168,7 @@ type CommandGetOptions struct {
|
|||
genericclioptions.IOStreams
|
||||
}
|
||||
|
||||
// NewCommandGetOptions returns a GetOptions with default chunk size 500.
|
||||
// NewCommandGetOptions returns a CommandGetOptions with default chunk size 500.
|
||||
func NewCommandGetOptions(streams genericclioptions.IOStreams) *CommandGetOptions {
|
||||
return &CommandGetOptions{
|
||||
PrintFlags: get.NewGetPrintFlags(),
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package join
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -47,7 +47,7 @@ func NewCmdJoin(f cmdutil.Factory, parentCommand string) *cobra.Command {
|
|||
if err := opts.Validate(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := RunJoin(f, opts); err != nil {
|
||||
if err := opts.Run(f); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -138,10 +138,10 @@ func (j *CommandJoinOption) AddFlags(flags *pflag.FlagSet) {
|
|||
flags.BoolVar(&j.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
}
|
||||
|
||||
// RunJoin is the implementation of the 'join' command.
|
||||
func RunJoin(f cmdutil.Factory, opts CommandJoinOption) error {
|
||||
klog.V(1).Infof("joining cluster. cluster name: %s", opts.ClusterName)
|
||||
klog.V(1).Infof("joining cluster. cluster namespace: %s", opts.ClusterNamespace)
|
||||
// Run is the implementation of the 'join' command.
|
||||
func (j *CommandJoinOption) Run(f cmdutil.Factory) error {
|
||||
klog.V(1).Infof("joining cluster. cluster name: %s", j.ClusterName)
|
||||
klog.V(1).Infof("joining cluster. cluster namespace: %s", j.ClusterNamespace)
|
||||
|
||||
// Get control plane karmada-apiserver client
|
||||
controlPlaneRestConfig, err := f.ToRawKubeConfigLoader().ClientConfig()
|
||||
|
|
@ -151,16 +151,16 @@ func RunJoin(f cmdutil.Factory, opts CommandJoinOption) error {
|
|||
}
|
||||
|
||||
// Get cluster config
|
||||
clusterConfig, err := apiclient.RestConfig(opts.ClusterContext, opts.ClusterKubeConfig)
|
||||
clusterConfig, err := apiclient.RestConfig(j.ClusterContext, j.ClusterKubeConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get joining cluster config. error: %v", err)
|
||||
}
|
||||
|
||||
return JoinCluster(controlPlaneRestConfig, clusterConfig, opts)
|
||||
return j.RunJoinCluster(controlPlaneRestConfig, clusterConfig)
|
||||
}
|
||||
|
||||
// JoinCluster join the cluster into karmada.
|
||||
func JoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts CommandJoinOption) (err error) {
|
||||
// RunJoinCluster join the cluster into karmada.
|
||||
func (j *CommandJoinOption) RunJoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config) (err error) {
|
||||
controlPlaneKubeClient := kubeclient.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
karmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
clusterKubeClient := kubeclient.NewForConfigOrDie(clusterConfig)
|
||||
|
|
@ -168,13 +168,13 @@ func JoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comman
|
|||
klog.V(1).Infof("joining cluster config. endpoint: %s", clusterConfig.Host)
|
||||
|
||||
registerOption := util.ClusterRegisterOption{
|
||||
ClusterNamespace: opts.ClusterNamespace,
|
||||
ClusterName: opts.ClusterName,
|
||||
ClusterNamespace: j.ClusterNamespace,
|
||||
ClusterName: j.ClusterName,
|
||||
ReportSecrets: []string{util.KubeCredentials, util.KubeImpersonator},
|
||||
ClusterProvider: opts.ClusterProvider,
|
||||
ClusterRegion: opts.ClusterRegion,
|
||||
ClusterZone: opts.ClusterZone,
|
||||
DryRun: opts.DryRun,
|
||||
ClusterProvider: j.ClusterProvider,
|
||||
ClusterRegion: j.ClusterRegion,
|
||||
ClusterZone: j.ClusterZone,
|
||||
DryRun: j.DryRun,
|
||||
ControlPlaneConfig: controlPlaneRestConfig,
|
||||
ClusterConfig: clusterConfig,
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ func JoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comman
|
|||
return err
|
||||
}
|
||||
|
||||
if opts.DryRun {
|
||||
if j.DryRun {
|
||||
return nil
|
||||
}
|
||||
registerOption.Secret = *clusterSecret
|
||||
|
|
@ -210,7 +210,7 @@ func JoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comman
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("cluster(%s) is joined successfully\n", opts.ClusterName)
|
||||
fmt.Printf("cluster(%s) is joined successfully\n", j.ClusterName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -13,8 +13,21 @@ import (
|
|||
"k8s.io/kubectl/pkg/util/templates"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/addons"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/apply"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/cordon"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/deinit"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/describe"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/exec"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/get"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/logs"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/promote"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/register"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/taint"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/token"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
|
||||
)
|
||||
|
|
@ -55,42 +68,42 @@ func NewKarmadaCtlCommand(cmdUse, parentCommand string) *cobra.Command {
|
|||
{
|
||||
Message: "Basic Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
NewCmdGet(f, parentCommand, ioStreams),
|
||||
get.NewCmdGet(f, parentCommand, ioStreams),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Cluster Registration Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
cmdinit.NewCmdInit(parentCommand),
|
||||
NewCmdDeInit(parentCommand),
|
||||
addons.NewCommandAddons(parentCommand),
|
||||
NewCmdJoin(f, parentCommand),
|
||||
NewCmdUnjoin(f, parentCommand),
|
||||
NewCmdToken(f, parentCommand, ioStreams),
|
||||
NewCmdRegister(parentCommand),
|
||||
deinit.NewCmdDeInit(parentCommand),
|
||||
addons.NewCmdAddons(parentCommand),
|
||||
join.NewCmdJoin(f, parentCommand),
|
||||
unjoin.NewCmdUnjoin(f, parentCommand),
|
||||
token.NewCmdToken(f, parentCommand, ioStreams),
|
||||
register.NewCmdRegister(parentCommand),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Cluster Management Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
NewCmdCordon(f, parentCommand),
|
||||
NewCmdUncordon(f, parentCommand),
|
||||
NewCmdTaint(f, parentCommand),
|
||||
cordon.NewCmdCordon(f, parentCommand),
|
||||
cordon.NewCmdUncordon(f, parentCommand),
|
||||
taint.NewCmdTaint(f, parentCommand),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Troubleshooting and Debugging Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
NewCmdLogs(f, parentCommand, ioStreams),
|
||||
NewCmdExec(f, parentCommand, ioStreams),
|
||||
NewCmdDescribe(f, parentCommand, ioStreams),
|
||||
logs.NewCmdLogs(f, parentCommand, ioStreams),
|
||||
exec.NewCmdExec(f, parentCommand, ioStreams),
|
||||
describe.NewCmdDescribe(f, parentCommand, ioStreams),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Advanced Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
NewCmdApply(f, parentCommand, ioStreams),
|
||||
NewCmdPromote(f, parentCommand),
|
||||
apply.NewCmdApply(f, parentCommand, ioStreams),
|
||||
promote.NewCmdPromote(f, parentCommand),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package logs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -52,7 +52,7 @@ var (
|
|||
|
||||
// NewCmdLogs new logs command.
|
||||
func NewCmdLogs(f util.Factory, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := &LogsOptions{
|
||||
o := &CommandLogsOptions{
|
||||
KubectlLogsOptions: kubectllogs.NewLogsOptions(streams, false),
|
||||
}
|
||||
|
||||
|
|
@ -89,15 +89,15 @@ func NewCmdLogs(f util.Factory, parentCommand string, streams genericclioptions.
|
|||
return cmd
|
||||
}
|
||||
|
||||
// LogsOptions contains the input to the logs command.
|
||||
type LogsOptions struct {
|
||||
// CommandLogsOptions contains the input to the logs command.
|
||||
type CommandLogsOptions struct {
|
||||
// flags specific to logs
|
||||
KubectlLogsOptions *kubectllogs.LogsOptions
|
||||
Cluster string
|
||||
}
|
||||
|
||||
// Complete ensures that options are valid and marshals them if necessary
|
||||
func (o *LogsOptions) Complete(cmd *cobra.Command, args []string, f util.Factory) error {
|
||||
func (o *CommandLogsOptions) Complete(cmd *cobra.Command, args []string, f util.Factory) error {
|
||||
if o.Cluster == "" {
|
||||
return fmt.Errorf("must specify a cluster")
|
||||
}
|
||||
|
|
@ -125,11 +125,11 @@ func (o *LogsOptions) Complete(cmd *cobra.Command, args []string, f util.Factory
|
|||
}
|
||||
|
||||
// Validate checks to the LogsOptions to see if there is sufficient information run the command
|
||||
func (o *LogsOptions) Validate() error {
|
||||
func (o *CommandLogsOptions) Validate() error {
|
||||
return o.KubectlLogsOptions.Validate()
|
||||
}
|
||||
|
||||
// Run retrieves a pod log
|
||||
func (o *LogsOptions) Run() error {
|
||||
func (o *CommandLogsOptions) Run() error {
|
||||
return o.KubectlLogsOptions.RunLogs()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package promote
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -23,6 +23,7 @@ import (
|
|||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/get"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/pkg/resourceinterpreter/defaultinterpreter/prune"
|
||||
|
|
@ -303,7 +304,7 @@ func (o *CommandPromoteOption) promote(controlPlaneRestConfig *rest.Config, obj
|
|||
}
|
||||
|
||||
// getObjInfo get obj info in member cluster
|
||||
func (o *CommandPromoteOption) getObjInfo(f cmdutil.Factory, cluster string, args []string) (*Obj, error) {
|
||||
func (o *CommandPromoteOption) getObjInfo(f cmdutil.Factory, cluster string, args []string) (*get.Obj, error) {
|
||||
r := f.NewBuilder().
|
||||
Unstructured().
|
||||
NamespaceParam(o.Namespace).
|
||||
|
|
@ -326,7 +327,7 @@ func (o *CommandPromoteOption) getObjInfo(f cmdutil.Factory, cluster string, arg
|
|||
return nil, fmt.Errorf("the %s or %s don't exist in cluster(%s)", args[0], args[1], o.Cluster)
|
||||
}
|
||||
|
||||
obj := &Obj{
|
||||
obj := &get.Obj{
|
||||
Cluster: cluster,
|
||||
Info: infos[0],
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package register
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package taint
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
@ -68,7 +67,7 @@ func NewCmdTaint(f util.Factory, parentCommand string) *cobra.Command {
|
|||
if err := opts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := RunTaint(f, opts); err != nil {
|
||||
if err := opts.Run(f); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -78,8 +77,11 @@ func NewCmdTaint(f util.Factory, parentCommand string) *cobra.Command {
|
|||
},
|
||||
}
|
||||
|
||||
flag := cmd.Flags()
|
||||
opts.AddFlags(flag)
|
||||
flags := cmd.Flags()
|
||||
options.AddKubeConfigFlags(flags)
|
||||
|
||||
flags.BoolVar(&opts.overwrite, "overwrite", opts.overwrite, "If true, allow taints to be overwritten, otherwise reject taint updates that overwrite existing taints.")
|
||||
flags.BoolVar(&opts.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
@ -155,15 +157,8 @@ func (o *CommandTaintOption) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddFlags adds flags to the specified FlagSet.
|
||||
func (o *CommandTaintOption) AddFlags(flags *pflag.FlagSet) {
|
||||
options.AddKubeConfigFlags(flags)
|
||||
flags.BoolVar(&o.overwrite, "overwrite", o.overwrite, "If true, allow taints to be overwritten, otherwise reject taint updates that overwrite existing taints.")
|
||||
flags.BoolVar(&o.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
}
|
||||
|
||||
// RunTaint set taints for the clusters
|
||||
func RunTaint(f util.Factory, opts CommandTaintOption) error {
|
||||
// Run set taints for the clusters
|
||||
func (o *CommandTaintOption) Run(f util.Factory) error {
|
||||
// Get control plane kube-apiserver client
|
||||
karmadaClient, err := f.KarmadaClientSet()
|
||||
if err != nil {
|
||||
|
|
@ -171,7 +166,7 @@ func RunTaint(f util.Factory, opts CommandTaintOption) error {
|
|||
}
|
||||
client := karmadaClient.ClusterV1alpha1().Clusters()
|
||||
|
||||
r := opts.builder.Do()
|
||||
r := o.builder.Do()
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -187,7 +182,7 @@ func RunTaint(f util.Factory, opts CommandTaintOption) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
operation, err := opts.updateTaints(obj)
|
||||
operation, err := o.updateTaints(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -196,7 +191,7 @@ func RunTaint(f util.Factory, opts CommandTaintOption) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !opts.DryRun {
|
||||
if !o.DryRun {
|
||||
patchBytes, patchErr := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
|
||||
|
||||
cluster, err := client.Get(context.TODO(), name, metav1.GetOptions{})
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package taint
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package token
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package karmadactl
|
||||
package unjoin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -55,7 +55,7 @@ func NewCmdUnjoin(f cmdutil.Factory, parentCommand string) *cobra.Command {
|
|||
if err := opts.Validate(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := RunUnjoin(f, opts); err != nil {
|
||||
if err := opts.Run(f); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -137,10 +137,10 @@ func (j *CommandUnjoinOption) AddFlags(flags *pflag.FlagSet) {
|
|||
flags.BoolVar(&j.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
}
|
||||
|
||||
// RunUnjoin is the implementation of the 'unjoin' command.
|
||||
func RunUnjoin(f cmdutil.Factory, opts CommandUnjoinOption) error {
|
||||
klog.V(1).Infof("unjoining cluster. cluster name: %s", opts.ClusterName)
|
||||
klog.V(1).Infof("unjoining cluster. cluster namespace: %s", opts.ClusterNamespace)
|
||||
// Run is the implementation of the 'unjoin' command.
|
||||
func (j *CommandUnjoinOption) Run(f cmdutil.Factory) error {
|
||||
klog.V(1).Infof("unjoining cluster. cluster name: %s", j.ClusterName)
|
||||
klog.V(1).Infof("unjoining cluster. cluster namespace: %s", j.ClusterNamespace)
|
||||
|
||||
// Get control plane kube-apiserver client
|
||||
controlPlaneRestConfig, err := f.ToRawKubeConfigLoader().ClientConfig()
|
||||
|
|
@ -151,26 +151,26 @@ func RunUnjoin(f cmdutil.Factory, opts CommandUnjoinOption) error {
|
|||
}
|
||||
|
||||
var clusterConfig *rest.Config
|
||||
if opts.ClusterKubeConfig != "" {
|
||||
if j.ClusterKubeConfig != "" {
|
||||
// Get cluster config
|
||||
clusterConfig, err = apiclient.RestConfig(opts.ClusterContext, opts.ClusterKubeConfig)
|
||||
clusterConfig, err = apiclient.RestConfig(j.ClusterContext, j.ClusterKubeConfig)
|
||||
if err != nil {
|
||||
klog.V(1).Infof("failed to get unjoining cluster config. error: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return UnJoinCluster(controlPlaneRestConfig, clusterConfig, opts)
|
||||
return j.RunUnJoinCluster(controlPlaneRestConfig, clusterConfig)
|
||||
}
|
||||
|
||||
// UnJoinCluster unJoin the cluster from karmada.
|
||||
func UnJoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts CommandUnjoinOption) (err error) {
|
||||
// RunUnJoinCluster unJoin the cluster from karmada.
|
||||
func (j *CommandUnjoinOption) RunUnJoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config) error {
|
||||
controlPlaneKarmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneRestConfig)
|
||||
|
||||
// delete the cluster object in host cluster that associates the unjoining cluster
|
||||
err = deleteClusterObject(controlPlaneKarmadaClient, opts)
|
||||
err := j.deleteClusterObject(controlPlaneKarmadaClient)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", opts.ClusterName, err)
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -182,23 +182,23 @@ func UnJoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comm
|
|||
klog.V(1).Infof("unjoining cluster config. endpoint: %s", clusterConfig.Host)
|
||||
|
||||
// delete RBAC resource from unjoining cluster
|
||||
err = deleteRBACResources(clusterKubeClient, opts.ClusterName, opts.forceDeletion, opts.DryRun)
|
||||
err = deleteRBACResources(clusterKubeClient, j.ClusterName, j.forceDeletion, j.DryRun)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete RBAC resource in unjoining cluster %q: %v", opts.ClusterName, err)
|
||||
klog.Errorf("Failed to delete RBAC resource in unjoining cluster %q: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// delete service account from unjoining cluster
|
||||
err = deleteServiceAccount(clusterKubeClient, opts.ClusterNamespace, opts.ClusterName, opts.forceDeletion, opts.DryRun)
|
||||
err = deleteServiceAccount(clusterKubeClient, j.ClusterNamespace, j.ClusterName, j.forceDeletion, j.DryRun)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete service account in unjoining cluster %q: %v", opts.ClusterName, err)
|
||||
klog.Errorf("Failed to delete service account in unjoining cluster %q: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// delete namespace from unjoining cluster
|
||||
err = deleteNamespaceFromUnjoinCluster(clusterKubeClient, opts.ClusterNamespace, opts.ClusterName, opts.forceDeletion, opts.DryRun)
|
||||
err = deleteNamespaceFromUnjoinCluster(clusterKubeClient, j.ClusterNamespace, j.ClusterName, j.forceDeletion, j.DryRun)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete namespace in unjoining cluster %q: %v", opts.ClusterName, err)
|
||||
klog.Errorf("Failed to delete namespace in unjoining cluster %q: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -206,6 +206,42 @@ func UnJoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comm
|
|||
return nil
|
||||
}
|
||||
|
||||
// deleteClusterObject delete the cluster object in host cluster that associates the unjoining cluster
|
||||
func (j *CommandUnjoinOption) deleteClusterObject(controlPlaneKarmadaClient *karmadaclientset.Clientset) error {
|
||||
if j.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := controlPlaneKarmadaClient.ClusterV1alpha1().Clusters().Delete(context.TODO(), j.ClusterName, metav1.DeleteOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return fmt.Errorf("no cluster object %s found in karmada control Plane", j.ClusterName)
|
||||
}
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// make sure the given cluster object has been deleted
|
||||
err = wait.Poll(1*time.Second, j.Wait, func() (done bool, err error) {
|
||||
_, err = controlPlaneKarmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), j.ClusterName, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return true, nil
|
||||
}
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get cluster %s. err: %v", j.ClusterName, err)
|
||||
return false, err
|
||||
}
|
||||
klog.Infof("Waiting for the cluster object %s to be deleted", j.ClusterName)
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", j.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteRBACResources deletes the cluster role, cluster rolebindings from the unjoining cluster.
|
||||
func deleteRBACResources(clusterKubeClient kubeclient.Interface, unjoiningClusterName string, forceDeletion, dryRun bool) error {
|
||||
if dryRun {
|
||||
|
|
@ -269,39 +305,3 @@ func deleteNamespaceFromUnjoinCluster(clusterKubeClient kubeclient.Interface, na
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteClusterObject delete the cluster object in host cluster that associates the unjoining cluster
|
||||
func deleteClusterObject(controlPlaneKarmadaClient *karmadaclientset.Clientset, opts CommandUnjoinOption) error {
|
||||
if opts.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := controlPlaneKarmadaClient.ClusterV1alpha1().Clusters().Delete(context.TODO(), opts.ClusterName, metav1.DeleteOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return fmt.Errorf("no cluster object %s found in karmada control Plane", opts.ClusterName)
|
||||
}
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", opts.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// make sure the given cluster object has been deleted
|
||||
err = wait.Poll(1*time.Second, opts.Wait, func() (done bool, err error) {
|
||||
_, err = controlPlaneKarmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), opts.ClusterName, metav1.GetOptions{})
|
||||
if apierrors.IsNotFound(err) {
|
||||
return true, nil
|
||||
}
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get cluster %s. err: %v", opts.ClusterName, err)
|
||||
return false, err
|
||||
}
|
||||
klog.Infof("Waiting for the cluster object %s to be deleted", opts.ClusterName)
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to delete cluster object. cluster name: %s, error: %v", opts.ClusterName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -16,8 +16,9 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||
"github.com/karmada-io/karmada/test/helper"
|
||||
|
|
@ -77,21 +78,21 @@ var _ = framework.SerialDescribe("Aggregated Kubernetes API Endpoint testing", f
|
|||
|
||||
ginkgo.BeforeEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: secretStoreNamespace,
|
||||
ClusterName: clusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.AfterEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Unjoinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: secretStoreNamespace,
|
||||
ClusterName: clusterName,
|
||||
|
|
@ -99,7 +100,7 @@ var _ = framework.SerialDescribe("Aggregated Kubernetes API Endpoint testing", f
|
|||
ClusterKubeConfig: kubeConfigPath,
|
||||
Wait: 5 * options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ import (
|
|||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||
|
|
@ -87,7 +88,7 @@ var _ = ginkgo.Describe("FederatedResourceQuota auto-provision testing", func()
|
|||
|
||||
ginkgo.AfterEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Unjoinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
|
|
@ -95,7 +96,7 @@ var _ = ginkgo.Describe("FederatedResourceQuota auto-provision testing", func()
|
|||
ClusterKubeConfig: kubeConfigPath,
|
||||
Wait: 5 * options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
@ -114,14 +115,14 @@ var _ = ginkgo.Describe("FederatedResourceQuota auto-provision testing", func()
|
|||
|
||||
ginkgo.It("federatedResourceQuota should be propagated to new joined clusters", func() {
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,11 @@ import (
|
|||
|
||||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/cordon"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/promote"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
khelper "github.com/karmada-io/karmada/pkg/util/helper"
|
||||
|
|
@ -48,7 +51,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
ginkgo.Context("Test promoting namespaced resource: deployment", func() {
|
||||
var deployment *appsv1.Deployment
|
||||
var deploymentNamespace, deploymentName string
|
||||
var deploymentOpts, namespaceOpts karmadactl.CommandPromoteOption
|
||||
var deploymentOpts, namespaceOpts promote.CommandPromoteOption
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
deploymentNamespace = fmt.Sprintf("karmadatest-%s", rand.String(RandomStrLength))
|
||||
|
|
@ -86,7 +89,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
|
||||
// Step 2, promote namespace used by the deployment from member1 to karmada
|
||||
ginkgo.By(fmt.Sprintf("Promoting namespace %s from member: %s to karmada control plane", deploymentNamespace, member1), func() {
|
||||
namespaceOpts = karmadactl.CommandPromoteOption{
|
||||
namespaceOpts = promote.CommandPromoteOption{
|
||||
Cluster: member1,
|
||||
}
|
||||
args := []string{"namespace", deploymentNamespace}
|
||||
|
|
@ -103,7 +106,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
|
||||
// Step 3, promote deployment from cluster member1 to karmada
|
||||
ginkgo.By(fmt.Sprintf("Promoting deployment %s from member: %s to karmada", deploymentName, member1), func() {
|
||||
deploymentOpts = karmadactl.CommandPromoteOption{
|
||||
deploymentOpts = promote.CommandPromoteOption{
|
||||
Namespace: deploymentNamespace,
|
||||
Cluster: member1,
|
||||
}
|
||||
|
|
@ -142,7 +145,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
var clusterRoleName, clusterRoleBindingName string
|
||||
var clusterRole *rbacv1.ClusterRole
|
||||
var clusterRoleBinding *rbacv1.ClusterRoleBinding
|
||||
var clusterRoleOpts, clusterRoleBindingOpts karmadactl.CommandPromoteOption
|
||||
var clusterRoleOpts, clusterRoleBindingOpts promote.CommandPromoteOption
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
var nameFlag = rand.String(RandomStrLength)
|
||||
|
|
@ -191,7 +194,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
|
||||
// Step2, promote clusterrole and clusterrolebinding from member1
|
||||
ginkgo.By(fmt.Sprintf("Promoting clusterrole %s and clusterrolebindings %s from member to karmada", clusterRoleName, clusterRoleBindingName), func() {
|
||||
clusterRoleOpts = karmadactl.CommandPromoteOption{
|
||||
clusterRoleOpts = promote.CommandPromoteOption{
|
||||
Cluster: member1,
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +207,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
err = clusterRoleOpts.Run(f, args)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
clusterRoleBindingOpts = karmadactl.CommandPromoteOption{
|
||||
clusterRoleBindingOpts = promote.CommandPromoteOption{
|
||||
Cluster: member1,
|
||||
}
|
||||
|
||||
|
|
@ -256,7 +259,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
})
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Promoting namespace %s from member: %s to karmada control plane", serviceNamespace, member1), func() {
|
||||
opts := karmadactl.CommandPromoteOption{
|
||||
opts := promote.CommandPromoteOption{
|
||||
Cluster: member1,
|
||||
}
|
||||
args := []string{"namespace", serviceNamespace}
|
||||
|
|
@ -270,7 +273,7 @@ var _ = ginkgo.Describe("Karmadactl promote testing", func() {
|
|||
})
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Promoting service %s from member: %s to karmada control plane", serviceName, member1), func() {
|
||||
opts := karmadactl.CommandPromoteOption{
|
||||
opts := promote.CommandPromoteOption{
|
||||
Namespace: serviceNamespace,
|
||||
Cluster: member1,
|
||||
}
|
||||
|
|
@ -357,14 +360,14 @@ var _ = framework.SerialDescribe("Karmadactl join/unjoin testing", ginkgo.Labels
|
|||
|
||||
ginkgo.BeforeEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
@ -423,7 +426,7 @@ var _ = framework.SerialDescribe("Karmadactl join/unjoin testing", ginkgo.Labels
|
|||
})
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Unjoinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
|
|
@ -431,7 +434,7 @@ var _ = framework.SerialDescribe("Karmadactl join/unjoin testing", ginkgo.Labels
|
|||
ClusterKubeConfig: kubeConfigPath,
|
||||
Wait: 5 * options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
@ -464,14 +467,14 @@ var _ = framework.SerialDescribe("Karmadactl cordon/uncordon testing", ginkgo.La
|
|||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
// When a newly joined cluster is unready at the beginning, the scheduler will ignore it.
|
||||
|
|
@ -482,7 +485,7 @@ var _ = framework.SerialDescribe("Karmadactl cordon/uncordon testing", ginkgo.La
|
|||
})
|
||||
ginkgo.DeferCleanup(func() {
|
||||
ginkgo.By(fmt.Sprintf("Unjoinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
|
|
@ -490,7 +493,7 @@ var _ = framework.SerialDescribe("Karmadactl cordon/uncordon testing", ginkgo.La
|
|||
ClusterKubeConfig: kubeConfigPath,
|
||||
Wait: 5 * options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
ginkgo.By(fmt.Sprintf("Deleting clusters: %s", clusterName), func() {
|
||||
|
|
@ -503,11 +506,10 @@ var _ = framework.SerialDescribe("Karmadactl cordon/uncordon testing", ginkgo.La
|
|||
|
||||
ginkgo.Context("cordon/uncordon cluster taint check", func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
opts := karmadactl.CommandCordonOption{
|
||||
DryRun: false,
|
||||
opts := cordon.CommandCordonOption{
|
||||
ClusterName: clusterName,
|
||||
}
|
||||
err := karmadactl.RunCordonOrUncordon(karmadactl.DesiredCordon, f, opts)
|
||||
err := cordon.RunCordonOrUncordon(cordon.DesiredCordon, f, opts)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
})
|
||||
|
|
@ -527,11 +529,10 @@ var _ = framework.SerialDescribe("Karmadactl cordon/uncordon testing", ginkgo.La
|
|||
})
|
||||
|
||||
ginkgo.It(fmt.Sprintf("cluster %s should not have unschedulable:NoSchedule taint", clusterName), func() {
|
||||
opts := karmadactl.CommandCordonOption{
|
||||
DryRun: false,
|
||||
opts := cordon.CommandCordonOption{
|
||||
ClusterName: clusterName,
|
||||
}
|
||||
err := karmadactl.RunCordonOrUncordon(karmadactl.DesiredUnCordon, f, opts)
|
||||
err := cordon.RunCordonOrUncordon(cordon.DesiredUnCordon, f, opts)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
ginkgo.By(fmt.Sprintf("cluster %s taint(unschedulable:NoSchedule) will be removed", clusterName), func() {
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/options"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||
|
|
@ -89,21 +90,21 @@ var _ = ginkgo.Describe("[namespace auto-provision] namespace auto-provision tes
|
|||
|
||||
ginkgo.BeforeEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.AfterEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Unjoinning cluster: %s", clusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: clusterName,
|
||||
|
|
@ -111,7 +112,7 @@ var _ = ginkgo.Describe("[namespace auto-provision] namespace auto-provision tes
|
|||
ClusterKubeConfig: kubeConfigPath,
|
||||
Wait: 5 * options.DefaultKarmadactlCommandDuration,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ import (
|
|||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/join"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/unjoin"
|
||||
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
|
||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||
testhelper "github.com/karmada-io/karmada/test/helper"
|
||||
|
|
@ -89,14 +90,14 @@ var _ = ginkgo.Describe("[cluster unjoined] reschedule testing", func() {
|
|||
|
||||
ginkgo.It("deployment reschedule testing", func() {
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", newClusterName), func() {
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: newClusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
// wait for the current cluster status changing to true
|
||||
|
|
@ -116,11 +117,11 @@ var _ = ginkgo.Describe("[cluster unjoined] reschedule testing", func() {
|
|||
|
||||
ginkgo.By("unjoin target cluster", func() {
|
||||
klog.Infof("Unjoining cluster %q.", newClusterName)
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: newClusterName,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
|
||||
|
|
@ -174,11 +175,11 @@ var _ = ginkgo.Describe("[cluster joined] reschedule testing", func() {
|
|||
|
||||
ginkgo.AfterEach(func() {
|
||||
ginkgo.By(fmt.Sprintf("Unjoin clsters: %s", newClusterName), func() {
|
||||
opts := karmadactl.CommandUnjoinOption{
|
||||
opts := unjoin.CommandUnjoinOption{
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: newClusterName,
|
||||
}
|
||||
err := karmadactl.RunUnjoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
ginkgo.By(fmt.Sprintf("Deleting clusters: %s", newClusterName), func() {
|
||||
|
|
@ -224,14 +225,14 @@ var _ = ginkgo.Describe("[cluster joined] reschedule testing", func() {
|
|||
})
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", newClusterName))
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: newClusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
// wait for the current cluster status changing to true
|
||||
|
|
@ -283,14 +284,14 @@ var _ = ginkgo.Describe("[cluster joined] reschedule testing", func() {
|
|||
}, pollTimeout, pollInterval).Should(gomega.BeTrue())
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Joinning cluster: %s", newClusterName))
|
||||
opts := karmadactl.CommandJoinOption{
|
||||
opts := join.CommandJoinOption{
|
||||
DryRun: false,
|
||||
ClusterNamespace: "karmada-cluster",
|
||||
ClusterName: newClusterName,
|
||||
ClusterContext: clusterContext,
|
||||
ClusterKubeConfig: kubeConfigPath,
|
||||
}
|
||||
err := karmadactl.RunJoin(f, opts)
|
||||
err := opts.Run(f)
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
|
||||
// wait for the current cluster status changing to true
|
||||
|
|
|
|||
Loading…
Reference in New Issue