Skip to content

Commit

Permalink
feat: use subnet crd to manage logical switch
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Jul 13, 2019
1 parent d6ffee7 commit ed7264e
Show file tree
Hide file tree
Showing 689 changed files with 84,212 additions and 17,214 deletions.
5 changes: 4 additions & 1 deletion cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "net/http/pprof"
"time"

kubeovninformer "github.com/alauda/kube-ovn/pkg/client/informers/externalversions"
"github.com/alauda/kube-ovn/pkg/daemon"
"github.com/alauda/kube-ovn/pkg/ovs"
kubeinformers "k8s.io/client-go/informers"
Expand Down Expand Up @@ -34,11 +35,13 @@ func main() {

stopCh := signals.SetupSignalHandler()
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(config.KubeClient, time.Second*30)
ctl, err := daemon.NewController(config, kubeInformerFactory)
kubeovnInformerFactory := kubeovninformer.NewSharedInformerFactoryWithOptions(config.KubeOvnClient, time.Second*30)
ctl, err := daemon.NewController(config, kubeInformerFactory, kubeovnInformerFactory)
if err != nil {
klog.Fatalf("create controller failed %v", err)
}
kubeInformerFactory.Start(stopCh)
kubeovnInformerFactory.Start(stopCh)
go ctl.Run(stopCh)
go func() {
klog.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", config.PprofPort), nil))
Expand Down
24 changes: 4 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@ require (
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/json-iterator/go v1.1.6 // indirect
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
github.com/juju/testing v0.0.0-20190613124551-e81189438503 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/parnurzeal/gorequest v0.2.15
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/projectcalico/felix v3.6.1+incompatible
github.com/projectcalico/go-json v0.0.0-20161128004156-6219dc7339ba // indirect
Expand All @@ -50,22 +41,15 @@ require (
github.com/spf13/pflag v1.0.3
github.com/vishvananda/netlink v1.0.0
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c // indirect
golang.org/x/net v0.0.0-20190328230028-74de082e2cca // indirect
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect
golang.org/x/sys v0.0.0-20190402142545-baf5eb976a8c // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
google.golang.org/appengine v1.5.0 // indirect
google.golang.org/grpc v1.21.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.42.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
k8s.io/api v0.0.0-20190111032252-67edc246be36
k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93
k8s.io/client-go v0.0.0-20190111032708-6bf63545bd02
k8s.io/klog v0.2.0
k8s.io/api v0.0.0-20190703205437-39734b2a72fe
k8s.io/apimachinery v0.0.0-20190703205208-4cfb76a8bf76
k8s.io/client-go v0.0.0-20190704045512-07281898b0f0
k8s.io/klog v0.3.1
k8s.io/kube-openapi v0.0.0-20190401085232-94e1e7b7574c // indirect
k8s.io/sample-controller v0.0.0-20190326030654-b8f621986e45
sigs.k8s.io/yaml v1.1.0 // indirect
)
82 changes: 60 additions & 22 deletions go.sum

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set -o errexit
set -o nounset
set -o pipefail
set -x

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
CODEGEN_PKG=$GOPATH/src/k8s.io/code-generator

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/alauda/kube-ovn/pkg/client github.com/alauda/kube-ovn/pkg/apis \
kubeovn:v1
5 changes: 5 additions & 0 deletions pkg/apis/kubeovn/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kubeovn

const (
GroupName = "kubeovn.io"
)
4 changes: 4 additions & 0 deletions pkg/apis/kubeovn/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// +k8s:deepcopy-gen=package
// +groupName=kubeovn.io

package v1
41 changes: 41 additions & 0 deletions pkg/apis/kubeovn/v1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/alauda/kube-ovn/pkg/apis/kubeovn"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: kubeovn.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder initializes a scheme builder
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&IP{},
&IPList{},
&Subnet{},
&SubnetList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
81 changes: 81 additions & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ProtocolIPv4 = "IPv4"
ProtocolIPv6 = "IPv6"
PrtotcolDual = "Dual"

GWDistributedType = "distributed"
GWCentralizedType = "centralized"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient:nonNamespaced

type IP struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IPSpec `json:"spec"`
}

type IPSpec struct {
PodName string `json:"podName"`
Namespace string `json:"namespace"`
NodeName string `json:"nodeName"`
IPAddress string `json:"ipAddress"`
MacAddress string `json:"macAddress"`
ContainerID string `json:"containerID"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type IPList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []IP `json:"items"`
}

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient:nonNamespaced

type Subnet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SubnetSpec `json:"spec"`
}

type SubnetSpec struct {
Default bool `json:"default"`
Protocol string `json:"protocol"`
Namespaces []string `json:"namespaces,omitempty"`
CIDRBlock string `json:"cidrBlock"`
Gateway string `json:"gateway"`
ExcludeIps []string `json:"excludeIps,omitempty"`

GatewayType string `json:"gatewayType"`
GatewayNode string `json:"gatewayNode"`
NatOutgoing bool `json:"natOutgoing"`

Private bool `json:"private"`
AllowSubnets []string `json:"allowSubnets,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type SubnetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Subnet `json:"items"`
}

0 comments on commit ed7264e

Please sign in to comment.