Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

miraclejzd
Copy link

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants