feature: Sort import

This commit is contained in:
wencaiwulue
2022-06-22 10:49:27 +08:00
parent e1f8510ddc
commit 1ed2064eda
51 changed files with 649 additions and 834 deletions

View File

@@ -2,18 +2,20 @@ package cmds
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
config2 "github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/driver"
"github.com/wencaiwulue/kubevpn/pkg"
"github.com/wencaiwulue/kubevpn/util"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
"net/http"
"os"
"path/filepath"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/driver"
"github.com/wencaiwulue/kubevpn/pkg"
"github.com/wencaiwulue/kubevpn/util"
)
var connect = pkg.ConnectOptions{}
@@ -24,7 +26,7 @@ func init() {
connectCmd.PersistentFlags().StringArrayVar(&connect.Workloads, "workloads", []string{}, "workloads, like: pods/tomcat, deployment/nginx, replicaset/tomcat...")
connectCmd.Flags().StringVar((*string)(&connect.Mode), "mode", string(pkg.Reverse), "default mode is reverse")
connectCmd.Flags().StringToStringVarP(&connect.Headers, "headers", "H", map[string]string{}, "headers, format is k=v, like: k1=v1,k2=v2")
connectCmd.Flags().BoolVar(&config2.Debug, "debug", false, "true/false")
connectCmd.Flags().BoolVar(&config.Debug, "debug", false, "true/false")
RootCmd.AddCommand(connectCmd)
}
@@ -41,7 +43,7 @@ var connectCmd = &cobra.Command{
}
},
PreRun: func(*cobra.Command, []string) {
util.InitLogger(config2.Debug)
util.InitLogger(config.Debug)
if util.IsWindows() {
driver.InstallWireGuardTunDriver()
}

View File

@@ -2,20 +2,22 @@ package cmds
import (
"context"
"net/http"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
config2 "github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/pkg"
"github.com/wencaiwulue/kubevpn/util"
"net/http"
)
var config pkg.Route
var route pkg.Route
func init() {
ServerCmd.Flags().StringArrayVarP(&config.ServeNodes, "nodeCommand", "L", []string{}, "command needs to be executed")
ServerCmd.Flags().StringVarP(&config.ChainNode, "chainCommand", "F", "", "command needs to be executed")
ServerCmd.Flags().BoolVar(&config2.Debug, "debug", false, "true/false")
ServerCmd.Flags().StringArrayVarP(&route.ServeNodes, "nodeCommand", "L", []string{}, "command needs to be executed")
ServerCmd.Flags().StringVarP(&route.ChainNode, "chainCommand", "F", "", "command needs to be executed")
ServerCmd.Flags().BoolVar(&config.Debug, "debug", false, "true/false")
RootCmd.AddCommand(ServerCmd)
}
@@ -24,11 +26,11 @@ var ServerCmd = &cobra.Command{
Short: "serve",
Long: `serve`,
PreRun: func(*cobra.Command, []string) {
util.InitLogger(config2.Debug)
util.InitLogger(config.Debug)
go func() { log.Info(http.ListenAndServe("localhost:6060", nil)) }()
},
Run: func(cmd *cobra.Command, args []string) {
if err := pkg.Start(context.TODO(), config); err != nil {
if err := pkg.Start(context.TODO(), route); err != nil {
log.Fatal(err)
}
select {}

View File

@@ -2,11 +2,13 @@ package cmds
import (
"fmt"
"github.com/spf13/cobra"
config2 "github.com/wencaiwulue/kubevpn/config"
"runtime"
"runtime/debug"
"time"
"github.com/spf13/cobra"
"github.com/wencaiwulue/kubevpn/config"
)
// --ldflags -X
@@ -31,7 +33,7 @@ var versionCmd = &cobra.Command{
Long: `This is the version of KubeVPN`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("KubeVPN: CLI\n")
fmt.Printf(" Version: %s\n", config2.Version)
fmt.Printf(" Version: %s\n", config.Version)
fmt.Printf(" Branch: %s\n", Branch)
fmt.Printf(" Git commit: %s\n", GitCommit)
fmt.Printf(" Built time: %s\n", reformatDate(BuildTime))
@@ -43,9 +45,9 @@ var versionCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(versionCmd)
// Prefer version number inserted at build using --ldflags
if config2.Version == "" {
if config.Version == "" {
if i, ok := debug.ReadBuildInfo(); ok {
config2.Version = i.Main.Version
config.Version = i.Main.Version
}
}
}

View File

@@ -2,6 +2,7 @@ package main
import (
"github.com/wencaiwulue/kubevpn/cmd/kubevpn/cmds"
_ "net/http/pprof"
)

View File

@@ -3,9 +3,11 @@ package main
import (
"context"
"flag"
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
serverv3 "github.com/envoyproxy/go-control-plane/pkg/server/v3"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/pkg/control_plane"
"github.com/wencaiwulue/kubevpn/util"
)

View File

@@ -3,6 +3,7 @@ package config
import (
"crypto/tls"
"embed"
log "github.com/sirupsen/logrus"
)

View File

@@ -3,11 +3,12 @@ package config
import (
"crypto/tls"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/util"
"io"
"net"
"testing"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/util"
)
func init() {

View File

@@ -1,8 +1,9 @@
package core
import (
"github.com/wencaiwulue/kubevpn/config"
"sync"
"github.com/wencaiwulue/kubevpn/config"
)
var (

View File

@@ -2,11 +2,11 @@ package core
import (
"context"
"k8s.io/client-go/util/retry"
"net"
"time"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/util/retry"
)
type Server struct {

View File

@@ -2,8 +2,9 @@ package core
import (
"crypto/tls"
"github.com/wencaiwulue/kubevpn/config"
"net"
"github.com/wencaiwulue/kubevpn/config"
)
type tcpTransporter struct{}

View File

@@ -3,10 +3,12 @@ package core
import (
"context"
"errors"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"net"
"time"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
)
type fakeUDPTunnelConnector struct {

View File

@@ -3,7 +3,6 @@ package core
import (
"context"
"errors"
"github.com/wencaiwulue/kubevpn/config"
"net"
"sync"
"time"
@@ -13,6 +12,8 @@ import (
"github.com/songgao/water/waterutil"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
"github.com/wencaiwulue/kubevpn/config"
)
func ipToTunRouteKey(ip net.IP) string {

View File

@@ -3,14 +3,16 @@ package dns
import (
"bytes"
"context"
miekgdns "github.com/miekg/dns"
"github.com/pkg/errors"
"github.com/wencaiwulue/kubevpn/util"
v12 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/wencaiwulue/kubevpn/util"
)
func GetDNSServiceIPFromPod(clientset *kubernetes.Clientset, restclient *rest.RESTClient, config *rest.Config, podName, namespace string) (*miekgdns.ClientConfig, error) {

View File

@@ -4,10 +4,11 @@
package dns
import (
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"os"
"os/exec"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
)
// systemd-resolve --status, systemd-resolve --flush-caches

View File

@@ -1,11 +1,12 @@
package dns
import (
"strings"
"time"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/cache"
"strings"
"time"
)
type server struct {

View File

@@ -2,11 +2,13 @@ package dns
import (
"fmt"
miekgdns "github.com/miekg/dns"
"github.com/wencaiwulue/kubevpn/util"
"strconv"
"testing"
"time"
miekgdns "github.com/miekg/dns"
"github.com/wencaiwulue/kubevpn/util"
)
func TestSetupDnsServer(t *testing.T) {

View File

@@ -6,19 +6,21 @@ package dns
import (
"context"
"fmt"
"github.com/fsnotify/fsnotify"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/util"
"io/fs"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/sets"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/fsnotify/fsnotify"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
"github.com/wencaiwulue/kubevpn/util"
)
var cancel context.CancelFunc

View File

@@ -6,14 +6,15 @@ package dns
import (
"context"
"fmt"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"net"
"os"
"os/exec"
"strconv"
miekgdns "github.com/miekg/dns"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
)
func SetupDNS(config *miekgdns.ClientConfig) error {

View File

@@ -1,13 +1,15 @@
package driver
import (
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/driver/openvpn"
"github.com/wencaiwulue/kubevpn/driver/wintun"
"k8s.io/client-go/util/retry"
"os"
"os/exec"
"path/filepath"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/util/retry"
"github.com/wencaiwulue/kubevpn/driver/openvpn"
"github.com/wencaiwulue/kubevpn/driver/wintun"
)
func InstallTunTapDriver() {

80
go.mod
View File

@@ -4,36 +4,37 @@ go 1.18
require (
github.com/cilium/ipam v0.0.0-20211026130907-54a76012817c
github.com/containerd/containerd v1.5.7
github.com/docker/libcontainer v2.2.1+incompatible
github.com/envoyproxy/go-control-plane v0.10.1
github.com/fsnotify/fsnotify v1.4.9
github.com/fsnotify/fsnotify v1.5.1
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/miekg/dns v1.0.14
github.com/milosgajdos/tenus v0.0.3
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/onsi/ginkgo v1.14.1 // indirect
github.com/pkg/errors v0.9.1
github.com/shadowsocks/go-shadowsocks2 v0.1.5
github.com/sirupsen/logrus v1.8.1
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cobra v1.1.3
github.com/spf13/cobra v1.4.0
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
golang.org/x/sys v0.0.0-20220209214540-3681064d5158
golang.zx2c4.com/wireguard v0.0.0-20211209221555-9c9e7e272434
golang.zx2c4.com/wireguard/windows v0.4.10
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.36.0
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.2
k8s.io/apimachinery v0.21.2
k8s.io/cli-runtime v0.21.2
k8s.io/client-go v0.21.2
k8s.io/klog/v2 v2.10.0 // indirect
k8s.io/kubectl v0.21.2
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.24.2
k8s.io/apimachinery v0.24.2
k8s.io/cli-runtime v0.24.2
k8s.io/client-go v0.24.2
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kubectl v0.24.2
)
require (
github.com/golang/protobuf v1.5.2
sigs.k8s.io/yaml v1.3.0
)
require (
@@ -45,18 +46,19 @@ require (
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
@@ -64,14 +66,18 @@ require (
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.18.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
@@ -80,20 +86,20 @@ require (
github.com/stretchr/testify v1.7.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
k8s.io/component-base v0.21.2 // indirect
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/kustomize/api v0.8.8 // indirect
sigs.k8s.io/kustomize/kyaml v0.10.17 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.24.2 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/kustomize/api v0.11.4 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

895
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -3,19 +3,21 @@ package pkg
import (
"context"
"encoding/json"
"os"
"os/signal"
"strconv"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/dns"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
v12 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/util/retry"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/dns"
)
var stopChan = make(chan os.Signal)

View File

@@ -2,9 +2,15 @@ package pkg
import (
"context"
"errors"
"fmt"
errors2 "github.com/pkg/errors"
"net"
"os"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/core"
@@ -22,12 +28,6 @@ import (
"k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/polymorphichelpers"
"net"
"os"
"strconv"
"strings"
"sync/atomic"
"time"
)
type Mode string
@@ -299,7 +299,7 @@ func (c *ConnectOptions) setupDNS() {
func Start(ctx context.Context, r Route) error {
servers, err := r.GenerateServers()
if err != nil {
return errors2.WithStack(err)
return errors.WithStack(err)
}
if len(servers) == 0 {
return errors.New("invalid config")
@@ -415,7 +415,10 @@ func getCIDR(clientset *kubernetes.Clientset, namespace string) ([]*net.IPNet, e
func (c *ConnectOptions) InitClient() (err error) {
configFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
configFlags.KubeConfig = &c.KubeconfigPath
if _, err = os.Stat(c.KubeconfigPath); err == nil {
configFlags.KubeConfig = &c.KubeconfigPath
}
c.factory = cmdutil.NewFactory(cmdutil.NewMatchVersionFlags(configFlags))
if c.config, err = c.factory.ToRESTConfig(); err != nil {
@@ -432,7 +435,6 @@ func (c *ConnectOptions) InitClient() (err error) {
return
}
}
c.factory.ToRESTConfig()
log.Infof("kubeconfig path: %s, namespace: %s, services: %v", c.KubeconfigPath, c.Namespace, c.Workloads)
return
}

View File

@@ -4,8 +4,12 @@ import (
"context"
"crypto/md5"
"fmt"
"net"
"os/exec"
"testing"
"time"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
@@ -16,10 +20,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"net"
"os/exec"
"testing"
"time"
"github.com/wencaiwulue/kubevpn/util"
)
var (

View File

@@ -2,15 +2,17 @@ package control_plane
import (
"fmt"
"time"
cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
httpinspector "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/http_inspector/v3"
hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
tcp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
v32 "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
httpconnectionmanager "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
tcpproxy "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
matcher "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
@@ -18,13 +20,12 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
v1 "k8s.io/api/core/v1"
"time"
corev1 "k8s.io/api/core/v1"
)
type Virtual struct {
Uid string // group.resource.name
Ports []v1.ContainerPort
Ports []corev1.ContainerPort
Rules []*Rule
}
@@ -126,8 +127,8 @@ func ToRoute(clusterName string, headers map[string]string) *route.Route {
r = append(r, &route.HeaderMatcher{
Name: k,
HeaderMatchSpecifier: &route.HeaderMatcher_StringMatch{
StringMatch: &v32.StringMatcher{
MatchPattern: &v32.StringMatcher_Exact{
StringMatch: &matcher.StringMatcher{
MatchPattern: &matcher.StringMatcher_Exact{
Exact: v,
},
},
@@ -168,14 +169,14 @@ func DefaultRoute() *route.Route {
}
}
func ToListener(listenerName string, routeName string, port int32, p v1.Protocol) *listener.Listener {
func ToListener(listenerName string, routeName string, port int32, p corev1.Protocol) *listener.Listener {
var protocol core.SocketAddress_Protocol
switch p {
case v1.ProtocolTCP:
case corev1.ProtocolTCP:
protocol = core.SocketAddress_TCP
case v1.ProtocolUDP:
case corev1.ProtocolUDP:
protocol = core.SocketAddress_UDP
case v1.ProtocolSCTP:
case corev1.ProtocolSCTP:
protocol = core.SocketAddress_TCP
}
@@ -184,14 +185,14 @@ func ToListener(listenerName string, routeName string, port int32, p v1.Protocol
return pbst
}
httpManager := &hcm.HttpConnectionManager{
CodecType: hcm.HttpConnectionManager_AUTO,
httpManager := &httpconnectionmanager.HttpConnectionManager{
CodecType: httpconnectionmanager.HttpConnectionManager_AUTO,
StatPrefix: "http",
HttpFilters: []*hcm.HttpFilter{{
HttpFilters: []*httpconnectionmanager.HttpFilter{{
Name: wellknown.Router,
}},
RouteSpecifier: &hcm.HttpConnectionManager_Rds{
Rds: &hcm.Rds{
RouteSpecifier: &httpconnectionmanager.HttpConnectionManager_Rds{
Rds: &httpconnectionmanager.Rds{
ConfigSource: &core.ConfigSource{
ResourceApiVersion: resource.DefaultAPIVersion,
ConfigSourceSpecifier: &core.ConfigSource_ApiConfigSource{
@@ -212,9 +213,9 @@ func ToListener(listenerName string, routeName string, port int32, p v1.Protocol
},
}
tcpConfig := &tcp.TcpProxy{
tcpConfig := &tcpproxy.TcpProxy{
StatPrefix: "tcp",
ClusterSpecifier: &tcp.TcpProxy_Cluster{
ClusterSpecifier: &tcpproxy.TcpProxy_Cluster{
Cluster: "origin_cluster",
},
}

View File

@@ -3,15 +3,16 @@ package control_plane
import (
"context"
"fmt"
"io/ioutil"
"math"
"math/rand"
"strconv"
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/sirupsen/logrus"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/yaml"
"math"
"math/rand"
"strconv"
)
type Processor struct {

View File

@@ -3,6 +3,9 @@ package control_plane
import (
"context"
"fmt"
"log"
"net"
clusterservice "github.com/envoyproxy/go-control-plane/envoy/service/cluster/v3"
discoverygrpc "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
endpointservice "github.com/envoyproxy/go-control-plane/envoy/service/endpoint/v3"
@@ -12,8 +15,6 @@ import (
secretservice "github.com/envoyproxy/go-control-plane/envoy/service/secret/v3"
serverv3 "github.com/envoyproxy/go-control-plane/pkg/server/v3"
"google.golang.org/grpc"
"log"
"net"
)
const (

View File

@@ -3,24 +3,26 @@ package pkg
import (
"context"
"fmt"
"net"
"github.com/cilium/ipam/service/allocator"
"github.com/cilium/ipam/service/ipallocator"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
v12 "k8s.io/client-go/kubernetes/typed/core/v1"
"net"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"github.com/wencaiwulue/kubevpn/config"
)
type DHCPManager struct {
client v12.ConfigMapInterface
client corev1.ConfigMapInterface
cidr *net.IPNet
namespace string
}
func NewDHCPManager(client v12.ConfigMapInterface, namespace string, cidr *net.IPNet) *DHCPManager {
func NewDHCPManager(client corev1.ConfigMapInterface, namespace string, cidr *net.IPNet) *DHCPManager {
return &DHCPManager{
client: client,
namespace: namespace,

View File

@@ -4,12 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
config2 "github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/pkg/control_plane"
"github.com/wencaiwulue/kubevpn/pkg/mesh"
"github.com/wencaiwulue/kubevpn/util"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,8 +19,11 @@ import (
v12 "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/yaml"
"strings"
"time"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/pkg/control_plane"
"github.com/wencaiwulue/kubevpn/pkg/mesh"
"github.com/wencaiwulue/kubevpn/util"
)
// https://istio.io/latest/docs/ops/deployment/requirements/#ports-used-by-istio
@@ -60,7 +62,7 @@ func InjectVPNAndEnvoySidecar(factory cmdutil.Factory, clientset v12.ConfigMapIn
for _, container := range templateSpec.Spec.Containers {
containerNames.Insert(container.Name)
}
if containerNames.HasAll(config2.SidecarVPN, config2.SidecarEnvoyProxy) {
if containerNames.HasAll(config.SidecarVPN, config.SidecarEnvoyProxy) {
// add rollback func to remove envoy config
rollbackFuncList = append(rollbackFuncList, func() {
err = removeEnvoyConfig(clientset, nodeID, headers)
@@ -154,12 +156,12 @@ func UnPatchContainer(factory cmdutil.Factory, mapInterface v12.ConfigMapInterfa
}
func addEnvoyConfig(mapInterface v12.ConfigMapInterface, nodeID string, localTUNIP string, headers map[string]string, port []v1.ContainerPort) error {
configMap, err := mapInterface.Get(context.TODO(), config2.PodTrafficManager, metav1.GetOptions{})
configMap, err := mapInterface.Get(context.TODO(), config.PodTrafficManager, metav1.GetOptions{})
if err != nil {
return err
}
var v = make([]*control_plane.Virtual, 0)
if str, ok := configMap.Data[config2.Envoy]; ok {
if str, ok := configMap.Data[config.Envoy]; ok {
if err = yaml.Unmarshal([]byte(str), &v); err != nil {
return err
}
@@ -191,20 +193,20 @@ func addEnvoyConfig(mapInterface v12.ConfigMapInterface, nodeID string, localTUN
if err != nil {
return err
}
configMap.Data[config2.Envoy] = string(marshal)
configMap.Data[config.Envoy] = string(marshal)
_, err = mapInterface.Update(context.Background(), configMap, metav1.UpdateOptions{})
return err
}
func removeEnvoyConfig(mapInterface v12.ConfigMapInterface, nodeID string, headers map[string]string) error {
configMap, err := mapInterface.Get(context.TODO(), config2.PodTrafficManager, metav1.GetOptions{})
configMap, err := mapInterface.Get(context.TODO(), config.PodTrafficManager, metav1.GetOptions{})
if k8serrors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
str, ok := configMap.Data[config2.Envoy]
str, ok := configMap.Data[config.Envoy]
if !ok {
return errors.New("can not found value for key: envoy-config.yaml")
}
@@ -233,7 +235,7 @@ func removeEnvoyConfig(mapInterface v12.ConfigMapInterface, nodeID string, heade
if err != nil {
return err
}
configMap.Data[config2.Envoy] = string(marshal)
configMap.Data[config.Envoy] = string(marshal)
_, err = mapInterface.Update(context.Background(), configMap, metav1.UpdateOptions{})
return err
}

View File

@@ -1,13 +1,14 @@
package exchange
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/util"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)
func RemoveContainer(spec *v1.PodSpec) {
func RemoveContainer(spec *corev1.PodSpec) {
for i := 0; i < len(spec.Containers); i++ {
if spec.Containers[i].Name == config.SidecarVPN {
spec.Containers = append(spec.Containers[:i], spec.Containers[i+1:]...)
@@ -16,12 +17,12 @@ func RemoveContainer(spec *v1.PodSpec) {
}
}
func AddContainer(spec *v1.PodSpec, c util.PodRouteConfig) {
func AddContainer(spec *corev1.PodSpec, c util.PodRouteConfig) {
// remove vpn container if already exist
RemoveContainer(spec)
t := true
zero := int64(0)
spec.Containers = append(spec.Containers, v1.Container{
spec.Containers = append(spec.Containers, corev1.Container{
Name: config.SidecarVPN,
Image: config.ImageServer,
Command: []string{"/bin/sh", "-c"},
@@ -36,9 +37,9 @@ func AddContainer(spec *v1.PodSpec, c util.PodRouteConfig) {
"iptables -t nat -A OUTPUT -o lo ! -p icmp -j DNAT --to-destination " + c.LocalTunIP + ";" +
"kubevpn serve -L 'tun://0.0.0.0:8421/" + c.TrafficManagerRealIP + ":8422?net=" + c.InboundPodTunIP + "&route=" + c.Route + "' --debug=true",
},
SecurityContext: &v1.SecurityContext{
Capabilities: &v1.Capabilities{
Add: []v1.Capability{
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{
"NET_ADMIN",
//"SYS_MODULE",
},
@@ -46,17 +47,17 @@ func AddContainer(spec *v1.PodSpec, c util.PodRouteConfig) {
RunAsUser: &zero,
Privileged: &t,
},
Resources: v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: resource.MustParse("128m"),
v1.ResourceMemory: resource.MustParse("128Mi"),
Resources: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("128m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Limits: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: resource.MustParse("256m"),
v1.ResourceMemory: resource.MustParse("256Mi"),
Limits: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("256m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
},
ImagePullPolicy: v1.PullIfNotPresent,
ImagePullPolicy: corev1.PullIfNotPresent,
})
if len(spec.PriorityClassName) == 0 {
spec.PriorityClassName = "system-cluster-critical"

View File

@@ -2,11 +2,13 @@ package mesh
import (
"fmt"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/util"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/util"
)
func RemoveContainers(spec *v1.PodTemplateSpec) {

View File

@@ -2,10 +2,11 @@ package pkg
import (
"bytes"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
"net"
"strings"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
)
// DetectAndDisableConflictDevice will detect conflict route table and try to disable device

View File

@@ -5,10 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"strconv"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/pkg/exchange"
"github.com/wencaiwulue/kubevpn/util"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -23,10 +25,10 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/retry"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"net"
"strconv"
"strings"
"time"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/pkg/exchange"
"github.com/wencaiwulue/kubevpn/util"
)
func CreateOutboundPod(clientset *kubernetes.Clientset, namespace string, trafficManagerIP string, nodeCIDR []*net.IPNet) (net.IP, error) {

View File

@@ -5,10 +5,14 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"os/exec"
"path/filepath"
"testing"
"time"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/util"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -22,11 +26,9 @@ import (
"k8s.io/client-go/util/homedir"
"k8s.io/client-go/util/retry"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"net"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/util"
)
//func TestCreateServer(t *testing.T) {
@@ -174,7 +176,7 @@ func TestDeleteAndCreate(t *testing.T) {
object, err := util.GetUnstructuredObject(factory, Namespace, "pods/nginx")
u := object.Object.(*unstructured.Unstructured)
var pp v1.Pod
var pp corev1.Pod
marshal, err := json.Marshal(u)
err = json.Unmarshal(marshal, &pp)
@@ -187,7 +189,7 @@ func TestDeleteAndCreate(t *testing.T) {
}
_ = exec.Command("kubectl", "wait", "pods/nginx", "--for=delete").Run()
p := &v1.Pod{ObjectMeta: pp.ObjectMeta, Spec: pp.Spec}
p := &corev1.Pod{ObjectMeta: pp.ObjectMeta, Spec: pp.Spec}
CleanupUselessInfo(p)
if err = retry.OnError(wait.Backoff{
Steps: 10,
@@ -200,7 +202,7 @@ func TestDeleteAndCreate(t *testing.T) {
}
clientset, err := factory.KubernetesClientSet()
get, err := clientset.CoreV1().Pods(p.Namespace).Get(context.TODO(), p.Name, metav1.GetOptions{})
if err != nil || get.Status.Phase != v1.PodRunning {
if err != nil || get.Status.Phase != corev1.PodRunning {
return true
}
return false

View File

@@ -2,12 +2,14 @@ package pkg
import (
"crypto/tls"
"net"
"strings"
"github.com/pkg/errors"
"github.com/wencaiwulue/kubevpn/config"
"github.com/wencaiwulue/kubevpn/core"
"github.com/wencaiwulue/kubevpn/tun"
"net"
"strings"
)
type Route struct {

View File

@@ -4,9 +4,10 @@
package pkg
import (
"golang.org/x/net/route"
"net"
"syscall"
"golang.org/x/net/route"
)
// not contains route like 10.61.64/18 10.61.64.1 UCS utun3, todo how about pull a merge to golang sdk???

View File

@@ -4,11 +4,12 @@
package pkg
import (
log "github.com/sirupsen/logrus"
"net"
"os/exec"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
)
// sudo ifconfig utun3 down

View File

@@ -3,18 +3,6 @@ package main
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/util"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"net"
"net/http"
"os/exec"
@@ -24,6 +12,20 @@ import (
"sync"
"testing"
"time"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"github.com/wencaiwulue/kubevpn/util"
)
var (
@@ -49,7 +51,7 @@ func TestFunctions(t *testing.T) {
func pingPodIP(t *testing.T) {
ctx, f := context.WithTimeout(context.TODO(), time.Second*60)
defer f()
list, err := clientset.CoreV1().Pods(namespace).List(ctx, v1.ListOptions{})
list, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
t.Error(err)
}
@@ -72,7 +74,7 @@ func pingPodIP(t *testing.T) {
}
func healthCheckPod(t *testing.T) {
podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), v1.ListOptions{
podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", "productpage").String(),
})
if err != nil {
@@ -95,7 +97,7 @@ func healthCheckPod(t *testing.T) {
}
func healthCheckService(t *testing.T) {
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), v1.ListOptions{
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", "productpage").String(),
})
if err != nil {
@@ -119,7 +121,7 @@ func healthCheckService(t *testing.T) {
func shortDomain(t *testing.T) {
var app = "productpage"
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), v1.ListOptions{
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", app).String(),
})
if err != nil {
@@ -143,7 +145,7 @@ func shortDomain(t *testing.T) {
func fullDomain(t *testing.T) {
var app = "productpage"
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), v1.ListOptions{
serviceList, err := clientset.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", app).String(),
})
if err != nil {
@@ -169,7 +171,7 @@ func dialUDP(t *testing.T) {
port := util.GetAvailableUDPPortOrDie()
go server(port)
list, err := clientset.CoreV1().Pods(namespace).List(context.Background(), v1.ListOptions{
list, err := clientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", "reviews").String(),
})
if err != nil {

View File

@@ -1,10 +1,12 @@
package main
import (
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/tun"
"io"
"net"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/tun"
)
func main() {

View File

@@ -1,10 +1,12 @@
package main
import (
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/tun"
"io"
"net"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/tun"
)
func main() {

View File

@@ -2,11 +2,12 @@ package tun
import (
"errors"
log "github.com/sirupsen/logrus"
"github.com/songgao/water"
"net"
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/songgao/water"
)
// Config is the config for TUN device.

View File

@@ -2,13 +2,14 @@ package tun
import (
"fmt"
"github.com/wencaiwulue/kubevpn/config"
"net"
"os/exec"
"strings"
log "github.com/sirupsen/logrus"
"github.com/songgao/water"
"github.com/wencaiwulue/kubevpn/config"
)
func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {

View File

@@ -3,7 +3,6 @@ package tun
import (
"errors"
"fmt"
"github.com/wencaiwulue/kubevpn/config"
"net"
"syscall"
@@ -11,6 +10,8 @@ import (
"github.com/milosgajdos/tenus"
log "github.com/sirupsen/logrus"
"github.com/songgao/water"
"github.com/wencaiwulue/kubevpn/config"
)
func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {

View File

@@ -5,13 +5,14 @@ package tun
import (
"fmt"
"github.com/wencaiwulue/kubevpn/config"
"net"
"os/exec"
"strings"
log "github.com/sirupsen/logrus"
"github.com/songgao/water"
"github.com/wencaiwulue/kubevpn/config"
)
func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {

View File

@@ -2,13 +2,14 @@ package tun
import (
"fmt"
"net"
"os"
"time"
"github.com/pkg/errors"
"golang.org/x/sys/windows"
wireguardtun "golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"net"
"os"
"time"
)
func createTun(cfg Config) (net.Conn, *net.Interface, error) {

View File

@@ -5,20 +5,23 @@ package util
import (
"flag"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd"
"os"
"os/exec"
"os/signal"
"runtime"
"syscall"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd"
)
func RunWithElevated() {
// fix if startup with normal user, after elevated home dir will change to root user in linux
// but unix don't have this issue
if runtime.GOOS == "linux" && flag.Lookup("kubeconfig") == nil {
os.Args = append(os.Args, "--kubeconfig", clientcmd.RecommendedHomeFile)
if _, err := os.Stat(clientcmd.RecommendedHomeFile); err == nil {
os.Args = append(os.Args, "--kubeconfig", clientcmd.RecommendedHomeFile)
}
}
cmd := exec.Command("sudo", os.Args...)
log.Info(cmd.Args)

View File

@@ -4,11 +4,12 @@
package util
import (
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
"os"
"strings"
"syscall"
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
)
// ref https://stackoverflow.com/questions/31558066/how-to-ask-for-administer-privileges-on-windows-with-go

View File

@@ -2,8 +2,9 @@ package util
import (
"fmt"
log "github.com/sirupsen/logrus"
"path/filepath"
log "github.com/sirupsen/logrus"
)
func InitLogger(debug bool) {

View File

@@ -2,10 +2,11 @@ package util
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
"os/exec"
"time"
log "github.com/sirupsen/logrus"
"github.com/wencaiwulue/kubevpn/config"
)
// DeleteWindowsFirewallRule Delete all action block firewall rule

View File

@@ -4,25 +4,30 @@ import (
"bytes"
"context"
"encoding/binary"
"github.com/wencaiwulue/kubevpn/config"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubectl/pkg/polymorphichelpers"
"strconv"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"os"
osexec "os/exec"
"runtime"
"strconv"
"strings"
"time"
dockerterm "github.com/moby/term"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv4"
"io"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions"
runtimeresource "k8s.io/cli-runtime/pkg/resource"
@@ -36,14 +41,10 @@ import (
"k8s.io/client-go/transport/spdy"
"k8s.io/kubectl/pkg/cmd/exec"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/polymorphichelpers"
"k8s.io/kubectl/pkg/util/interrupt"
"net"
"net/http"
"os"
osexec "os/exec"
"runtime"
"strings"
"time"
"github.com/wencaiwulue/kubevpn/config"
)
func GetAvailableUDPPortOrDie() int {

View File

@@ -3,8 +3,10 @@ package util
import (
"context"
"fmt"
"net"
"testing"
log "github.com/sirupsen/logrus"
config2 "github.com/wencaiwulue/kubevpn/config"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/cli-runtime/pkg/genericclioptions"
@@ -12,15 +14,15 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubectl/pkg/cmd/util"
"net"
"testing"
"github.com/wencaiwulue/kubevpn/config"
)
var (
namespace string
clientset *kubernetes.Clientset
restclient *rest.RESTClient
config *rest.Config
restconfig *rest.Config
)
func TestShell(t *testing.T) {
@@ -30,20 +32,20 @@ func TestShell(t *testing.T) {
configFlags.KubeConfig = &clientcmd.RecommendedHomeFile
f := util.NewFactory(util.NewMatchVersionFlags(configFlags))
if config, err = f.ToRESTConfig(); err != nil {
if restconfig, err = f.ToRESTConfig(); err != nil {
log.Fatal(err)
}
if restclient, err = rest.RESTClientFor(config); err != nil {
if restclient, err = rest.RESTClientFor(restconfig); err != nil {
log.Fatal(err)
}
if clientset, err = kubernetes.NewForConfig(config); err != nil {
if clientset, err = kubernetes.NewForConfig(restconfig); err != nil {
log.Fatal(err)
}
if namespace, _, err = f.ToRawKubeConfigLoader().Namespace(); err != nil {
log.Fatal(err)
}
out, err := Shell(clientset, restclient, config, config2.PodTrafficManager, namespace, "cat /etc/resolv.conf | grep nameserver | awk '{print$2}'")
out, err := Shell(clientset, restclient, restconfig, config.PodTrafficManager, namespace, "cat /etc/resolv.conf | grep nameserver | awk '{print$2}'")
serviceList, err := clientset.CoreV1().Services(v1.NamespaceSystem).List(context.Background(), v1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("metadata.name", "kube-dns").String(),
})