Skip to content

Commit

Permalink
Add antctl join command
Browse files Browse the repository at this point in the history
Signed-off-by: hujiajing <hjiajing@vmware.com>
  • Loading branch information
hjiajing committed Aug 10, 2022
1 parent 3225809 commit 8efa04a
Show file tree
Hide file tree
Showing 19 changed files with 1,239 additions and 941 deletions.
99 changes: 69 additions & 30 deletions docs/multicluster/antctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,96 @@ To see the usage examples of these commands, you may also run `antctl mc get [su

## antctl mc create

`antctl mc create` command can create access-token and other resources like ClusterSet, ClusterClaims for
Antrea Multi-cluster setup

+ `antctl mc create accesstoken` command can create accesstoken for member clusters.
+ `antctl mc create clusterclaims` command can create two ClusterClaims in a leader or member cluster. One for the leader or member cluster, and another for the ClusterSet.
+ `antctl mc create clusterset` command can create a ClusterSet in a leader or member cluster.
`antctl mc create` command can create tokens for member clusters to join a ClusterSet. The command will
also create a Secret to store the token, as well as a ServiceAccount and a RoleBinding. The `--output-file`
option saves the member token Secret manifest to a file.

```bash
anctcl mc create accesstoken [NAME] [-n NAMESPACE] [--serviceaccount SERVICE_ACCOUNT] [--role-binding ROLE_BINDING]
antctl mc create clusterclaims [-n NAMESPACE] [--clusterset-id CLUSTERSET_ID] [--cluster-id CLUSTER_ID]
antctl mc create clusterset [NAME] [-n NAMESPACE] [--leader-server LEADER_SERVER] [--service-account SERVICE_ACCOUNT] [--secret SECRET] [--leader-cluster LEADER_CLUSTER_ID]
anctcl mc create membertoken NAME -n NAMESPACE [--output-file OUTPUT_FILE]
```

To see the usage examples of these commands, you may also run `antctl mc create [subcommand] --help`.

## antctl mc add
## antctl mc deploy

`antctl mc deploy` command deploys Antrea Multi-cluster Controller to a leader or member cluster.

`antctl mc add` command can add a new member cluster to a ClusterSet.
+ `antctl mc deploy leadercluster` command deploys Antrea Multi-cluster Controller to a leader cluster and imports
all the Antrea Multi-cluster CRDs.
+ `antctl mc deploy membercluster` command deploys Antrea Multi-cluster Controller to a member cluster and imports
all the Antrea Multi-cluster CRDs.

```bash
antctl mc add membercluster [CLUSTER_ID] [-n NAMESPACE] [--clusterset CLUSTERSET] [--service-account SERVICE_ACCOUNT]
antctl mc deploy leadercluster -n NAMESPACE [--antrea-version ANTREA_VERSION] [-f PATH_TO_MANIFEST]
antctl mc deploy membercluster -n NAMESPACE [--antrea-version ANTREA_VERSION] [-f PATH_TO_MANIFEST]
```

To see the usage examples of these commands, you may also run `antctl mc add [subcommand] --help`.

## antctl mc delete
To see the usage examples of these commands, you may also run `antctl mc deploy [subcommand] --help`.

`antctl mc delete` command can delete resources in an Antrea Multi-cluster ClusterSet.
## antctl mc init

+ `antctl mc delete clusterclaims` command can delete the two ClusterClaims in a specified Namespace. One for the leader or member cluster, and another for the ClusterSet.
+ `antctl mc delete clusterset` command can delete a ClusterSet in a leader or member cluster.
+ `antctl mc delete member-cluster` command can delete a member cluster in a specified Antrea Multi-cluster ClusterSet.
`antctl mc init` command initializes an Antrea Multi-cluster ClusterSet in a leader cluster. It will create a
ClusterSet and ClusterClaims for the leader cluster. If the `--output-file` option is specified, the config arguments
for member clusters to join the ClusterSet will be saved to the specified file.

```bash
antctl mc delete clusterclaims [-n NAMESPACE]
antctl mc delete clusterset [NAME] [-n NAMESPACE]
antctl mc delete membercluster [MEMBER_CLUSTER_ID] [-n NAMESPACE] [--clusterset CLUSTERSET]
antctl mc init -n NAMESPACE --clusterset CLUSTERSET_ID --clusterid CLUSTERID [--create-token] [--output-file OUTPUT_FILE]
```

To see the usage examples of these commands, you may also run `antctl mc delete [subcommand] --help`.
To see the usage examples of this command, you may also run `antctl mc init --help`.

## antctl mc deploy
## antctl mc join

`antctl mc deploy` command can deploy Antrea Multi-cluster Controller to a leader or member cluster.
`antctl mc join` command lets a member cluster join an existing Antrea Multi-cluster ClusterSet. It will create a
ClusterSet and ClusterClaims for the member cluster. Users can use command line options or a config file (which can
be the output file of the `anctl mc init` command) to specify the ClusterSet join arguments.

+ `antctl mc deploy leadercluster` command can deploy Antrea Multi-cluster Controller to a leader cluster, and define all the CRDs the leader cluster needed.
+ `antctl mc deploy membercluster` command can deploy Antrea Multi-cluster Controller to a member cluster, and define all the CRDs the member cluster needed.
When the config file is provided, the command line options may be overwritten by the file. A token is needed for a
member cluster to access the leader cluster API server. Users can either specify a pre-created token Secret with the
`--token-secret-name` option, or pass a Secret manifest to create the Secret with either the `--token-secret-file`
option or the config file.

```bash
antctl mc deploy leadercluster [--antrea-version ANTREA_VERSION] [-n NAMESPACE] [-f PATH_TO_MANIFEST]
antctl mc deploy membercluster [--antrea-version ANTREA_VERSION] [-n NAMESPACE] [-f PATH_TO_MANIFEST]
antctl mc join --clusterset=CLUSTERSET_ID \
--clusterid=CLUSTER_ID \
--namespace=MEMBER_NAMESPACE \
--leader-clusterid=LEADER_CLUSTER_ID \
--leader-namespace=LEADER_NAMESPACE \
--leader-apiserver=LEADER_APISERVER \
--token-secret-name=TOKEN_SECRET_NAME \
--token-secret-file=TOKEN_SECRET_FILE

