Skip to content

Commit

Permalink
make --include-cluster-resources optional/default true for restores
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <steve@heptio.com>
  • Loading branch information
skriss committed Oct 23, 2017
1 parent b7d8ef5 commit 59b4ec9
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 49 deletions.
26 changes: 13 additions & 13 deletions docs/cli-reference/ark_create_restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ ark create restore BACKUP [flags]
### Options

```
--exclude-namespaces stringArray namespaces to exclude from the restore
--exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io
-h, --help help for restore
--include-cluster-resources include cluster-scoped resources in the restore (default true)
--include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *)
--include-resources stringArray resources to include in the restore, formatted as resource.group, such as storageclasses.storage.k8s.io (use '*' for all resources)
--label-columns stringArray a comma-separated list of labels to be displayed as columns
--labels mapStringString labels to apply to the restore
--namespace-mappings mapStringString namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...
-o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'.
--restore-volumes optionalBool[=true] whether to restore volumes from snapshots
-l, --selector labelSelector only restore resources matching this label selector (default <none>)
--show-labels show labels in the last column
--exclude-namespaces stringArray namespaces to exclude from the restore
--exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io
-h, --help help for restore
--include-cluster-resources optionalBool[=true] include cluster-scoped resources in the restore
--include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *)
--include-resources stringArray resources to include in the restore, formatted as resource.group, such as storageclasses.storage.k8s.io (use '*' for all resources)
--label-columns stringArray a comma-separated list of labels to be displayed as columns
--labels mapStringString labels to apply to the restore
--namespace-mappings mapStringString namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...
-o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'.
--restore-volumes optionalBool[=true] whether to restore volumes from snapshots
-l, --selector labelSelector only restore resources matching this label selector (default <none>)
--show-labels show labels in the last column
```

### Options inherited from parent commands
Expand Down
26 changes: 13 additions & 13 deletions docs/cli-reference/ark_restore_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ ark restore create BACKUP [flags]
### Options

```
--exclude-namespaces stringArray namespaces to exclude from the restore
--exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io
-h, --help help for create
--include-cluster-resources include cluster-scoped resources in the restore (default true)
--include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *)
--include-resources stringArray resources to include in the restore, formatted as resource.group, such as storageclasses.storage.k8s.io (use '*' for all resources)
--label-columns stringArray a comma-separated list of labels to be displayed as columns
--labels mapStringString labels to apply to the restore
--namespace-mappings mapStringString namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...
-o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'.
--restore-volumes optionalBool[=true] whether to restore volumes from snapshots
-l, --selector labelSelector only restore resources matching this label selector (default <none>)
--show-labels show labels in the last column
--exclude-namespaces stringArray namespaces to exclude from the restore
--exclude-resources stringArray resources to exclude from the restore, formatted as resource.group, such as storageclasses.storage.k8s.io
-h, --help help for create
--include-cluster-resources optionalBool[=true] include cluster-scoped resources in the restore
--include-namespaces stringArray namespaces to include in the restore (use '*' for all namespaces) (default *)
--include-resources stringArray resources to include in the restore, formatted as resource.group, such as storageclasses.storage.k8s.io (use '*' for all resources)
--label-columns stringArray a comma-separated list of labels to be displayed as columns
--labels mapStringString labels to apply to the restore
--namespace-mappings mapStringString namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...
-o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'.
--restore-volumes optionalBool[=true] whether to restore volumes from snapshots
-l, --selector labelSelector only restore resources matching this label selector (default <none>)
--show-labels show labels in the last column
```

### Options inherited from parent commands
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/ark/v1/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ type RestoreSpec struct {
RestorePVs *bool `json:"restorePVs"`

// IncludeClusterResources specifies whether cluster-scoped resources
// should be included for consideration in the restore.
IncludeClusterResources bool `json:"includeClusterResources"`
// should be included for consideration in the restore. If null, defaults
// to true.
IncludeClusterResources *bool `json:"includeClusterResources"`
}

// RestorePhase is a string representation of the lifecycle phase
Expand Down
9 changes: 5 additions & 4 deletions pkg/cmd/cli/restore/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type CreateOptions struct {
ExcludeResources flag.StringArray
NamespaceMappings flag.Map
Selector flag.LabelSelector
IncludeClusterResources bool
IncludeClusterResources flag.OptionalBool
}

func NewCreateOptions() *CreateOptions {
Expand All @@ -72,7 +72,7 @@ func NewCreateOptions() *CreateOptions {
IncludeNamespaces: flag.NewStringArray("*"),
NamespaceMappings: flag.NewMap().WithEntryDelimiter(",").WithKeyValueDelimiter(":"),
RestoreVolumes: flag.NewOptionalBool(nil),
IncludeClusterResources: true,
IncludeClusterResources: flag.NewOptionalBool(nil),
}
}

Expand All @@ -89,7 +89,8 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
// like a normal bool flag
f.NoOptDefVal = "true"

flags.BoolVar(&o.IncludeClusterResources, "include-cluster-resources", o.IncludeClusterResources, "include cluster-scoped resources in the restore")
f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "include cluster-scoped resources in the restore")
f.NoOptDefVal = "true"
}

func (o *CreateOptions) Validate(c *cobra.Command, args []string) error {
Expand Down Expand Up @@ -130,7 +131,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
NamespaceMapping: o.NamespaceMappings.Data(),
LabelSelector: o.Selector.LabelSelector,
RestorePVs: o.RestoreVolumes.Value,
IncludeClusterResources: o.IncludeClusterResources,
IncludeClusterResources: o.IncludeClusterResources.Value,
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func addToResult(r *api.RestoreResult, ns string, e error) {
func (ctx *context) restoreResource(resource, namespace, resourcePath string) (api.RestoreResult, api.RestoreResult) {
warnings, errs := api.RestoreResult{}, api.RestoreResult{}

if !ctx.restore.Spec.IncludeClusterResources && namespace == "" {
if ctx.restore.Spec.IncludeClusterResources != nil && !*ctx.restore.Spec.IncludeClusterResources && namespace == "" {
ctx.infof("Skipping resource %s because it's cluster-scoped", resource)
return warnings, errs
}
Expand Down
Loading

0 comments on commit 59b4ec9

Please sign in to comment.