Skip to content

Commit

Permalink
fast node slice initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelichkovich committed May 13, 2024
1 parent 494db85 commit 2f5a718
Show file tree
Hide file tree
Showing 45 changed files with 12,245 additions and 200 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea
kind/

bin/
/github.com/
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ FROM alpine:latest
LABEL org.opencontainers.image.source https://github.com/k8snetworkplumbingwg/whereabouts
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/ip-control-loop .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/node-slice-controller .
COPY script/install-cni.sh .
CMD ["/install-cni.sh"]
269 changes: 269 additions & 0 deletions backup-ip-pools
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
apiVersion: v1
items:
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:14Z"
generation: 1
name: wa-nad-kind-control-plane
namespace: kube-system
resourceVersion: "89341"
uid: dd4f0db6-ab76-42bd-af65-51f851527b3e
spec:
allocations: {}
range: 10.0.0.0/8
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker
namespace: kube-system
resourceVersion: "89175"
uid: 0cf74918-2359-4ae0-a0b0-5e59c1f10f23
spec:
allocations:
"1":
id: 15e56cd8f50603a504f8852857fd32a81fdc177384258d39e0cce930cf26f5bf
podref: default/web-3
range: 10.0.64.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker10
namespace: kube-system
resourceVersion: "89199"
uid: fa824bd7-8baf-495a-87c1-250deb643529
spec:
allocations:
"1":
id: 4c7ef4d2c2364903a9eb95d48f6020a145d76dcd9426d255280f30e664c94f7c
podref: default/web-0
range: 10.0.128.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 3
name: wa-nad-kind-worker11
namespace: kube-system
resourceVersion: "89205"
uid: ec1151ef-5494-47e8-bc16-06c9b4141fa3
spec:
allocations:
"1":
id: 0d81f7b32979f895d4744a640f95f85fdee3c843622307813822da471830b216
podref: default/web-16
"2":
id: 65bffaae9cee8201cdb558f9eec95111a6bf06ae3903b8f45850bd0e9788879d
podref: default/web-13
range: 10.0.144.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:09Z"
generation: 2
name: wa-nad-kind-worker12
namespace: kube-system
resourceVersion: "89102"
uid: 0ec20afa-425d-4cc7-a94c-6e56b989fe14
spec:
allocations:
"1":
id: b65a1853354b42a413245835cf40d78baafdeab3e15092f0bb6cf315ae9145a9
podref: default/web-7
range: 10.0.0.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker13
namespace: kube-system
resourceVersion: "89248"
uid: 632ab0ab-0eca-4286-8a26-a9049500c7d1
spec:
allocations:
"1":
id: 69052635b467754fd351616c62075759c73ec8f73c9a20427cf7f3ed854b08ce
podref: default/web-9
range: 10.0.160.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker14
namespace: kube-system
resourceVersion: "89168"
uid: da9fdb1f-24b1-4a65-831e-8e09efd54158
spec:
allocations:
"1":
id: 1ed33682057dd7c11ae1d70c386008ae9cdf6e8eaf999fb0a088eac72f6e6092
podref: default/web-6
range: 10.0.176.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:12Z"
generation: 2
name: wa-nad-kind-worker15
namespace: kube-system
resourceVersion: "89319"
uid: 365b2337-edac-4dab-abb2-7e2fbf01cc3c
spec:
allocations:
"1":
id: 3334f1ae4dc5432c56aaf82b746bdc410d6047d80733811812f0975317f1e7fa
podref: default/web-12
range: 10.0.16.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:09Z"
generation: 2
name: wa-nad-kind-worker16
namespace: kube-system
resourceVersion: "89078"
uid: 147e4979-b2d9-44d2-b88c-6f425eea2894
spec:
allocations:
"1":
id: 652a78a6a20356b161d9759228809f898249ea5282e8b60b9da26e76096da096
podref: default/web-1
range: 10.0.32.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker2
namespace: kube-system
resourceVersion: "89153"
uid: fe4a0b26-897e-495f-8ddf-7dd2937e7ba8
spec:
allocations:
"1":
id: 03ec29893896071efc51537912d499adf414edb4692b9a2ae0de106e2bc630f9
podref: default/web-8
range: 10.0.192.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:12Z"
generation: 2
name: wa-nad-kind-worker3
namespace: kube-system
resourceVersion: "89279"
uid: 809444fc-3a7c-4c84-90c5-69f537706964
spec:
allocations:
"1":
id: f887517a5770729e6815c8b05233c193c737ccdbcaf4f944e8a924d887104fac
podref: default/web-19
range: 10.0.208.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:09Z"
generation: 2
name: wa-nad-kind-worker4
namespace: kube-system
resourceVersion: "89074"
uid: e2f79eff-2d62-4b90-9ab2-71d56db54371
spec:
allocations:
"1":
id: f52adf7bc90a10cffc46017d939c89574b7d2a73200a4bb88b917e993b1e22d8
podref: default/web-2
range: 10.0.48.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 3
name: wa-nad-kind-worker5
namespace: kube-system
resourceVersion: "89237"
uid: ea5bfc24-45bf-431a-a1f6-5c6d574537b9
spec:
allocations:
"1":
id: c079825def9e249408d639aad537b5a9f4c9ea70efd74b59a920c55e896d0809
podref: default/web-11
"2":
id: 3d4cc3799d6abe91578f85d5b54223a4ce0cf0c5003b61878347d2aab8bb90f7
podref: default/web-15
range: 10.0.96.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:09Z"
generation: 3
name: wa-nad-kind-worker6
namespace: kube-system
resourceVersion: "89103"
uid: 19ee6861-b60c-4191-9954-c563f2b6fdab
spec:
allocations:
"1":
id: 7a82e54f4aed85584b3140ebe32ec1a4e3c07f92cd7ce97b0771d25174e14b00
podref: default/web-14
"2":
id: f798a65997b572a3654937452fbee5b866ba7aaa4fa04d97f501cbebbf18fac5
podref: default/web-18
range: 10.0.224.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 2
name: wa-nad-kind-worker7
namespace: kube-system
resourceVersion: "89222"
uid: f96d1a90-c99a-402b-85bb-fde3ad9cb576
spec:
allocations:
"1":
id: 8c568d2c1b96bd400a2d3649c86eebf195519246dafcb7b7ed0ab3e320c84f14
podref: default/web-10
range: 10.0.80.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:09Z"
generation: 2
name: wa-nad-kind-worker8
namespace: kube-system
resourceVersion: "89109"
uid: c7632c7b-d465-430c-9979-cb58fed4b6bc
spec:
allocations:
"1":
id: 90e7c856df1951f79748e6fb21eba4ea1613c084a6aca66546b46c1f945244ae
podref: default/web-5
range: 10.0.240.0/20
- apiVersion: whereabouts.cni.cncf.io/v1alpha1
kind: IPPool
metadata:
creationTimestamp: "2024-05-13T18:06:11Z"
generation: 3
name: wa-nad-kind-worker9
namespace: kube-system
resourceVersion: "89224"
uid: 0b976109-aa6b-4e66-9198-0adf145bd6dd
spec:
allocations:
"1":
id: bc4d86106b2cb4a67154e8c2dcd3e801c0ce5892c54e74bfa59b9f116457e645
podref: default/web-17
"2":
id: 6286beace20b5c785abc3192b79b21d3968cfd2869c8bef1d902d0f210693162
podref: default/web-4
range: 10.1.0.0/20
kind: List
metadata:
resourceVersion: ""
91 changes: 91 additions & 0 deletions cmd/nodeslicecontroller/node_slice_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package main

