Skip to content

Commit 72911ae

Browse files
committed
Update plugin to fix some probelms amd update image version to latest
fix version showing issue, now it uses upstream commit as plugin version update image to 2.0.1 in login part. wait for the deployment to be ready and then getthe QR code Signed-off-by: chenliu1993 <[email protected]>
1 parent ef6ea12 commit 72911ae

File tree

11 files changed

+74
-33
lines changed

11 files changed

+74
-33
lines changed

krew/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
bilipro

krew/Makefile

+19-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,30 @@ help: #### display help
2020
deploy: build install #### build + install
2121

2222

23+
.PHONY: fmt
24+
fmt: #### run go fmt against code
25+
@go fmt ./...
26+
27+
28+
.PHONY: vet
29+
vet: #### run go vet against code
30+
@go vet ./...
31+
32+
.PHONY: update-modules
33+
update-modules: tidy #### update go modules
34+
35+
.PHONY: tidy
36+
tidy: #### run go mod tidy
37+
@go mod tidy
38+
2339
.PHONY: build
2440
build: #### build the plugin
25-
@go vet ./... && \
26-
go fmt ./... && \
27-
echo "build on ${GOOS}/${GOARCH}" && \
28-
cd ${ROOT_DIR}/krew/cmd && \
29-
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags "-X github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd.Version=${GITCOMMIT}" -o $(BIN_NAME) kubectl-bilipro.go
30-
41+
@echo "build on ${GOOS}/${GOARCH}" && \
42+
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -mod readonly -ldflags "-X github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd.version=${GITCOMMIT}" -o bin/$(BIN_NAME) cmd/kubectl-bilipro.go
3143

3244
.PHONY: install
3345
install: #### install the plugin
34-
@cd ${ROOT_DIR}/krew/cmd && \
46+
@cd ${ROOT_DIR}/krew/bin && \
3547
sudo install ./$(BIN_NAME) ${KUBECTL_DIR}/$(BIN_NAME)
3648

3749
.PHONY: test

krew/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ For example: the kubectl is installed under `/usr/bin`, then put the bilibilipro
1818

1919
### Deployment && Update
2020

21-
Command: `kubectl bilipro init --config config.yaml [optional]--login`
21+
Prerequsites: please make sure you have the right permission to at least manage namespaces/deployments
22+
23+
Command: `kubectl bilipro init --config config.yaml`
2224

2325
Creates Deployment with the needed environments.
2426

2527
Optional Options:
2628

27-
- `--image=zai7lou/bilibili_tool_pro:1.0.1`
29+
- `--image=zai7lou/bilibili_tool_pro:2.0.1`
2830
- `--namespace=bilipro`
29-
- `--image-pull-secret=`
31+
- `--image-pull-secret=<docker secrets>`
32+
- `--login` to scan QR code to login
3033

3134
Required Options:
3235

krew/cmd/kubectl-bilipro.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
"github.com/spf13/pflag"
78

89
"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd"
910
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
1011
"k8s.io/cli-runtime/pkg/genericclioptions"
11-
"k8s.io/klog/v2"
1212
)
1313

1414
func main() {
@@ -17,7 +17,7 @@ func main() {
1717

1818
cmd := cmd.NewExecutor(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})
1919
if err := cmd.Execute(); err != nil {
20-
klog.Error(helper.GenErrorMsg(helper.SERVER_ERROR, err.Error()).Error())
20+
fmt.Println(helper.GenErrorMsg(helper.SERVER_ERROR, err.Error()).Error())
2121
os.Exit(1)
2222
}
2323
}

krew/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
k8s.io/apimachinery v0.25.4
1010
k8s.io/cli-runtime v0.25.4
1111
k8s.io/client-go v0.25.4
12-
k8s.io/klog/v2 v2.80.1
1312
sigs.k8s.io/kustomize/api v0.12.1
1413
sigs.k8s.io/kustomize/kyaml v0.13.9
1514
sigs.k8s.io/yaml v1.3.0
@@ -58,10 +57,11 @@ require (
5857
gopkg.in/inf.v0 v0.9.1 // indirect
5958
gopkg.in/yaml.v2 v2.4.0 // indirect
6059
gopkg.in/yaml.v3 v3.0.1 // indirect
60+
k8s.io/klog/v2 v2.80.1 // indirect
6161
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
6262
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
6363
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
6464
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
6565
)
6666

67-
replace github.com/RayWangQvQ/BiliBiliToolPro/krew => ../krew
67+
// replace github.com/RayWangQvQ/BiliBiliToolPro/krew => ../krew

