Skip to content

Commit

Permalink
Remove Namespace creation and Nat/Denat refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
palexster committed Jul 7, 2021
1 parent 7cc1ce3 commit 58a92e1
Show file tree
Hide file tree
Showing 54 changed files with 1,024 additions and 390 deletions.
3 changes: 3 additions & 0 deletions apis/virtualKubelet/v1alpha1/groupversion_info.go
Expand Up @@ -34,6 +34,9 @@ var (
// NamespaceMapGroupResource is group resource used to register these objects.
NamespaceMapGroupResource = schema.GroupResource{Group: GroupVersion.Group, Resource: "namespacemaps"}

// NamespaceMapGroupVersionResource is groupResourceVersion used to register these objects.
NamespaceMapGroupVersionResource = schema.GroupVersionResource{Group: GroupVersion.Group, Version: "v1alpha1", Resource: "namespacemaps"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

Expand Down
2 changes: 1 addition & 1 deletion cmd/virtual-kubelet/main.go
Expand Up @@ -61,7 +61,7 @@ func main() {
if opts.Profiling {
enableProfiling()
}
if err := registerKubernetes(s); err != nil {
if err := registerKubernetes(ctx,s); err != nil {
klog.Fatal(err)
}
return nil
Expand Down
5 changes: 4 additions & 1 deletion cmd/virtual-kubelet/register.go
@@ -1,13 +1,16 @@
package main

import (
"context"

"github.com/liqotech/liqo/cmd/virtual-kubelet/provider"
liqoProvider "github.com/liqotech/liqo/pkg/virtualKubelet/provider"
)

func registerKubernetes(s *provider.Store) error {
func registerKubernetes(ctx context.Context, s *provider.Store) error {
return s.Register("kubernetes", func(cfg provider.InitConfig) (provider.Provider, error) {
return liqoProvider.NewLiqoProvider(
ctx,
cfg.NodeName,
cfg.RemoteClusterID,
cfg.HomeClusterID,
Expand Down
4 changes: 2 additions & 2 deletions cmd/virtual-kubelet/root/flag.go
Expand Up @@ -38,9 +38,9 @@ func InstallFlags(flags *pflag.FlagSet, c *Opts) {
"how often to perform a full resync of Liqo resources informers")
flags.DurationVar(&c.StartupTimeout, "startup-timeout", c.StartupTimeout, "How long to wait for the virtual-kubelet to start")

flags.StringVar(&c.ForeignClusterId, "foreign-cluster-id", c.ForeignClusterId, "The Id of the foreign cluster")
flags.StringVar(&c.ForeignClusterID, "foreign-cluster-id", c.ForeignClusterID, "The Id of the foreign cluster")
flags.StringVar(&c.KubeletNamespace, "kubelet-namespace", c.KubeletNamespace, "The namespace of the virtual kubelet")
flags.StringVar(&c.HomeClusterId, "home-cluster-id", c.HomeClusterId, "The Id of the home cluster")
flags.StringVar(&c.HomeClusterID, "home-cluster-id", c.HomeClusterID, "The Id of the home cluster")
flags.StringVar(&c.LiqoIpamServer, "ipam-server", c.LiqoIpamServer, "The server the Virtual Kubelet should"+
"connect to in order to contact the IPAM module")
flags.BoolVar(&c.Profiling, "enable-profiling", c.Profiling, "Enable pprof profiling")
Expand Down
18 changes: 5 additions & 13 deletions cmd/virtual-kubelet/root/opts.go
Expand Up @@ -16,11 +16,9 @@ package root

import (
"os"
"path/filepath"
"strconv"
"time"

"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"

"github.com/liqotech/liqo/pkg/consts"
Expand All @@ -37,7 +35,7 @@ const (
DefaultKubeClusterDomain = "cluster.local"

DefaultKubeletNamespace = "default"
DefaultHomeClusterId = "cluster1"
DefaultHomeClusterID = "cluster1"
DefaultLiqoIpamServer = consts.NetworkManagerServiceName
)

Expand Down Expand Up @@ -77,8 +75,8 @@ type Opts struct {
// Startup Timeout is how long to wait for the kubelet to start
StartupTimeout time.Duration

ForeignClusterId string
HomeClusterId string
ForeignClusterID string
HomeClusterID string
KubeletNamespace string

LiqoIpamServer string
Expand Down Expand Up @@ -126,16 +124,10 @@ func SetDefaultOpts(c *Opts) error {
}
if c.HomeKubeconfig == "" {
c.HomeKubeconfig = os.Getenv("KUBECONFIG")
if c.HomeKubeconfig == "" {
home, _ := homedir.Dir()
if home != "" {
c.HomeKubeconfig = filepath.Join(home, ".kube", "config")
}
}
}
// This is a workaround, when the cluster-id mechanism will be implemented, this parameter will be fetched accordingly
if c.HomeClusterId == "" {
c.HomeClusterId = DefaultHomeClusterId
if c.HomeClusterID == "" {
c.HomeClusterID = DefaultHomeClusterID
}

if c.LiqoIpamServer == "" {
Expand Down
8 changes: 4 additions & 4 deletions cmd/virtual-kubelet/root/root.go
Expand Up @@ -72,7 +72,7 @@ func runRootCommand(ctx context.Context, s *provider.Store, c *Opts) error {
return errors.New("provider kubeconfig is mandatory")
}

if c.ForeignClusterId == "" {
if c.ForeignClusterID == "" {
return errors.New("cluster id is mandatory")
}

Expand Down Expand Up @@ -126,8 +126,8 @@ func runRootCommand(ctx context.Context, s *provider.Store, c *Opts) error {
DaemonPort: c.ListenPort,
InternalIP: os.Getenv("VKUBELET_POD_IP"),
KubeClusterDomain: c.KubeClusterDomain,
RemoteClusterID: c.ForeignClusterId,
HomeClusterID: c.HomeClusterId,
RemoteClusterID: c.ForeignClusterID,
HomeClusterID: c.HomeClusterID,
RemoteKubeConfig: c.ForeignKubeconfig,
InformerResyncPeriod: c.InformerResyncPeriod,
LiqoIpamServer: c.LiqoIpamServer,
Expand Down Expand Up @@ -162,7 +162,7 @@ func runRootCommand(ctx context.Context, s *provider.Store, c *Opts) error {
liqoProvider.SetProviderStopper(podProviderStopper)
networkReadyChan := liqoProvider.GetNetworkReadyChan()

liqoNodeProvider, err := liqonodeprovider.NewLiqoNodeProvider(c.NodeName, c.ForeignClusterId,
liqoNodeProvider, err := liqonodeprovider.NewLiqoNodeProvider(c.NodeName, c.ForeignClusterID,
c.KubeletNamespace, pNode, podProviderStopper, networkReadyChan, nil, c.LiqoInformerResyncPeriod)
if err != nil {
klog.Fatal(err)
Expand Down
@@ -1,4 +1,12 @@
rules:
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand Down
24 changes: 13 additions & 11 deletions deployments/liqo/files/liqo-virtual-kubelet-local-ClusterRole.yaml
Expand Up @@ -3,7 +3,6 @@ rules:
- ""
resources:
- configmaps
- namespaces
- secrets
- services
verbs:
Expand All @@ -15,10 +14,15 @@ rules:
- apiGroups:
- ""
resources:
- namespaces/status
- nodes/status
- pods/status
- services/status
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- create
- delete
Expand All @@ -30,7 +34,9 @@ rules:
- apiGroups:
- ""
resources:
- nodes
- nodes/status
- pods/status
- services/status
verbs:
- create
- delete
Expand Down Expand Up @@ -114,12 +120,8 @@ rules:
- apiGroups:
- virtualkubelet.liqo.io
resources:
- namespacenattingtables
- namespacemaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
1 change: 1 addition & 0 deletions deployments/liqo/templates/liqo-virtual-kubelet-local.yaml
Expand Up @@ -7,3 +7,4 @@ kind: ClusterRole
metadata:
name: {{ include "liqo.prefixedName" $virtualKubeletConfig }}
{{ .Files.Get (include "liqo.cluster-role-filename" (dict "prefix" ( include "liqo.prefixedName" $virtualKubeletConfig))) }}
---
1 change: 0 additions & 1 deletion install.sh
Expand Up @@ -678,7 +678,6 @@ function main() {
launch_agent_installer
else
uninstall_liqodash
unjoin_clusters
purge_liqo_preuninstall
uninstall_liqo
purge_liqo
Expand Down

0 comments on commit 58a92e1

Please sign in to comment.