import (
"flag"
nadclient "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned"
nadinformers "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/informers/externalversions"
clientset "github.com/k8snetworkplumbingwg/whereabouts/pkg/client/clientset/versioned"
informers "github.com/k8snetworkplumbingwg/whereabouts/pkg/client/informers/externalversions"
node_controller "github.com/k8snetworkplumbingwg/whereabouts/pkg/node-controller"

"time"

kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"

"github.com/k8snetworkplumbingwg/whereabouts/pkg/node-controller/signals"
)

var (
masterURL string
kubeconfig string
)

// TODO: leader election
func main() {
klog.InitFlags(nil)
flag.Parse()

// set up signals so we handle the shutdown signal gracefully
ctx := signals.SetupSignalHandler()
logger := klog.FromContext(ctx)

cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
logger.Error(err, "Error building kubeconfig")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
logger.Error(err, "Error building kubernetes clientset")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}

whereaboutsClient, err := clientset.NewForConfig(cfg)
if err != nil {
logger.Error(err, "Error building kubernetes clientset")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}

nadClient, err := nadclient.NewForConfig(cfg)
if err != nil {
logger.Error(err, "Error building kubernetes clientset")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
whereaboutsInformerFactory := informers.NewSharedInformerFactory(whereaboutsClient, time.Second*30)
nadInformerFactory := nadinformers.NewSharedInformerFactory(nadClient, time.Second*30)

controller := node_controller.NewController(
ctx,
kubeClient,
whereaboutsClient,
nadClient,
kubeInformerFactory.Core().V1().Nodes(),
whereaboutsInformerFactory.Whereabouts().V1alpha1().NodeSlicePools(),
whereaboutsInformerFactory.Whereabouts().V1alpha1().IPPools(),
nadInformerFactory.K8sCniCncfIo().V1().NetworkAttachmentDefinitions(),
false,
)

// notice that there is no need to run Start methods in a separate goroutine. (i.e. go kubeInformerFactory.Start(ctx.done())
// Start method is non-blocking and runs all registered informers in a dedicated goroutine.
kubeInformerFactory.Start(ctx.Done())
whereaboutsInformerFactory.Start(ctx.Done())
nadInformerFactory.Start(ctx.Done())

//TODO: make workers configurable via flag, what is a sane value here? How will concurrency work?
if err = controller.Run(ctx, 1); err != nil {
logger.Error(err, "Error running controller")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
}

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
}
Loading

0 comments on commit 2f5a718

Please sign in to comment.