antctl mc join --config-file PATH_TO_CONFIG_FILE
```

To see the usage examples of these commands, you may also run `antctl mc deploy [subcommand] --help`.
Below is a config file example:

```yaml
apiVersion: multicluster.antrea.io/v1alpha1
kind: ClusterSetJoinConfig
clusterSetID: clusterset1
clusterID: cluster-east
namespace: kube-system
leaderClusterID: cluster-north
leaderNamespace: antrea-multicluster
leaderAPIServer: https://172.18.0.3:6443
tokenSecretName: cluster-east-token
```
## antctl mc leave
`antctl mc leave` command lets a member cluster leave a ClusterSet. It will delete the ClusterSet and ClusterClaims
and other resources created by antctl for the member cluster.

```bash
antctl mc leave --clusterset CLUSTERSET_ID --namespace [NAMESPACE]
```

## antctl mc destroy

`antctl mc destroy` command can destroy an Antrea Multi-cluster ClusterSet in a leader cluster. It will delete the
ClusterSet and ClusterClaims and other resources created by antctl for the leader cluster.

```bash
antctl mc destroy --clusterset=CLUSTERSET_ID --namespace [NAMESPACE]
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
google.golang.org/protobuf v1.27.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.24.0
k8s.io/apiextensions-apiserver v0.24.0
k8s.io/apimachinery v0.24.0
Expand All @@ -75,6 +76,7 @@ require (
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
sigs.k8s.io/controller-runtime v0.12.1
sigs.k8s.io/mcs-api v0.1.0
sigs.k8s.io/yaml v1.3.0
)

