@@ -28,6 +28,7 @@ type OperatorInstall struct {
2828 Channel string
2929 Version string
3030 Approval subscription.ApprovalValue
31+ WatchNamespaces []string
3132 InstallMode operator.InstallMode
3233 InstallTimeout time.Duration
3334 CleanupTimeout time.Duration
@@ -44,13 +45,23 @@ func (i *OperatorInstall) BindFlags(fs *pflag.FlagSet) {
4445 fs .StringVarP (& i .Channel , "channel" , "c" , "" , "subscription channel" )
4546 fs .VarP (& i .Approval , "approval" , "a" , fmt .Sprintf ("approval (%s or %s)" , v1alpha1 .ApprovalManual , v1alpha1 .ApprovalAutomatic ))
4647 fs .StringVarP (& i .Version , "version" , "v" , "" , "install specific version for operator (default latest)" )
47- fs .VarP (& i .InstallMode , "install-mode " , "i " , "install mode " )
48+ fs .StringSliceVarP (& i .WatchNamespaces , "watch " , "w " , [] string {}, "namespaces to watch " )
4849 fs .DurationVarP (& i .InstallTimeout , "timeout" , "t" , time .Minute , "the amount of time to wait before cancelling the install" )
4950 fs .DurationVar (& i .CleanupTimeout , "cleanup-timeout" , time .Minute , "the amount to time to wait before cancelling cleanup" )
5051 fs .BoolVarP (& i .CreateOperatorGroup , "create-operator-group" , "C" , false , "create operator group if necessary" )
52+
53+ fs .VarP (& i .InstallMode , "install-mode" , "i" , "install mode" )
54+ fs .MarkHidden ("install-mode" )
5155}
5256
5357func (i * OperatorInstall ) Run (ctx context.Context ) (* v1alpha1.ClusterServiceVersion , error ) {
58+ if len (i .WatchNamespaces ) > 0 && ! i .InstallMode .IsEmpty () {
59+ return nil , fmt .Errorf ("WatchNamespaces and InstallMode options are mutually exclusive" )
60+ }
61+ if i .InstallMode .IsEmpty () {
62+ i .configureInstallModeFromWatch ()
63+ }
64+
5465 pm , err := i .getPackageManifest (ctx )
5566 if err != nil {
5667 return nil , fmt .Errorf ("get package manifest: %v" , err )
@@ -90,6 +101,22 @@ func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
90101 return csv , nil
91102}
92103
104+ func (i * OperatorInstall ) configureInstallModeFromWatch () {
105+ i .InstallMode .TargetNamespaces = i .WatchNamespaces
106+ switch len (i .InstallMode .TargetNamespaces ) {
107+ case 0 :
108+ i .InstallMode .InstallModeType = v1alpha1 .InstallModeTypeAllNamespaces
109+ case 1 :
110+ if i .InstallMode .TargetNamespaces [0 ] == i .config .Namespace {
111+ i .InstallMode .InstallModeType = v1alpha1 .InstallModeTypeOwnNamespace
112+ } else {
113+ i .InstallMode .InstallModeType = v1alpha1 .InstallModeTypeSingleNamespace
114+ }
115+ default :
116+ i .InstallMode .InstallModeType = v1alpha1 .InstallModeTypeMultiNamespace
117+ }
118+ }
119+
93120func (i * OperatorInstall ) getPackageManifest (ctx context.Context ) (* operatorsv1.PackageManifest , error ) {
94121 pm := & operatorsv1.PackageManifest {}
95122 key := types.NamespacedName {
0 commit comments