7
7
"os"
8
8
"os/exec"
9
9
"strings"
10
- "time"
11
10
12
11
corev1 "k8s.io/api/core/v1"
13
12
@@ -17,8 +16,6 @@ import (
17
16
18
17
"sigs.k8s.io/kustomize/api/types"
19
18
20
- "k8s.io/klog/v2"
21
-
22
19
"github.com/spf13/cobra"
23
20
24
21
"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
@@ -52,15 +49,15 @@ func newInitCmd(out io.Writer, errOut io.Writer) *cobra.Command {
52
49
RunE : func (cmd * cobra.Command , args []string ) error {
53
50
err := o .run (out )
54
51
if err != nil {
55
- klog . Error (err )
52
+ fmt . Println (err )
56
53
return err
57
54
}
58
55
return nil
59
56
},
60
57
}
61
58
62
59
f := cmd .Flags ()
63
- f .StringVarP (& o .deployOpts .Image , "image" , "i" , "zai7lou/bilibili_tool_pro:1 .0.1" , "bilibilipro image" )
60
+ f .StringVarP (& o .deployOpts .Image , "image" , "i" , "zai7lou/bilibili_tool_pro:2 .0.1" , "bilibilipro image" )
64
61
f .StringVarP (& o .deployOpts .Namespace , "namespace" , "n" , "bilipro" , "namespace scope for this request" )
65
62
f .StringVar (& o .deployOpts .ImagePullSecret , "image-pull-secret" , "" , "image pull secret to be used for pulling bilibilipro image" )
66
63
f .StringVarP (& o .deployOpts .ConfigFilePath , "config" , "c" , "" , "the config file contanis the environment variables" )
@@ -94,6 +91,8 @@ func (o *initCmd) run(writer io.Writer) error {
94
91
}
95
92
96
93
// TODO: All about paths are a little bit tricky should give it more thoughts
94
+
95
+ fmt .Println ("Creating the kustomization file" )
97
96
// if the bilibili tool is deployed under system/pre-defined namespace, ignore the namespace file
98
97
var resources []string // nolint: go-staticcheck
99
98
if o .deployOpts .Namespace == "default" || o .deployOpts .Namespace == "kube-system" || o .deployOpts .Namespace == "kube-public" {
@@ -211,6 +210,7 @@ func (o *initCmd) run(writer io.Writer) error {
211
210
}
212
211
}
213
212
213
+ fmt .Println ("Applying the kustomization file" )
214
214
// do kubectl apply
215
215
// make sure kubectl is under your PATH
216
216
cmd := exec .Command ("kubectl" , "apply" , "-f" , "-" )
@@ -219,9 +219,9 @@ func (o *initCmd) run(writer io.Writer) error {
219
219
return err
220
220
}
221
221
222
- // if there is login required
222
+ // if there is login required, exectue the login command as the last step
223
223
if o .login {
224
-
224
+ fmt . Println ( "please login..." )
225
225
client , _ , err := helper .GetK8sClient ()
226
226
if err != nil {
227
227
return err
@@ -233,8 +233,33 @@ func (o *initCmd) run(writer io.Writer) error {
233
233
return err
234
234
}
235
235
236
- // TODO: Stupid way, just sleep to wait container is ready, maybe a watch is a better option
237
- time .Sleep (15 * time .Second )
236
+ fmt .Println ("wait for the deployment to be ready" )
237
+ // Wait for the deployment ready
238
+ checkCmdArgs := []string {
239
+ "rollout" ,
240
+ "status" ,
241
+ "deployment/bilibilipro" ,
242
+ "-n" ,
243
+ o .deployOpts .Namespace ,
244
+ }
245
+ checkCmd := exec .Command ("kubectl" , checkCmdArgs ... )
246
+
247
+ for {
248
+ if err := checkCmd .Start (); err != nil {
249
+ fmt .Printf ("deployment is not ready yet, current status: %v\n " , err )
250
+ continue
251
+ }
252
+
253
+ err := checkCmd .Wait ()
254
+ if err == nil {
255
+ fmt .Printf ("deployment is ready\n " )
256
+ break
257
+ }
258
+ fmt .Printf ("deployment is not ready yet, current status: %v\n " , err )
259
+ }
260
+
261
+ fmt .Println ("please scan the QR code" )
262
+ // Exec the login command
238
263
args := []string {
239
264
"exec" ,
240
265
podName ,
0 commit comments