You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an `--apply` flag to the install command that enables applying existing resources rather than creating them. This can be useful as part of the upgrade process for existing installations.
5
+
6
+
## Background
7
+
The current Velero install command creates resources but doesn't provide a direct way to apply updates to an existing installation.
8
+
Users attempting to run the install command on an existing installation receive "already exists" messages.
9
+
Upgrade steps for existing installs typically involve a three (or more) step process to apply updated CRDs (using `--dry-run` and piping to `kubectl apply`) and then updating/setting images on the Velero deployment and node-agent.
10
+
11
+
## Goals
12
+
- Provide a simple flag to enable applying resources on an existing Velero installation.
13
+
- Use server-side apply to update existing resources rather than attempting to create them.
14
+
- Maintain consistency with the regular install flow.
15
+
16
+
## Non Goals
17
+
- Implement special logic for specific version-to-version upgrades (i.e. resource deletion, etc).
18
+
- Add complex upgrade validation or pre/post-upgrade hooks.
19
+
- Provide rollback capabilities.
20
+
21
+
## High-Level Design
22
+
The `--apply` flag will be added to the Velero install command.
23
+
When this flag is set, the installation process will use server-side apply to update existing resources instead of using create on new resources.
24
+
This flag can be used as _part_ of the upgrade process, but will not always fully handle an upgrade.
25
+
26
+
## Detailed Design
27
+
The implementation adds a new boolean flag `--apply` to the install command.
28
+
This flag will be passed through to the underlying install functions where the resource creation logic resides.
29
+
30
+
When the flag is set to true:
31
+
- The `createOrApplyResource` function will use server-side apply with field manager "velero-cli" and `force=true` to update resources.
32
+
- Resources will be applied in the same order as they would be created during installation.
33
+
- Custom Resource Definitions will still be processed first, and the system will wait for them to be established before continuing.
34
+
35
+
The server-side apply approach with `force=true` ensures that resources are updated even if there are conflicts with the last applied state.
36
+
This provides a best-effort mechanism to apply resources that follows the same flow as installation but updates resources instead of creating them.
37
+
38
+
No special handling is added for specific versions or resource structures, making this a general-purpose mechanism for applying resources.
39
+
40
+
## Alternatives Considered
41
+
1. Creating a separate `upgrade` command that would duplicate much of the install command logic.
42
+
- Rejected due to code duplication and maintenance overhead.
43
+
44
+
2. Implementing version-specific upgrade logic to handle breaking changes between versions.
45
+
- Rejected as overly complex and difficult to maintain across multiple version paths.
46
+
- This could be considered again in the future, but is not in the scope of the current design.
47
+
48
+
3. Adding automatic detection of existing resources and switching to apply mode.
49
+
- Rejected as it could lead to unexpected behavior and confusion if users unintentionally apply changes to existing resources.
50
+
51
+
## Security Considerations
52
+
The apply flag maintains the same security profile as the install command.
53
+
No additional permissions are required beyond what is needed for resource creation.
54
+
The use of `force=true` with server-side apply could potentially override manual changes made to resources, but this is a necessary trade-off to ensure apply is successful.
55
+
56
+
## Compatibility
57
+
This enhancement is compatible with all existing Velero installations as it is a new opt-in flag.
58
+
It does not change any resource formats or API contracts.
59
+
The apply process is best-effort and does not guarantee compatibility between arbitrary versions of Velero.
60
+
Users should still consult release notes for any breaking changes that may require manual intervention.
61
+
This flag could be adopted by the helm chart, specifically for CRD updates, to simplify the CRD update job.
62
+
63
+
## Implementation
64
+
The implementation involves:
65
+
1. Adding support for `Apply` to the existing Kubernetes client code.
66
+
1. Adding the `--apply` flag to the install command options.
67
+
1. Changing `createResource` to `createOrApplyResource` and updating it to use server-side apply when the `apply` boolean is set.
68
+
69
+
The implementation is straightforward and follows existing code patterns.
70
+
No migration of state or special handling of specific resources is required.
Copy file name to clipboardExpand all lines: pkg/cmd/cli/install/install.go
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,7 @@ type Options struct {
92
92
ConcurrentBackupsint
93
93
NodeAgentDisableHostPathbool
94
94
kubeletRootDirstring
95
+
Applybool
95
96
ServerPriorityClassNamestring
96
97
NodeAgentPriorityClassNamestring
97
98
}
@@ -102,6 +103,7 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) {
102
103
flags.StringVar(&o.BucketName, "bucket", o.BucketName, "Name of the object storage bucket where backups should be stored")
103
104
flags.StringVar(&o.SecretFile, "secret-file", o.SecretFile, "File containing credentials for backup and volume provider. If not specified, --no-secret must be used for confirmation. Optional.")
104
105
flags.BoolVar(&o.NoSecret, "no-secret", o.NoSecret, "Flag indicating if a secret should be created. Must be used as confirmation if --secret-file is not provided. Optional.")
106
+
flags.BoolVar(&o.Apply, "apply", o.Apply, "Flag indicating if resources should be applied instead of created. This can be used for updating existing resources.")
105
107
flags.BoolVar(&o.NoDefaultBackupLocation, "no-default-backup-location", o.NoDefaultBackupLocation, "Flag indicating if a default backup location should be created. Must be used as confirmation if --bucket or --provider are not provided. Optional.")
106
108
flags.StringVar(&o.Image, "image", o.Image, "Image to use for the Velero and node agent pods. Optional.")
107
109
flags.StringVar(&o.Prefix, "prefix", o.Prefix, "Prefix under which all Velero data should be stored within the bucket. Optional.")
@@ -416,7 +418,7 @@ func (o *Options) Run(c *cobra.Command, f client.Factory) error {
416
418
417
419
errorMsg:=fmt.Sprintf("\n\nError installing Velero. Use `kubectl logs deploy/velero -n %s` to check the deploy logs", o.Namespace)
0 commit comments