-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
209cfb0
commit 5bfddfc
Showing
26 changed files
with
1,763 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
.idea | ||
kind/ | ||
|
||
bin/ | ||
/github.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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(), | ||
) | ||
|
||
// 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.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.4.1 | ||
creationTimestamp: null | ||
name: nodeslicepools.whereabouts.cni.cncf.io | ||
spec: | ||
group: whereabouts.cni.cncf.io | ||
names: | ||
kind: NodeSlicePool | ||
listKind: NodeSlicePoolList | ||
plural: nodeslicepools | ||
singular: nodeslicepool | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: NodeSlicePool is the Schema for the nodesliceippools API | ||
properties: | ||
apiVersion: | ||
description: 'APIVersion defines the versioned schema of this representation | ||
of an object. Servers should convert recognized schemas to the latest | ||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
kind: | ||
description: 'Kind is a string value representing the REST resource this | ||
object represents. Servers may infer this from the endpoint the client | ||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
description: NodeSlicePoolSpec defines the desired state of NodeSlicePool | ||
properties: | ||
range: | ||
description: Range is a RFC 4632/4291-style string that represents | ||
an IP address and prefix length in CIDR notation this refers to | ||
the entire range where the node is allocated a subset | ||
type: string | ||
sliceSize: | ||
type: string | ||
required: | ||
- range | ||
- sliceSize | ||
type: object | ||
status: | ||
description: NodeSlicePoolStatus defines the desired state of NodeSlicePool | ||
properties: | ||
allocations: | ||
items: | ||
properties: | ||
nodeName: | ||
type: string | ||
sliceRange: | ||
type: string | ||
required: | ||
- nodeName | ||
- sliceRange | ||
type: object | ||
type: array | ||
required: | ||
- allocations | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
status: | ||
acceptedNames: | ||
kind: "" | ||
plural: "" | ||
conditions: [] | ||
storedVersions: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
pkg/api/whereabouts.cni.cncf.io/v1alpha1/nodeslicepool_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"net" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// NodeSlicePoolSpec defines the desired state of NodeSlicePool | ||
type NodeSlicePoolSpec struct { | ||
// Range is a RFC 4632/4291-style string that represents an IP address and prefix length in CIDR notation | ||
// this refers to the entire range where the node is allocated a subset | ||
Range string `json:"range"` | ||
|
||
SliceSize string `json:"sliceSize"` | ||
} | ||
|
||
// NodeSlicePoolStatus defines the desired state of NodeSlicePool | ||
type NodeSlicePoolStatus struct { | ||
Allocations []NodeSliceAllocation `json:"allocations"` | ||
} | ||
|
||
type NodeSliceAllocation struct { | ||
NodeName string `json:"nodeName"` | ||
SliceRange string `json:"sliceRange"` | ||
} | ||
|
||
// ParseCIDR formats the Range of the IPPool | ||
func (i NodeSlicePool) ParseCIDR() (net.IP, *net.IPNet, error) { | ||
return net.ParseCIDR(i.Spec.Range) | ||
} | ||
|
||
// +genclient | ||
// +kubebuilder:object:root=true | ||
|
||
// NodeSlicePool is the Schema for the nodesliceippools API | ||
type NodeSlicePool struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec NodeSlicePoolSpec `json:"spec,omitempty"` | ||
Status NodeSlicePoolStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// NodeSlicePoolList contains a list of NodeSlicePool | ||
type NodeSlicePoolList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []NodeSlicePool `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.