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

Multi-cluster bootstrap in antctl #3474

Merged
merged 1 commit into from
Jun 8, 2022
Merged

Conversation

hjiajing
Copy link
Contributor

Deploy multi-cluster ClusterSet in antctl command.
The users could just input antctl mc create or antctl mc add to create a new ClusterSet or add a member cluster to a existing ClusterSet rather than edit YAML files.

There are three verb in antctl mc command, add, create and delete. Use for creating ClusterSet, updating ClusterSet and deleting ClusterSet.
Signed-off-by: hjiajing hjiajing@vmware.com

@hjiajing
Copy link
Contributor Author

@luolanzone could please help to review? Thanks

@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2022

Codecov Report

Merging #3474 (c3c595e) into main (87918f6) will decrease coverage by 2.21%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3474      +/-   ##
==========================================
- Coverage   64.33%   62.12%   -2.22%     
==========================================
  Files         290      288       -2     
  Lines       41225    41252      +27     
==========================================
- Hits        26524    25626     -898     
- Misses      12578    13579    +1001     
+ Partials     2123     2047      -76     
Flag Coverage Δ
kind-e2e-tests 48.24% <ø> (-3.42%) ⬇️
unit-tests 44.34% <ø> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/antctl/antctl.go 50.00% <ø> (ø)
...g/agent/apiserver/handlers/featuregates/handler.go 4.54% <0.00%> (-77.28%) ⬇️
pkg/controller/egress/store/egressgroup.go 1.72% <0.00%> (-54.32%) ⬇️
pkg/agent/controller/networkpolicy/packetin.go 16.90% <0.00%> (-52.82%) ⬇️
...kg/apiserver/registry/system/supportbundle/rest.go 22.17% <0.00%> (-50.44%) ⬇️
pkg/agent/flowexporter/exporter/certificate.go 0.00% <0.00%> (-50.00%) ⬇️
pkg/support/dump.go 7.90% <0.00%> (-49.16%) ⬇️
pkg/support/dump_others.go 0.00% <0.00%> (-44.74%) ⬇️
...g/agent/apiserver/handlers/addressgroup/handler.go 5.00% <0.00%> (-35.00%) ⬇️
...agent/apiserver/handlers/appliedtogroup/handler.go 5.00% <0.00%> (-35.00%) ⬇️
... and 45 more

pkg/antctl/raw/multicluster/add/member_cluster.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/commands.go Outdated Show resolved Hide resolved
Comment on lines 97 to 105
scheme := k8sruntime.NewScheme()
if err = mcsscheme.AddToScheme(scheme); err != nil {
return err
}
if err = antreamcscheme.AddToScheme(scheme); err != nil {
return err
}
if err = k8sscheme.AddToScheme(scheme); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this will be done in a shared place for all mc commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is implemented in PR #3287 , so I will do rebase later and update it. Thanks

pkg/antctl/raw/multicluster/delete/clusterset.go Outdated Show resolved Hide resolved

