kubewharf / kubeadmiral

Multi-Cluster Kubernetes Orchestration
https://kubeadmiral.io
Apache License 2.0
816 stars 97 forks source link

feat: add command-line tool admiralctl join&unjoin #302

Closed miraclejzd closed 10 months ago

miraclejzd commented 10 months ago

Summary

Currently, users need to manually create Secret and FederatedCluster resources through YAML files to add member clusters, and this file-based approach is not very convenient. Thanks to the work in #202, the command-line tool admiralctl has taken shape. In this proposal, I am building upon this work by introducing a new subcommand, admiralctl join, corresponding to #260. With this command, users can add member clusters via the command line.

Motivation

With the command-line tool, users can conveniently add member clusters without the need to manually create Secret and FederatedCluster resources.

Proposal

Command line tool framework selection

Similar to #202, utilizing cobra as the framework for the command-line tool.

admiralctl join subcommand

  1. Retrieve the kubeconfig file of the member cluster and extract information such as server endpoint, CA, cert, key, and bearer token.
  2. Validate the legitimacy of the member cluster:
    • Check if the control-plane nodes of the member cluster are Ready.
    • Verify if the member cluster has already joined Kubeadmiral (by checking the existence of the kube-admiral-system namespace and the annotation of it).
  3. Create Secret and FederatedCluster resources through the Clientset.

Command design

./admiralctl join --help
Join a member cluster to Kubeadmiral control plane.

 If the control plane of the member cluster is not ready or has already joined, this command will do nothing.

Examples:
  # Join cluster1 to Kubeadmiral by kubeconfig
  admiralctl join cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH>

  # Support to use '--api-endpoint' to overwrite the member cluster's api-endpoint
  admiralctl join cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --api-endpoint=<CLUSTER_API_ENDPOINT>

  # Support to use '--use-service-account' to determine whether create a new ServiceAccount when join
  admiralctl join cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --use-service-account=false

  # Support to use '--cluster-context' to specify the context of member cluster
  admiralctl join cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --cluster-context=<CLUSTER_CONTEXT>

Options:
    --api-endpoint='':
        api-endpoint of the member cluster.

    --cluster-context='':
        Context name of member cluster in kubeconfig.

    --cluster-kubeconfig='':
        Path of the member cluster kubeconfig.

    --use-service-account=true:
        Whether creates a new ServiceAccount when join, corresponding to FederatedCluster.spec.useServiceAccount.
        If you set 'false', BearerToken should be in the kubeconfig.

Usage:
  admiralctl join <FCLUSTER_NAME> --cluster-kubeconfig <CLUSTER_KUBECONFIG_PATH> [options]

admiralctl unjoin subcommand

  1. Validate the legitimacy of the member cluster:
    • Verify if the cluster has already joined Kubeadmiral
    • Check if the secret of the FederatedCluster is existed.
  2. Delete the FederatedCluster resource from Kubeadmiral.

Command design

./admiralctl unjoin --help
Unjoin a FederatedCluster from Kubeadmiral federation.

 If the the federated cluster has not joined the federation, this command will do nothing.

Examples:
  # Unjoin cluster1 from Kubeadmiral federation
  admiralctl unjoin cluster1

Usage:
  admiralctl unjoin <FCLUSTER_NAME> [options]
CLAassistant commented 10 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

:white_check_mark: miraclejzd
:x: Zhida Jiang


Zhida Jiang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.