require (
Expand Down Expand Up @@ -183,11 +185,9 @@ require (
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

// Newer version of github.com/googleapis/gnostic make use of newer gopkg.in/yaml(v3), which conflicts with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func NewRemoteCommonArea(clusterID common.ClusterID, clusterSetID common.Cluster
scheme *runtime.Scheme, localClusterClient client.Client, clusterSetNamespace string, localNamespace string) (RemoteCommonArea, error) {
klog.InfoS("Create a RemoteCommonArea", "cluster", clusterID)

crtData, token, err := getSecretCACrtAndToken(secret)
crtData, token, err := GetSecretCACrtAndToken(secret)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -189,9 +189,9 @@ func NewRemoteCommonArea(clusterID common.ClusterID, clusterSetID common.Cluster
}

/**
* getSecretCACrtAndToken returns the access credentials from Secret.
* GetSecretCACrtAndToken returns the access credentials from Secret.
*/
func getSecretCACrtAndToken(secretObj *v1.Secret) ([]byte, []byte, error) {
func GetSecretCACrtAndToken(secretObj *v1.Secret) ([]byte, []byte, error) {
caData, found := secretObj.Data[v1.ServiceAccountRootCAKey]
if !found {
return nil, nil, fmt.Errorf("ca.crt data not found in Secret %v", secretObj.GetName())
Expand Down
20 changes: 16 additions & 4 deletions pkg/antctl/antctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,25 +598,37 @@ $ antctl get podmulticaststats pod -n namespace`,
commandGroup: mc,
},
{
cobraCommand: multicluster.AddCmd,
cobraCommand: multicluster.CreateCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
},
{
cobraCommand: multicluster.CreateCmd,
cobraCommand: multicluster.DeployCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
},
{
cobraCommand: multicluster.DeleteCmd,
cobraCommand: multicluster.JoinCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
},
{
cobraCommand: multicluster.DeployCmd,
cobraCommand: multicluster.LeaveCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
},
{
cobraCommand: multicluster.InitCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
},
{
cobraCommand: multicluster.DestroyCmd,
supportAgent: false,
supportController: false,
commandGroup: mc,
Expand Down
115 changes: 0 additions & 115 deletions pkg/antctl/raw/multicluster/add/member_cluster.go

This file was deleted.

23 changes: 5 additions & 18 deletions pkg/antctl/raw/multicluster/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ package multicluster
import (
"github.com/spf13/cobra"

"antrea.io/antrea/pkg/antctl/raw/multicluster/add"
"antrea.io/antrea/pkg/antctl/raw/multicluster/create"
deleteCmd "antrea.io/antrea/pkg/antctl/raw/multicluster/delete"
"antrea.io/antrea/pkg/antctl/raw/multicluster/deploy"
"antrea.io/antrea/pkg/antctl/raw/multicluster/get"
)
Expand All @@ -34,32 +32,21 @@ var CreateCmd = &cobra.Command{
Short: "Create multi-cluster resources",
}

var AddCmd = &cobra.Command{
Use: "add",
Short: "Add a new member cluster to a ClusterSet",
}

var DeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete multi-cluster resources",
}

var DeployCmd = &cobra.Command{
Use: "deploy",
Short: "Deploy Antrea Multi-cluster Controller to a leader or member cluster",
}

var JoinCmd = NewJoinCommand()
var LeaveCmd = NewLeaveCommand()
var InitCmd = NewInitCommand()
var DestroyCmd = NewDestroyCommand()

func init() {
GetCmd.AddCommand(get.NewClusterSetCommand())
GetCmd.AddCommand(get.NewResourceImportCommand())
GetCmd.AddCommand(get.NewResourceExportCommand())
CreateCmd.AddCommand(create.NewClusterClaimCmd())
CreateCmd.AddCommand(create.NewAccessTokenCmd())
CreateCmd.AddCommand(create.NewClusterSetCmd())
DeleteCmd.AddCommand(deleteCmd.NewMemberClusterCmd())
DeleteCmd.AddCommand(deleteCmd.NewClusterSetCmd())
DeleteCmd.AddCommand(deleteCmd.NewClusterClaimCmd())
AddCmd.AddCommand(add.NewMemberClusterCmd())
DeployCmd.AddCommand(deploy.NewLeaderClusterCmd())
DeployCmd.AddCommand(deploy.NewMemberClusterCmd())
}
Loading

0 comments on commit 8efa04a

Please sign in to comment.