Skip to content

Commit ddf4d44

Browse files
authored
Add command 'antctl upgrade api-storage' in antctl (#5198)
To upgrade existing objects of Antrea CRDs to the storage version. Signed-off-by: Hongliang Liu <[email protected]>
1 parent 4dcd030 commit ddf4d44

File tree

6 files changed

+546
-4
lines changed

6 files changed

+546
-4
lines changed

docs/antctl.md

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Antctl
22

3-
Antctl is the command-line tool for Antrea. At the moment, antctl supports
3+
antctl is the command-line tool for Antrea. At the moment, antctl supports
44
running in three different modes:
55

66
* "controller mode": when run out-of-cluster or from within the Antrea
@@ -36,6 +36,7 @@ running in three different modes:
3636
- [Multi-cluster commands](#multi-cluster-commands)
3737
- [Multicast commands](#multicast-commands)
3838
- [Showing memberlist state](#showing-memberlist-state)
39+
- [Upgrade existing objects of CRDs](#upgrade-existing-objects-of-crds)
3940
<!-- /toc -->
4041

4142
## Installation
@@ -497,7 +498,7 @@ $ antctl traceflow -D pod1 -f tcp,tcp_dst=80 --live-traffic --dropped-only -t 10
497498

498499
### Antctl Proxy
499500

500-
Antctl can run as a reverse proxy for the Antrea API (Controller or arbitrary
501+
antctl can run as a reverse proxy for the Antrea API (Controller or arbitrary
501502
Agent). Usage is very similar to `kubectl proxy` and the implementation is
502503
essentially the same.
503504

@@ -669,7 +670,8 @@ testmulticast-vw7gx5b9 test3-sender-1 0 10
669670

670671
### Showing memberlist state
671672

672-
`antctl` agent command `get memberlist` (or `get ml`) prints the state of memberlist cluster of Antrea Agent.
673+
`antctl` agent command `get memberlist` (or `get ml`) prints the state of memberlist
674+
cluster of Antrea Agent.
673675

674676
```bash
675677
$ antctl get memberlist
@@ -679,3 +681,78 @@ worker1 172.18.0.4 Alive
679681
worker2 172.18.0.3 Alive
680682
worker3 172.18.0.2 Dead
681683
```
684+
685+
### Upgrade existing objects of CRDs
686+
687+
antctl supports upgrading existing objects of Antrea CRDs to the storage version.
688+
The related sub-commands should be run out-of-cluster. Please ensure that the
689+
kubeconfig file used by antctl has the necessary permissions. The required permissions
690+
are listed in the following sample ClusterRole.
691+
692+
```yaml
693+
apiVersion: rbac.authorization.k8s.io/v1
694+
kind: ClusterRole
695+
metadata:
696+
name: antctl
697+
rules:
698+
- apiGroups:
699+
- apiextensions.k8s.io
700+
resources:
701+
- customresourcedefinitions
702+
verbs:
703+
- get
704+
- list
705+
- apiGroups:
706+
- apiextensions.k8s.io
707+
resources:
708+
- customresourcedefinitions/status
709+
verbs:
710+
- update
711+
- apiGroups:
712+
- crd.antrea.io
713+
resources:
714+
- "*"
715+
verbs:
716+
- get
717+
- list
718+
- update
719+
```
720+
721+
This command performs a dry-run to upgrade all existing objects of Antrea CRDs to
722+
the storage version:
723+
724+
```bash
725+
antctl upgrade api-storage --dry-run
726+
```
727+
728+
This command upgrades all existing objects of Antrea CRDs to the storage version:
729+
730+
```bash
731+
antctl upgrade api-storage
732+
```
733+
734+
This command upgrades existing AntreaAgentInfo objects to the storage version:
735+
736+
```bash
737+
antctl upgrade api-storage --crds=antreaagentinfos.crd.antrea.io
738+
```
739+
740+
This command upgrades existing Egress and Group objects to the storage version:
741+
742+
```bash
743+
antctl upgrade api-storage --crds=egresses.crd.antrea.io,groups.crd.antrea.io
744+
```
745+
746+
If you encounter any errors related to permissions while running the commands, double-check
747+
the permissions of the kubeconfig used by antctl. Ensure that the ClusterRole has the
748+
required permissions. The following sample errors are caused by insufficient permissions:
749+
750+
```bash
751+
Error: failed to get CRD list: customresourcedefinitions.apiextensions.k8s.io is forbidden: User "user" cannot list resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope
752+
753+
Error: externalippools.crd.antrea.io is forbidden: User "user" cannot list resource "externalippools" in API group "crd.antrea.io" at the cluster scope
754+
755+
Error: error upgrading object prod-external-ip-pool of CRD "externalippools.crd.antrea.io": externalippools.crd.antrea.io "prod-external-ip-pool" is forbidden: User "user" cannot update resource "externalippools" in API group "crd.antrea.io" at the cluster scope
756+
757+
Error: error updating CRD "externalippools.crd.antrea.io" status.storedVersion: customresourcedefinitions.apiextensions.k8s.io "externalippools.crd.antrea.io" is forbidden: User "user" cannot update resource "customresourcedefinitions/status" in API group "apiextensions.k8s.io" at the cluster scope
758+
```

pkg/antctl/antctl.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"antrea.io/antrea/pkg/antctl/raw/set"
3333
"antrea.io/antrea/pkg/antctl/raw/supportbundle"
3434
"antrea.io/antrea/pkg/antctl/raw/traceflow"
35+
"antrea.io/antrea/pkg/antctl/raw/upgrade/apistorage"
3536
"antrea.io/antrea/pkg/antctl/transform/addressgroup"
3637
"antrea.io/antrea/pkg/antctl/transform/appliedtogroup"
3738
"antrea.io/antrea/pkg/antctl/transform/controllerinfo"
@@ -679,6 +680,12 @@ $ antctl get podmulticaststats pod -n namespace`,
679680
supportController: false,
680681
supportFlowAggregator: true,
681682
},
683+
{
684+
cobraCommand: apistorage.NewCommand(),
685+
supportAgent: false,
686+
supportController: false,
687+
commandGroup: upgrade,
688+
},
682689
},
683690
codec: scheme.Codecs,
684691
}

pkg/antctl/command_definition.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
get
7373
query
7474
mc
75+
upgrade
7576
)
7677

7778
var groupCommands = map[commandGroup]*cobra.Command{
@@ -90,6 +91,11 @@ var groupCommands = map[commandGroup]*cobra.Command{
9091
Short: "Sub-commands of multi-cluster feature",
9192
Long: "Sub-commands of multi-cluster feature",
9293
},
94+
upgrade: {
95+
Use: "upgrade",
96+
Short: "Sub-commands for upgrade operations",
97+
Long: "Sub-commands for upgrade operations",
98+
},
9399
}
94100

95101
type endpointResponder interface {

pkg/antctl/command_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func (cl *commandList) applyToRootCommand(root *cobra.Command, client AntctlClie
6363
if (runtime.Mode == runtime.ModeAgent && cmd.supportAgent) ||
6464
(runtime.Mode == runtime.ModeController && cmd.supportController) ||
6565
(runtime.Mode == runtime.ModeFlowAggregator && cmd.supportFlowAggregator) ||
66-
(!runtime.InPod && cmd.commandGroup == mc) {
66+
(!runtime.InPod && cmd.commandGroup == mc) ||
67+
(!runtime.InPod && cmd.commandGroup == upgrade) {
6768
if groupCommand, ok := groupCommands[cmd.commandGroup]; ok {
6869
groupCommand.AddCommand(cmd.cobraCommand)
6970
} else {

0 commit comments

Comments
 (0)