|
| 1 | +# Kubectl-oadp plugin design |
| 2 | + |
| 3 | +## Abstract |
| 4 | +The purpose of the kubectl-oadp plugin is to allow the customer to create and delete backups, along with creating restores in OADP without needing to alias velero to do so. Non-cluster admins should also be able to create NABs (Non-Admin Backups) and get the logs from them. |
| 5 | + |
| 6 | +## Background |
| 7 | +The current OpenShift cli is suboptimal as oc backup delete $foo deletes the k8s object instead of the backup but velero backup delete $foo deletes the backup, along with the backup files in storage. Currently, customers would need to alias velero in order to delete their backups, which is not ideal. The purpose of kubectl-oadp would be to make the cli experience better and easier to use along with enabling users to be able to get the logs of the backups. |
| 8 | + |
| 9 | +## Goals |
| 10 | +- Customers can create, delete, and get the logs of the backups and restores |
| 11 | +- A non-cluster admin can create, delete and receive the logs of the Non-Admin-Backups (NAB) |
| 12 | + |
| 13 | +## Non-Goals |
| 14 | +- Non-Admin-Restore and other Non-Admin CRs due to time constraints |
| 15 | + |
| 16 | +## Use-Case |
| 17 | +A use case of the kubectl-oadp cli could be when a non-cluster admin would like to create a NAB or view the logs of a NAB without having to depend on the cluster admins to do so. Another use case would be if a developer would want to create a normal backup, they can just use this plugin to do so. |
| 18 | + |
| 19 | +## High-Level Design |
| 20 | +Creating a kubectl plugin (kubectl-oadp) will be a good solution to the problem at hand. It will be able to create/delete backups and restores utilizing the go package imports. Non-cluster admin will be able to create NABs without the need for cluster admin to do it for them. A way to distinguish between creating either NABs or regular backups would be in the cli using the non-admin api. For instance, if you would like to create a NAB, you would have to do kubectl oadp nonadmin backup create [backupname]. |
| 21 | + |
| 22 | +## Detailed Design |
| 23 | +The kubectl plugin will have imports from velero to help with the creation/deletion of backups and restores. It will be written in Golang and be using cobra for command-line parsing. The non-admin cli can be a subset of some backup clis that already exist such as backup.go and create.go. |
| 24 | + |
| 25 | +What we discovered with the regular commands such as version, backup, and restore we can just import the libraries |
| 26 | + |
| 27 | +```go |
| 28 | +package cmd |
| 29 | + |
| 30 | +import ( |
| 31 | + "fmt" |
| 32 | + "os" |
| 33 | + |
| 34 | + "github.com/spf13/cobra" |
| 35 | + "github.com/vmware-tanzu/velero/pkg/cmd/cli/backup" |
| 36 | + "github.com/vmware-tanzu/velero/pkg/cmd/cli/restore" |
| 37 | + "github.com/vmware-tanzu/velero/pkg/cmd/cli/version" |
| 38 | +) |
| 39 | +``` |
| 40 | +With non-admin, we would have to create the cli ourselves since there are no CLIs for it. |
| 41 | + |
| 42 | +```go |
| 43 | +func NewCreateCommand(f client.Factory, use string) *cobra.Command { |
| 44 | + o := NewCreateOptions() |
| 45 | + |
| 46 | + c := &cobra.Command{ |
| 47 | + Use: use + " NAME", |
| 48 | + Short: "Create a non-admin backup", |
| 49 | + Args: cobra.MaximumNArgs(1), |
| 50 | + Run: func(c *cobra.Command, args []string) { |
| 51 | + cmd.CheckError(o.Complete(args, f)) |
| 52 | + cmd.CheckError(o.Validate(c, args, f)) |
| 53 | + cmd.CheckError(o.Run(c, f)) |
| 54 | + }, |
| 55 | + |
| 56 | +``` |
| 57 | +CLI Examples |
| 58 | +```sh |
| 59 | +kubectl oadp backup create |
| 60 | +kubectl oadp backup delete |
| 61 | +kubectl oadp nonadmin backup create <BACKUP_NAME> |
| 62 | +kubectl oadp nonadmin backup logs |
| 63 | +kubectl oadp nonadmin backup describe |
| 64 | +kubectl oadp restore create |
| 65 | +``` |
| 66 | +
|
| 67 | +## Alternatives Considered |
| 68 | +An alternative that was considered was creating our own CLI from scratch and not using a plugin. We can instead use the existing oc commands and just add on to them with a kubectl plugin. |
| 69 | +
|
| 70 | +Aliasing is another way in which you could access the velero command line. However, this is not ideal because non admins do not have permission to use the velero cli, so the kubectl plugin would allow non admins to retrieve their non admin backups similar to admins via velero cli. |
| 71 | +
|
| 72 | +## Security Considerations |
| 73 | +The security for the plugin is controlled by OpenShift RBAC, enabling cluster admins to manage user permissions. This is utilized to restrict users to commands permitted within their namespace. The plugin also generates error messages like "Unauthorized Access" when users attempt commands without proper permissions. |
| 74 | +
|
| 75 | +## Compatibility |
| 76 | +This plugin would need to be updated so that it would be importing the right version of the velero backup and restore libraries. |
| 77 | +
|
| 78 | +## Future Work |
| 79 | +Some future work that could be expanded upon would be Non-admin Restores, and other Non-admin CRs such as NonAdminBackupStorageLocation. These would allow more options for those who would like to use different non admin commands. |
0 commit comments