mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-11-02 11:34:28 +08:00
feat: add option extra-cidr
This commit is contained in:
@@ -47,9 +47,11 @@ import (
|
||||
)
|
||||
|
||||
type ConnectOptions struct {
|
||||
Namespace string
|
||||
Headers map[string]string
|
||||
Workloads []string
|
||||
Namespace string
|
||||
Headers map[string]string
|
||||
Workloads []string
|
||||
ExtraCIDR []string
|
||||
|
||||
clientset *kubernetes.Clientset
|
||||
restclient *rest.RESTClient
|
||||
config *rest.Config
|
||||
@@ -255,6 +257,14 @@ func (c *ConnectOptions) startLocalTunServe(ctx context.Context, forwardAddress
|
||||
for _, ipNet := range c.cidrs {
|
||||
list.Insert(ipNet.String())
|
||||
}
|
||||
// add extra-cidr
|
||||
for _, s := range c.ExtraCIDR {
|
||||
_, _, err = net.ParseCIDR(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid extra-cidr %s, err: %v", s, err)
|
||||
}
|
||||
list.Insert(s)
|
||||
}
|
||||
r := core.Route{
|
||||
ServeNodes: []string{
|
||||
fmt.Sprintf("tun:/127.0.0.1:8422?net=%s&route=%s", c.localTunIP.String(), strings.Join(list.UnsortedList(), ",")),
|
||||
|
||||
@@ -41,6 +41,7 @@ type DuplicateOptions struct {
|
||||
Namespace string
|
||||
Headers map[string]string
|
||||
Workloads []string
|
||||
ExtraCIDR []string
|
||||
|
||||
TargetKubeconfig string
|
||||
TargetNamespace string
|
||||
@@ -646,8 +647,31 @@ func (d *DuplicateOptions) setEnv(u *unstructured.Unstructured) error {
|
||||
}
|
||||
|
||||
// todo replace origin registry with special registry for pulling image
|
||||
func (d *DuplicateOptions) replaceRegistry(u *unstructured.Unstructured) {
|
||||
if d.TargetRegistry != "" {
|
||||
|
||||
func (d *DuplicateOptions) replaceRegistry(u *unstructured.Unstructured) error {
|
||||
if d.TargetRegistry == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
temp, path, err := util.GetPodTemplateSpecPath(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//for i, container := range temp.Spec.InitContainers {
|
||||
// if container.Image
|
||||
//}
|
||||
|
||||
var marshal []byte
|
||||
if marshal, err = json.Marshal(temp.Spec); err != nil {
|
||||
return err
|
||||
}
|
||||
var content map[string]interface{}
|
||||
if err = json.Unmarshal(marshal, &content); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = unstructured.SetNestedField(u.Object, content, append(path, "spec")...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
log "github.com/sirupsen/logrus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -299,3 +300,19 @@ func init() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
name := "alpine@sha256:b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c"
|
||||
named, err := reference.ParseNormalizedNamed(name)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
named = reference.TagNameOnly(named)
|
||||
domain := reference.Domain(named)
|
||||
path := reference.Path(named)
|
||||
tagged, ok := named.(reference.Tagged)
|
||||
if !ok {
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(domain, path, tagged)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user