@@ -2,7 +2,6 @@ package action
22
33import (
44 "context"
5- "flag"
65 "fmt"
76 "time"
87
@@ -25,7 +24,7 @@ type OperatorInstall struct {
2524
2625 Package string
2726 Channel string
28- Approve string
27+ Approval subscription. ApprovalValue
2928 InstallMode operator.InstallMode
3029 InstallTimeout time.Duration
3130 CleanupTimeout time.Duration
@@ -40,12 +39,11 @@ func NewOperatorInstall(cfg *Configuration) *OperatorInstall {
4039
4140func (i * OperatorInstall ) BindFlags (fs * pflag.FlagSet ) {
4241 fs .StringVarP (& i .Channel , "channel" , "c" , "" , "subscription channel" )
43- fs .StringVarP (& i .Approve , "approval" , "a" , "" , "approval (Automatic or Manual)" )
42+ fs .VarP (& i .Approval , "approval" , "a" , fmt .Sprintf ("approval (%s or %s)" , v1alpha1 .ApprovalManual , v1alpha1 .ApprovalAutomatic ))
43+ fs .VarP (& i .InstallMode , "install-mode" , "i" , "install mode" )
4444 fs .DurationVarP (& i .InstallTimeout , "timeout" , "t" , time .Minute , "the amount of time to wait before cancelling the install" )
4545 fs .DurationVar (& i .CleanupTimeout , "cleanup-timeout" , time .Minute , "the amount to time to wait before cancelling cleanup" )
4646 fs .BoolVar (& i .CreateOperatorGroup , "create-operator-group" , false , "create operator group if necessary" )
47- imVal := pflag .PFlagFromGoFlag (& flag.Flag {Value : & i .InstallMode }).Value
48- fs .VarP (imVal , "install-mode" , "i" , "install mode" )
4947}
5048
5149func (i * OperatorInstall ) Run (ctx context.Context ) (* v1alpha1.ClusterServiceVersion , error ) {
@@ -85,9 +83,7 @@ func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
8583 }
8684
8785 opts := []subscription.Option {}
88- if i .Approve != "" {
89- opts = append (opts , subscription .InstallPlanApproval (v1alpha1 .Approval (i .Approve )))
90- }
86+ opts = append (opts , subscription .InstallPlanApproval (i .Approval .Approval ))
9187
9288 subKey := types.NamespacedName {
9389 Namespace : i .config .Namespace ,
@@ -103,6 +99,34 @@ func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
10399 }
104100 log .Printf ("subscription %q created" , sub .Name )
105101
102+ // We need to approve the initial install plan
103+ if i .Approval .Approval == v1alpha1 .ApprovalManual {
104+ if err := wait .PollImmediateUntil (time .Millisecond * 250 , func () (bool , error ) {
105+ if err := i .config .Client .Get (ctx , subKey , sub ); err != nil {
106+ return false , err
107+ }
108+ if sub .Status .InstallPlanRef != nil {
109+ return true , nil
110+ }
111+ return false , nil
112+ }, ctx .Done ()); err != nil {
113+ return nil , fmt .Errorf ("waiting for subscription install plan to exist: %v" , err )
114+ }
115+
116+ ip := v1alpha1.InstallPlan {}
117+ ipKey := types.NamespacedName {
118+ Namespace : sub .Status .InstallPlanRef .Namespace ,
119+ Name : sub .Status .InstallPlanRef .Name ,
120+ }
121+ if err := i .config .Client .Get (ctx , ipKey , & ip ); err != nil {
122+ return nil , fmt .Errorf ("get install plan: %v" , err )
123+ }
124+ ip .Spec .Approved = true
125+ if err := i .config .Client .Update (ctx , & ip ); err != nil {
126+ return nil , fmt .Errorf ("approve install plan: %v" , err )
127+ }
128+ }
129+
106130 if err := wait .PollImmediateUntil (time .Millisecond * 250 , func () (bool , error ) {
107131 if err := i .config .Client .Get (ctx , subKey , sub ); err != nil {
108132 return false , err
@@ -112,7 +136,7 @@ func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
112136 }
113137 return false , nil
114138 }, ctx .Done ()); err != nil {
115- return nil , fmt .Errorf ("waiting for state \" AtLatestKnown\" : %v" , err )
139+ return nil , fmt .Errorf ("waiting for subscription state \" AtLatestKnown\" : %v" , err )
116140 }
117141
118142 csvKey := types.NamespacedName {
0 commit comments