func (o *memberClusterOptions) validateAndComplete() error {
if o.namespace == "" {
o.namespace = metav1.NamespaceDefault
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return err
}

fmt.Fprintf(cmd.OutOrStdout(), "member-cluster %s deleted", memberClusterID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/member-cluster/member cluster/
s/deleted/is deleted/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}
if len(memberClusters) == len(clusterSet.Spec.Members) {
return fmt.Errorf("member-cluster %s not found in ClusterSet %s", memberClusterID, memberClusterOpts.clusterSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/delete/member_cluster.go Outdated Show resolved Hide resolved
@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Mar 18, 2022
pkg/antctl/raw/multicluster/add/member_cluster.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/commands.go Show resolved Hide resolved

var DeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete Resources in a ClusterSet",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Resources/resources/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/create/clusterclaim.go Outdated Show resolved Hide resolved
Comment on lines 91 to 89
command.Flags().StringSliceVarP(&o.serviceAccount, "service-account", "", nil, "ServiceAccounts of the member clusters")
command.Flags().StringVarP(&o.secret, "secret", "", "", "Secret to access the leader cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serviceAccount is required only when creating ClusterSet in leader and secret is required only when it's in member cluster. maybe add some hints about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 87 to 85
command.Flags().StringVarP(&o.leaderClusterServer, "leader-server", "", "", "Leader cluster server address of the ClusterSet")
command.Flags().StringVarP(&o.leaderClusterPort, "leader-port", "", "6443", "Leader cluster port. If not set, use 6443 as default")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to combine these two options as one like option in kubectl
"leader-server'' The address and port of the leader cluster's Kubernetes API server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


var memberClusterExamples = strings.Trim(`
Delete a member cluster in a ClusterSet
$ antctl mc delete member-cluster <MEMBER_CLUSTER> -n <NAMESPACE> --cluster-set <CLUSTER_SET>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/MEMBER_CLUSTER/MEMBER_CLUSTER_ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return err
}

fmt.Fprintf(cmd.OutOrStdout(), "Member Cluster %s is deleted", memberClusterID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Cluster/cluster/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@lgtm-com
Copy link

lgtm-com bot commented Apr 5, 2022

This pull request introduces 1 alert when merging f8b36f8 into 7be763e - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Apr 7, 2022

This pull request introduces 1 alert when merging 1cfcb80 into 03b3f2b - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

return err
}

fmt.Fprintf(cmd.OutOrStdout(), "member cluster %s is added to ClusterSet %s successfully", memberClusterID, memberClusterOpt.clusterSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/member cluster/the member cluster/
s/ClusterSet/the ClusterSet/
make sure your error and output message format consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/deploy/deploy_helper.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Apr 10, 2022

This pull request introduces 1 alert when merging 5f69be5 into 7fea8d3 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@hjiajing hjiajing force-pushed the bootstrap branch 2 times, most recently from 53d0c1b to cde6995 Compare April 11, 2022 02:10
if o.leaderCluster == "" {
return fmt.Errorf("the leader-cluster-id cannot be empty")
}
if o.secret == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the serviceAccount field is only required when it's a ClustserSet in a leader cluster, and secret is only required when it's ClusterSet in a member cluster, Could you help to refine this kind of check? it's probably hard to check if it's member or leader, but maybe we can refine the validation here similar as below:

if o.secret == "" && o.memberClusters == nil {
  return fmt.Errorf("the service accounts list is required in leader cluster, the secret is required in member cluster")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

command.Flags().StringVarP(&o.leaderCluster, "leader-cluster", "", "", "Leader cluster of the ClusterSet")
command.Flags().StringVarP(&o.leaderClusterServer, "leader-server", "", "", "Leader cluster server address of the ClusterSet")
command.Flags().StringVarP(&o.leaderClusterNamespace, "leader-namespace", "", "", "Leader cluster Namespace")
command.Flags().StringToStringVarP(&o.memberClusters, "member-clusters", "", nil, "clusterID-ServiceAccount of the member clusters, it is required only when creating ClusterSet in leader cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change clusterID-ServiceAccount of the member clusters to clusterID and ServiceAccount group of the member clusters(e.g. --member-clusters member1=sa1,member2=sa2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/create/clusterset.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/delete/member_cluster.go Outdated Show resolved Hide resolved
return err
}
if len(args) != 1 {
return fmt.Errorf("exactly one NAME is required, got %d", len(args))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("exactly one NAME is required, got %d", len(args))
return fmt.Errorf("exactly one ClusterID is required, got %d", len(args))

}
}
if len(memberClusters) == len(clusterSet.Spec.Members) {
return fmt.Errorf("member-cluster %s not found in ClusterSet %s", memberClusterID, memberClusterOpts.clusterSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("member-cluster %s not found in ClusterSet %s", memberClusterID, memberClusterOpts.clusterSet)
return fmt.Errorf("member cluster %s not found in ClusterSet %s", memberClusterID, memberClusterOpts.clusterSet)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/deploy/deploy_helper.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/deploy/deploy_helper.go Outdated Show resolved Hide resolved
var memberClusterOpts *memberClusterOptions

var memberClusterExamples = strings.Trim(`
Create all the CRDs and resources of member cluster in namespace antrea-mcs-ns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create all the CRDs and resources of member cluster in namespace antrea-mcs-ns
Create all the CRDs and resources of member cluster in Namespace antrea-mcs-ns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder for Namespace

pkg/antctl/raw/multicluster/deploy/member_cluster.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/deploy/leader_cluster.go Outdated Show resolved Hide resolved
var leaderClusterOpts *leaderClusterOptions

var leaderClusterExamples = strings.Trim(`
Create all the CRDs and resources of leader cluster in namespace antrea-mcs-ns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create all the CRDs and resources of leader cluster in namespace antrea-mcs-ns
Create all the CRDs and resources of leader cluster in Namespace antrea-mcs-ns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/deploy/deploy_helper.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link to #3315? And is it the design description in the issue updated? If not, could you do so, so reviewers can understand?

var memberClusterOpts *memberClusterOptions

var memberClusterExamples = strings.Trim(`
Create all the CRDs and resources of member cluster in namespace antrea-mcs-ns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder for Namespace

return fmt.Errorf("the namespace cannot be empty")
}
if o.antreaVersion == "" {
return fmt.Errorf("the antrea-version cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is a must? Could we detect it from Antrea? We cannot default to antctl version? @luolanzone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jianjun. I think we could get the controller version by use antctl version code. I'm concerned about that only release version available and users may not use the antrea release verion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what is the issue if users are not using a release version? antctl can return dev version as well:

$ antctl version
antctlVersion: v1.7.0-dev-ac49f476.dirty
controllerVersion: v1.6.0-dev-f619dbd9.dirty

var leaderClusterOpts *leaderClusterOptions

var leaderClusterExamples = strings.Trim(`
Create all the CRDs and resources of leader cluster in Namespace antrea-mcs-ns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what exact this command does? What CRDs and resources are created? Why it is called "deploy" if it is not about deployment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jianjun. This command will create some CRDs and resources such as ServiceAccount and Role/RoleBinding of the multi-cluster controller, the deploy the Deployment "antrea-mc-controller". And I add more comments to the command.


func (o *memberClusterOptions) validateAndComplete() error {
if o.namespace == "" {
return fmt.Errorf("the namespace cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/antctl/raw/multicluster/delete/clusterset.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/clusterset.go Outdated Show resolved Hide resolved
@hjiajing hjiajing force-pushed the bootstrap branch 2 times, most recently from 2a432f5 to 3a081ab Compare May 6, 2022 07:47
return fmt.Errorf("the namespace cannot be empty")
}
if o.antreaVersion == "" {
return fmt.Errorf("the antrea-version cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what is the issue if users are not using a release version? antctl can return dev version as well:

$ antctl version
antctlVersion: v1.7.0-dev-ac49f476.dirty
controllerVersion: v1.6.0-dev-f619dbd9.dirty

pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/deploy/leader_cluster.go Outdated Show resolved Hide resolved
@hjiajing hjiajing force-pushed the bootstrap branch 4 times, most recently from 066af81 to b7be588 Compare May 16, 2022 11:04
@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 7, 2022

/test-multicluster-e2e

jianjuns
jianjuns previously approved these changes Jun 7, 2022
@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 7, 2022

/test-multicluster-e2e

1 similar comment
@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 7, 2022

/test-multicluster-e2e

luolanzone
luolanzone previously approved these changes Jun 7, 2022
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, One nit.

docs/multicluster/antctl.md Outdated Show resolved Hide resolved
@hjiajing hjiajing dismissed stale reviews from luolanzone and jianjuns via 9967584 June 7, 2022 08:29
@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 7, 2022

/test-multicluster-e2e

docs/multicluster/antctl.md Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/access_token.go Outdated Show resolved Hide resolved
pkg/antctl/raw/multicluster/create/clusterset.go Outdated Show resolved Hide resolved
@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 7, 2022

/test-multicluster-e2e

@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 8, 2022

/test-multicluster-e2e

@jianjuns
Copy link
Contributor

jianjuns commented Jun 8, 2022

Please fix the "Go / Verify docs and spelling" test failure. @hjiajing

@hjiajing
Copy link
Contributor Author

hjiajing commented Jun 8, 2022

@jianjuns Thanks for reminding. The Docs spelling failed because I used dollar as an example without output. Then I delete the dollar it passed now.

Add new subcommands to Create or Delete multi-cluster Resources.

Signed-off-by: hjiajing <hjiajing@vmware.com>
@jianjuns
Copy link
Contributor

jianjuns commented Jun 8, 2022

/test-multicluster-e2e

@jianjuns jianjuns merged commit 3e1b254 into antrea-io:main Jun 8, 2022
@jianjuns jianjuns added the action/release-note Indicates a PR that should be included in release notes. label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/multi-cluster Issues or PRs related to multi cluster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants