Skip to content

Commit 98c4a61

Browse files
authored
feat: sync mode modify api server & add ut for mode run and mode sync (#704)
* feat: mode sync modify kubeconfig apiserver to in cluster apiserver * feat: add ut for sync mode and run mode * fix: bugs
1 parent 4df63d1 commit 98c4a61

File tree

29 files changed

+1793
-399
lines changed

29 files changed

+1793
-399
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
5959
- name: Wait for pods reviews to be ready
6060
run: |
61-
kubectl wait --for=condition=Ready pods --all --timeout=3600s
61+
while ! kubectl wait --for=condition=Ready pods --all --timeout=3600s; do sleep 2; done
6262
kubectl get svc -A -o wide
6363
kubectl get pod -A -o wide
6464
kubectl get all -o wide

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
7575
- name: Wait for pods reviews to be ready
7676
run: |
77-
kubectl wait --for=condition=Ready pods --all --timeout=3600s
77+
while ! kubectl wait --for=condition=Ready pods --all --timeout=3600s; do sleep 2; done
7878
kubectl get svc -A -o wide
7979
kubectl get pod -A -o wide
8080
kubectl get all -o wide
@@ -146,7 +146,7 @@ jobs:
146146
147147
- name: Wait for pods reviews to be ready
148148
run: |
149-
kubectl wait --for=condition=Ready pods --all --timeout=3600s
149+
while ! kubectl wait --for=condition=Ready pods --all --timeout=3600s; do sleep 2; done
150150
kubectl get svc -A -o wide || true
151151
kubectl get pod -A -o wide || true
152152
kubectl get all -o wide || true
@@ -155,6 +155,9 @@ jobs:
155155
netstat -anr
156156
157157
- name: Test
158+
# for docker mount
159+
env:
160+
TMPDIR: /tmp
158161
run: make ut
159162

160163
windows:

cmd/kubevpn/cmds/connect.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ func CmdConnect(f cmdutil.Factory) *cobra.Command {
3636
Short: i18n.T("Connect to kubernetes cluster network"),
3737
Long: templates.LongDesc(i18n.T(`
3838
Connect to kubernetes cluster network
39-
40-
After connect to kubernetes cluster network, you can ping PodIP or
41-
curl ServiceIP in local PC, it also supports k8s DNS resolve.
42-
Like: curl authors/authors.default/authors.default.svc/authors.default.svc.cluster.local.
43-
So you can start up your application in local PC. depends on anything in
44-
k8s cluster is ok, connect to them just like in k8s cluster.
39+
40+
Upon establishing a connection to the Kubernetes cluster network, you can directly access Pod IPs and Service IPs from your local machine.
41+
This includes capabilities such as ping Pod IPs or curl Service IPs.
42+
Full Kubernetes DNS resolution is supported, enabling access via standard naming conventions,
43+
This allows you to run applications locally while seamlessly connecting to all resources within the Kubernetes cluster, as if operating inside the cluster itself.
4544
`)),
4645
Example: templates.Examples(i18n.T(`
4746
# Connect to k8s cluster network

cmd/kubevpn/cmds/run.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,8 @@ func CmdRun(f cmdutil.Factory) *cobra.Command {
100100
},
101101
RunE: func(cmd *cobra.Command, args []string) error {
102102
options.Workload = args[0]
103-
for i, arg := range args {
104-
if arg == "--" && i != len(args)-1 {
105-
options.ContainerOptions.Args = args[i+1:]
106-
break
107-
}
103+
if len(args) > 1 {
104+
options.ContainerOptions.Args = args[1:]
108105
}
109106

110107
if err := options.InitClient(f); err != nil {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/wencaiwulue/kubevpn/v2
33
go 1.23.2
44

55
require (
6+
github.com/calmh/incontainer v1.0.0
67
github.com/cilium/ipam v0.0.0-20230509084518-fd66eae7909b
78
github.com/containerd/containerd v1.7.27
89
github.com/containernetworking/cni v1.1.2
@@ -24,6 +25,7 @@ require (
2425
github.com/hpcloud/tail v1.0.0
2526
github.com/jcmturner/gofork v1.7.6
2627
github.com/jcmturner/gokrb5/v8 v8.4.4
28+
github.com/joho/godotenv v1.5.1
2729
github.com/kevinburke/ssh_config v1.2.0
2830
github.com/libp2p/go-netroute v0.2.1
2931
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
@@ -88,7 +90,6 @@ require (
8890
github.com/beorn7/perks v1.0.1 // indirect
8991
github.com/bits-and-blooms/bitset v1.13.0 // indirect
9092
github.com/blang/semver/v4 v4.0.0 // indirect
91-
github.com/calmh/incontainer v1.0.0 // indirect
9293
github.com/calmh/xdr v1.2.0 // indirect
9394
github.com/ccding/go-stun v0.1.5 // indirect
9495
github.com/cenkalti/backoff/v4 v4.3.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
361361
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
362362
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
363363
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
364+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
365+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
364366
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
365367
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
366368
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0WwEDBeqxKwb7WB62QX8bvZ/FJnVXIfk=

pkg/daemon/action/sync.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ func (svr *Server) Sync(resp rpc.Daemon_SyncServer) (err error) {
117117
}
118118
logger.Infof("Sync workloads...")
119119
options.SetContext(sshCtx)
120-
err = options.DoSync(plog.WithLogger(sshCtx, logger), []byte(req.KubeconfigBytes), req.Image)
120+
newKubeconfigBytes, err := options.ConvertApiServerToNodeIP(resp.Context(), []byte(req.KubeconfigBytes))
121+
if err != nil {
122+
return err
123+
}
124+
err = options.DoSync(plog.WithLogger(sshCtx, logger), newKubeconfigBytes, req.Image)
121125
if err != nil {
122126
plog.G(context.Background()).Errorf("Sync workloads failed: %v", err)
123127
return err

0 commit comments

Comments
 (0)