krew/pkg/cmd/delete.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"io"
56
"os/exec"
67
"strings"
@@ -9,8 +10,6 @@ import (
910
"sigs.k8s.io/kustomize/api/types"
1011
"sigs.k8s.io/yaml"
1112

12-
"k8s.io/klog/v2"
13-
1413
"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
1514
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
1615
"github.com/spf13/cobra"
@@ -42,9 +41,10 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
4241

4342
err := o.run(out)
4443
if err != nil {
45-
klog.Error(err)
44+
fmt.Println(err)
4645
return err
4746
}
47+
fmt.Println("bilibili tool is removed from your cluster")
4848
return nil
4949
},
5050
}

krew/pkg/cmd/get.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"io"
56
"os/exec"
67

7-
"k8s.io/klog/v2"
8-
98
"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
109
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
1110
"github.com/spf13/cobra"
@@ -37,7 +36,7 @@ func newGetCmd(out io.Writer, errOut io.Writer) *cobra.Command {
3736

3837
err := o.run(out)
3938
if err != nil {
40-
klog.Error(err)
39+
fmt.Println(err)
4140
return err
4241
}
4342
return nil

krew/pkg/cmd/init.go

+34-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"os/exec"
99
"strings"
10-
"time"
1110

1211
corev1 "k8s.io/api/core/v1"
1312

@@ -17,8 +16,6 @@ import (
1716

1817
"sigs.k8s.io/kustomize/api/types"
1918

20-
"k8s.io/klog/v2"
21-
2219
"github.com/spf13/cobra"
2320

2421
"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
@@ -52,15 +49,15 @@ func newInitCmd(out io.Writer, errOut io.Writer) *cobra.Command {
5249
RunE: func(cmd *cobra.Command, args []string) error {
5350
err := o.run(out)
5451
if err != nil {
55-
klog.Error(err)
52+
fmt.Println(err)
5653
return err
5754
}
5855
return nil
5956
},
6057
}
6158

6259
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")
6461
f.StringVarP(&o.deployOpts.Namespace, "namespace", "n", "bilipro", "namespace scope for this request")
6562
f.StringVar(&o.deployOpts.ImagePullSecret, "image-pull-secret", "", "image pull secret to be used for pulling bilibilipro image")
6663
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 {
9491
}
9592

9693
// TODO: All about paths are a little bit tricky should give it more thoughts
94+
95+
fmt.Println("Creating the kustomization file")
9796
// if the bilibili tool is deployed under system/pre-defined namespace, ignore the namespace file
9897
var resources []string // nolint: go-staticcheck
9998
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 {
211210
}
212211
}
213212

213+
fmt.Println("Applying the kustomization file")
214214
// do kubectl apply
215215
// make sure kubectl is under your PATH
216216
cmd := exec.Command("kubectl", "apply", "-f", "-")
@@ -219,9 +219,9 @@ func (o *initCmd) run(writer io.Writer) error {
219219
return err
220220
}
221221

222-
// if there is login required
222+
// if there is login required, exectue the login command as the last step
223223
if o.login {
224-
224+
fmt.Println("please login...")
225225
client, _, err := helper.GetK8sClient()
226226
if err != nil {
227227
return err
@@ -233,8 +233,33 @@ func (o *initCmd) run(writer io.Writer) error {
233233
return err
234234
}
235235

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
238263
args := []string{
239264
"exec",
240265
podName,

krew/pkg/cmd/version.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"io"
66

7-
"k8s.io/klog/v2"
8-
97
"github.com/spf13/cobra"
108
)
119

@@ -35,7 +33,7 @@ func newVersionCmd(out io.Writer, errOut io.Writer) *cobra.Command {
3533
RunE: func(cmd *cobra.Command, args []string) error {
3634
err := o.run()
3735
if err != nil {
38-
klog.Error(err)
36+
fmt.Println(err)
3937
return err
4038
}
4139
return nil

krew/pkg/resources/base/bilibiliPro/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
spec:
1414
containers:
1515
- name: bilibilipro
16-
image: zai7lou/bilibili_tool_pro:1.0.1
16+
image: zai7lou/bilibili_tool_pro:2.0.1
1717
imagePullPolicy: IfNotPresent
1818
resources:
1919
requests:

krew/pkg/utils/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func GetK8sClient() (*kubernetes.Clientset, *rest.Config, error) {
3333
if err != nil {
3434
return nil, nil, GenErrorMsg(SERVER_ERROR, err.Error())
3535
}
36+
config.QPS = float32(10.0)
37+
config.Burst = 20
3638

3739
// create the clientset
3840
clientset, err := kubernetes.NewForConfig(config)

0 commit comments

Comments
 (0)