Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
wencaiwulue committed Nov 21, 2023
1 parent 0e0885a commit 817b6ce
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 21 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,13 @@ jobs:
choco install make
- name: Build
run: make kubevpn-windows-amd64
run: make kubevpn-windows-amd64
upload-coverage-reports-to-codecov:
- runs-on: ubuntu-latest
if: ${{ always() }}
needs: [ "linux", "macos", "windows" ]
steps:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[![GitHub License][5]](https://github.com/KubeNetworks/kubevpn/blob/main/LICENSE)
[![Docker Pulls][6]](https://hub.docker.com/r/naison/kubevpn)
[![Releases][7]](https://github.com/KubeNetworks/kubevpn/releases)
[![GoDoc](https://godoc.org/github.com/KubeNetworks/kubevpn?status.png)](https://godoc.org/github.com/KubeNetworks/kubevpn)
[![Test coverage](http://gocover.io/_badge/github.com/KubeNetworks/kubevpn)](https://gocover.io/github.com/KubeNetworks/kubevpn)


[1]: https://img.shields.io/github/actions/workflow/status/KubeNetworks/kubevpn/release.yml?logo=github

Expand Down
2 changes: 2 additions & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[![GitHub License][5]](https://github.com/KubeNetworks/kubevpn/blob/main/LICENSE)
[![Docker Pulls][6]](https://hub.docker.com/r/naison/kubevpn)
[![Releases][7]](https://github.com/KubeNetworks/kubevpn/releases)
[![GoDoc](https://godoc.org/github.com/KubeNetworks/kubevpn?status.png)](https://godoc.org/github.com/KubeNetworks/kubevpn)
[![Test coverage](http://gocover.io/_badge/github.com/KubeNetworks/kubevpn)](https://gocover.io/github.com/KubeNetworks/kubevpn)

[1]: https://img.shields.io/github/actions/workflow/status/KubeNetworks/kubevpn/release.yml?logo=github

Expand Down
2 changes: 1 addition & 1 deletion pkg/dev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func DoDev(ctx context.Context, devOption *Options, conf *util.SshConfig, flags
return err
}
if inspect.State == nil {
return fmt.Errorf("can not get container status, please make contianer name is valid")
return fmt.Errorf("can not get container status, please make container name is valid")
}
if !inspect.State.Running {
return fmt.Errorf("container %s status is %s, expect is running, please make sure your outer docker name is correct", mode.ConnectedContainer(), inspect.State.Status)
Expand Down
1 change: 0 additions & 1 deletion pkg/driver/openvpn/other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package openvpn

Expand Down
3 changes: 1 addition & 2 deletions pkg/driver/openvpn/windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package openvpn

Expand All @@ -13,7 +12,7 @@ import (
//go:embed exe/tap-windows-9.21.2.exe
var fs embed.FS

// driver download from https://build.openvpn.net/downloads/releases/
// driver download from https://build.openvpn.net/downloads/releases/
func Install() error {
bytes, err := fs.ReadFile("exe/tap-windows-9.21.2.exe")
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/driver/wintun/amd64.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows && amd64
// +build windows,amd64

package wintun

Expand Down
1 change: 0 additions & 1 deletion pkg/driver/wintun/arm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows && arm
// +build windows,arm

package wintun

Expand Down
1 change: 0 additions & 1 deletion pkg/driver/wintun/arm64.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows && arm64
// +build windows,arm64

package wintun

Expand Down
1 change: 0 additions & 1 deletion pkg/driver/wintun/others.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package wintun

Expand Down
2 changes: 0 additions & 2 deletions pkg/driver/wintun/x86.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//go:build windows && (x86 || 386)
// +build windows
// +build x86 386

package wintun

Expand Down
6 changes: 5 additions & 1 deletion pkg/test/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func main() {
if err != nil {
panic(err)
}
tunConn, err := listener.Accept()
var tunConn net.Conn
tunConn, err = listener.Accept()
if err != nil {
log.Fatal(err)
}
defer tunConn.Close()
tcpConn, err := net.Dial("tcp", ":1080")
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/util/elevate_others.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package util

Expand Down
1 change: 0 additions & 1 deletion pkg/util/elevate_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package util

Expand Down
1 change: 0 additions & 1 deletion pkg/util/elevatecheck_others.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package util

Expand Down
1 change: 0 additions & 1 deletion pkg/util/elevatecheck_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package util

Expand Down
5 changes: 3 additions & 2 deletions pkg/util/getcidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ func getCIDRFromCNI(clientset *kubernetes.Clientset, restclient *rest.RESTClient

var cmd = `grep -a -R "service-cluster-ip-range\|cluster-cidr" /etc/cni/proc/*/cmdline | grep -a -v grep | tr "\0" "\n"`

var result []*net.IPNet
content, err := Shell(clientset, restclient, restconfig, pod.Name, "", pod.Namespace, []string{"sh", "-c", cmd})
var content string
content, err = Shell(clientset, restclient, restconfig, pod.Name, "", pod.Namespace, []string{"sh", "-c", cmd})
if err != nil {
return nil, err
}

var result []*net.IPNet
for _, s := range strings.Split(content, "\n") {
result = Deduplicate(append(result, parseCIDRFromString(s)...))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TransferImage(ctx context.Context, conf *SshConfig, imageSource, imageTarge
}
defer os.Remove(file.Name())

logrus.Infof("Transfering image %s", imageTarget)
logrus.Infof("Transferring image %s", imageTarget)
filename := filepath.Base(file.Name())
cmd := fmt.Sprintf(
"(docker load image -i ~/.kubevpn/%s && docker push %s) || (nerdctl image load -i ~/.kubevpn/%s && nerdctl image push %s)",
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/upgarde.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ func GetManifest(httpCli *http.Client, os string, arch string) (version string,
var all []byte
all, err = io.ReadAll(resp.Body)
if err != nil {
err = fmt.Errorf("failed to read all reponse from github api, err: %v", err)
err = fmt.Errorf("failed to read all response from github api, err: %v", err)
return
}
var m RootEntity
err = json.Unmarshal(all, &m)
if err != nil {
err = fmt.Errorf("failed to unmarshal reponse, err: %v", err)
err = fmt.Errorf("failed to unmarshal response, err: %v", err)
return
}
version = m.TagName
Expand Down

0 comments on commit 817b6ce

Please sign in to comment.