@@ -49,7 +49,7 @@ import (
4949 "github.com/vmware-tanzu/velero/pkg/cmd/cli/create"
5050 "github.com/vmware-tanzu/velero/pkg/cmd/cli/datamover"
5151 "github.com/vmware-tanzu/velero/pkg/cmd/cli/debug"
52- "github.com/vmware-tanzu/velero/pkg/cmd/cli/delete"
52+ veldelete "github.com/vmware-tanzu/velero/pkg/cmd/cli/delete"
5353 "github.com/vmware-tanzu/velero/pkg/cmd/cli/describe"
5454 "github.com/vmware-tanzu/velero/pkg/cmd/cli/get"
5555 "github.com/vmware-tanzu/velero/pkg/cmd/cli/repo"
@@ -349,6 +349,24 @@ func wrapPreRunE(existing func(*cobra.Command, []string) error, additional func(
349349 }
350350}
351351
352+ // isNonadminEnabled checks if nonadmin mode is enabled in the VeleroConfig.
353+ // Handles both boolean and string representations since
354+ // `oc oadp client config set nonadmin=true` stores the value as a string.
355+ func isNonadminEnabled (config clientcmd.VeleroConfig ) bool {
356+ val , ok := config ["nonadmin" ]
357+ if ! ok {
358+ return false
359+ }
360+ switch v := val .(type ) {
361+ case bool :
362+ return v
363+ case string :
364+ return strings .EqualFold (v , "true" )
365+ default :
366+ return false
367+ }
368+ }
369+
352370// NewVeleroRootCommand returns a root command with all Velero CLI subcommands attached.
353371func NewVeleroRootCommand (baseName string ) * cobra.Command {
354372
@@ -357,6 +375,13 @@ func NewVeleroRootCommand(baseName string) *cobra.Command {
357375 fmt .Fprintf (os .Stderr , "WARNING: Error reading config file: %v\n " , err )
358376 }
359377
378+ // When nonadmin mode is enabled, remove the namespace override so the
379+ // factory uses the current kubeconfig context namespace instead of an
380+ // admin namespace like openshift-adp.
381+ if isNonadminEnabled (config ) {
382+ delete (config , clientcmd .ConfigKeyNamespace )
383+ }
384+
360385 // Declare cmdFeatures and cmdColorzied here so we can access them in the PreRun hooks
361386 // without doing a chain of calls into the command's FlagSet
362387 var cmdFeatures veleroflag.StringArray
@@ -401,7 +426,7 @@ func NewVeleroRootCommand(baseName string) *cobra.Command {
401426 get .NewCommand (f ),
402427 describe .NewCommand (f ),
403428 create .NewCommand (f ),
404- delete .NewCommand (f ),
429+ veldelete .NewCommand (f ),
405430 cliclient .NewCommand (),
406431 completion .NewCommand (),
407432 repo .NewCommand (f ),
@@ -437,6 +462,21 @@ func NewVeleroRootCommand(baseName string) *cobra.Command {
437462 renameTimeoutFlag (cmd )
438463 }
439464
465+ // When nonadmin mode is enabled, hide all admin commands so only
466+ // nonadmin and client (for toggling the config) are visible.
467+ if isNonadminEnabled (config ) {
468+ allowedCmds := map [string ]bool {
469+ "nonadmin" : true ,
470+ "client" : true ,
471+ "completion" : true ,
472+ }
473+ for _ , cmd := range c .Commands () {
474+ if ! allowedCmds [cmd .Use ] {
475+ cmd .Hidden = true
476+ }
477+ }
478+ }
479+
440480 // Set custom usage template to show "oc oadp" instead of just "oadp"
441481 usageTemplate := c .UsageTemplate ()
442482 usageTemplate = strings .ReplaceAll (usageTemplate , "{{.CommandPath}}" , "oc {{.CommandPath}}" )
0 commit comments