Skip to content

Commit

Permalink
Merge pull request #209 from sids-b/fmt
Browse files Browse the repository at this point in the history
add fmt job in Makefile and run gofmt
  • Loading branch information
kevin-wangzefeng committed Jun 28, 2020
2 parents 0e75a4e + 5f0cb1d commit eb3d316
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 55 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GO_PATH=$(GOPATH)
SRCFILES=cni-genie.go
TEST_SRCFILES=$(wildcard *_test.go)
GO_PKG := $(shell go list ./... | grep -v vendor)

# Ensure that the dist directory is always created
MAKE_SURE_DIST_EXIST := $(shell mkdir -p dist)
Expand Down Expand Up @@ -66,3 +67,6 @@ endif
test:
go test ${PRINT} `go list ./${TESTDIR}/... | grep -v vendor | grep -v e2e | grep -v controllers`

.PHONY: fmt
fmt:
@go fmt $(GO_PKG)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ package network

const (
GroupName = "alpha.network.k8s.io"
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package versioned

import (
alphav1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned/typed/network/v1"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
flowcontrol "k8s.io/client-go/util/flowcontrol"
alphav1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned/typed/network/v1"
)

type Interface interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
package scheme

import (
alphav1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
alphav1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
)

var Scheme = runtime.NewScheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package v1

import (
scheme "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned/scheme"
v1 "github.com/cni-genie/CNI-Genie/utils"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
v1 "github.com/cni-genie/CNI-Genie/utils"
scheme "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned/scheme"
)

// LogicalNetworksGetter has a method to return a LogicalNetworkInterface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package v1

import (
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
rest "k8s.io/client-go/rest"
v1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
"github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned/scheme"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
rest "k8s.io/client-go/rest"
)

type AlphaV1Interface interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
sync "sync"
time "time"

versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
internalinterfaces "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/internalinterfaces"
network "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/network"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
cache "k8s.io/client-go/tools/cache"
versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
internalinterfaces "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/internalinterfaces"
network "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/network"
)

// SharedInformerOption defines the functional option type for SharedInformerFactory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package externalversions
import (
"fmt"

v1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
schema "k8s.io/apimachinery/pkg/runtime/schema"
cache "k8s.io/client-go/tools/cache"
v1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
)

// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package internalinterfaces
import (
time "time"

versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
cache "k8s.io/client-go/tools/cache"
versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
)

type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package v1
import (
time "time"

versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
internalinterfaces "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/internalinterfaces"
v1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/listers/network/v1"
network_v1 "github.com/cni-genie/CNI-Genie/utils"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
network_v1 "github.com/cni-genie/CNI-Genie/utils"
versioned "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/clientset/versioned"
internalinterfaces "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/informers/externalversions/internalinterfaces"
v1 "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/client/listers/network/v1"
)

// LogicalNetworkInformer provides access to a shared informer and lister for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
package v1

import (
r "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
v1 "github.com/cni-genie/CNI-Genie/utils"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
v1 "github.com/cni-genie/CNI-Genie/utils"
r "github.com/cni-genie/CNI-Genie/controllers/logicalnetwork-pkg/apis/alpha/network/v1"
)

// LogicalNetworkLister helps list LogicalNetworks.
Expand Down
2 changes: 1 addition & 1 deletion controllers/network-admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte) {
}
webhookConfig := &v1beta1.ValidatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "genie-network-admission-controller-config",
Name: "genie-network-admission-controller-config",
Namespace: "kube-system",
},
Webhooks: []v1beta1.ValidatingWebhook{
Expand Down
3 changes: 1 addition & 2 deletions controllers/network-admission-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import (
"io/ioutil"
"net/http"

"github.com/golang/glog"
genieUtils "github.com/cni-genie/CNI-Genie/utils"
"github.com/golang/glog"
"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

)

// only allow logical networks objects to be created only when all input validations are passed
Expand Down
61 changes: 29 additions & 32 deletions controllers/network-admission-controller/network-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"flag"
"fmt"
"github.com/golang/glog"
genieUtils "github.com/cni-genie/CNI-Genie/utils"
"github.com/golang/glog"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"net"
Expand All @@ -38,14 +38,14 @@ type PluginSubnetUsageData struct {
}

const (
ERR_NO_PLUGIN_MENTIONED_IN_LOGICAL_NETWORK = "No plugin mentioned in logical network";
ERR_NO_PLUGIN_MENTIONED_IN_PHYSICAL_NETWORK = "No plugin mentioned in physical network";
ERR_PHYSICAL_NW_NOT_FOUND = "Physical network not found";
ERR_INVALID_INNER_SUBNET = "Invalid inner subnet range";
ERR_SUBNET_OVERLAP_WITH_OTHER = "Inner subnet overlap with some other logical network subnet";
ERR_SUBNET_NOT_SPECIFIED = "Subnet not specified for logical network while using shared physical network";
ERR_INCORRECT_PHYSICALNETWORK_PARAS = "Incorrect physical network parameters";
ERR_INTERNAL_PROCESSING_FAILED = "Internal processing failure";
ERR_NO_PLUGIN_MENTIONED_IN_LOGICAL_NETWORK = "No plugin mentioned in logical network"
ERR_NO_PLUGIN_MENTIONED_IN_PHYSICAL_NETWORK = "No plugin mentioned in physical network"
ERR_PHYSICAL_NW_NOT_FOUND = "Physical network not found"
ERR_INVALID_INNER_SUBNET = "Invalid inner subnet range"
ERR_SUBNET_OVERLAP_WITH_OTHER = "Inner subnet overlap with some other logical network subnet"
ERR_SUBNET_NOT_SPECIFIED = "Subnet not specified for logical network while using shared physical network"
ERR_INCORRECT_PHYSICALNETWORK_PARAS = "Incorrect physical network parameters"
ERR_INTERNAL_PROCESSING_FAILED = "Internal processing failure"
)

var PluginSubnetUsageDataList []PluginSubnetUsageData
Expand Down Expand Up @@ -86,8 +86,8 @@ func checkSubnetOverlap(firstSubnetStr, secondSubnetStr string) bool {
_, secondSubnet, _ := net.ParseCIDR(secondSubnetStr)

for i := range secondSubnet.IP {
if secondSubnet.IP[i]&secondSubnet.Mask[i] != firstSubnet.IP[i]&firstSubnet.Mask[i]&secondSubnet.Mask[i] {
isFirstPartofSecond = false
if secondSubnet.IP[i]&secondSubnet.Mask[i] != firstSubnet.IP[i]&firstSubnet.Mask[i]&secondSubnet.Mask[i] {
isFirstPartofSecond = false
}
}

Expand All @@ -96,28 +96,27 @@ func checkSubnetOverlap(firstSubnetStr, secondSubnetStr string) bool {
}

for i := range firstSubnet.IP {
if firstSubnet.IP[i]&firstSubnet.Mask[i] != secondSubnet.IP[i]&secondSubnet.Mask[i]&firstSubnet.Mask[i] {
isSecondPartofFirst = false
if firstSubnet.IP[i]&firstSubnet.Mask[i] != secondSubnet.IP[i]&secondSubnet.Mask[i]&firstSubnet.Mask[i] {
isSecondPartofFirst = false
}
}

if true == isSecondPartofFirst {
return true
}

/* This means 2 subnets do not overlap*/
/* This means 2 subnets do not overlap*/
return false
}


/* Function to validate whether the innerSubnetStr is part of outer subnet or not*/
func checkIfValidInnerSubnet(outerSubnetStr, innerSubnetStr string) bool {

_, outerSubnet, _ := net.ParseCIDR(outerSubnetStr)
_, innerSubnet, _ := net.ParseCIDR(innerSubnetStr)

for i := range outerSubnet.IP {
if outerSubnet.IP[i]&outerSubnet.Mask[i] != innerSubnet.IP[i]&innerSubnet.Mask[i]&outerSubnet.Mask[i] {
if outerSubnet.IP[i]&outerSubnet.Mask[i] != innerSubnet.IP[i]&innerSubnet.Mask[i]&outerSubnet.Mask[i] {
return false
}
}
Expand Down Expand Up @@ -154,7 +153,6 @@ func validateNetworkParas(logicalNetwork *genieUtils.LogicalNetwork) *v1beta1.Ad
physicalNwPath := fmt.Sprintf("/apis/alpha.network.k8s.io/v1/namespaces/%s/physicalnetworks/%s",
logicalNetwork.ObjectMeta.Namespace, phyNwName)


physicalNwObj, err := client.ExtensionsV1beta1().RESTClient().Get().AbsPath(physicalNwPath).DoRaw()

if err != nil {
Expand All @@ -177,7 +175,7 @@ func validateNetworkParas(logicalNetwork *genieUtils.LogicalNetwork) *v1beta1.Ad

selectedPluginName := physicalNwInfo.Spec.SharedStatus.Plugin

if "" == selectedPluginName {
if "" == selectedPluginName {
admissionResponse.Result = &metav1.Status{
Reason: ERR_NO_PLUGIN_MENTIONED_IN_PHYSICAL_NETWORK,
}
Expand All @@ -189,7 +187,7 @@ func validateNetworkParas(logicalNetwork *genieUtils.LogicalNetwork) *v1beta1.Ad
outerSubnet := physicalNwInfo.Spec.SharedStatus.Subnet

isvalidSubnet := checkIfValidInnerSubnet(outerSubnet, logicalNetwork.Spec.SubSubnet)
if false == isvalidSubnet {
if false == isvalidSubnet {

admissionResponse.Result = &metav1.Status{
Reason: ERR_INVALID_INNER_SUBNET,
Expand All @@ -199,18 +197,18 @@ func validateNetworkParas(logicalNetwork *genieUtils.LogicalNetwork) *v1beta1.Ad
selectedSubnet = logicalNetwork.Spec.SubSubnet
} else {
/* Incase of shared physical network, subnet and plugin must be specified as part of logical network*/
if "" == logicalNetwork.Spec.Plugin {
admissionResponse.Result = &metav1.Status{
Reason: ERR_NO_PLUGIN_MENTIONED_IN_LOGICAL_NETWORK,
}
return &admissionResponse
if "" == logicalNetwork.Spec.Plugin {
admissionResponse.Result = &metav1.Status{
Reason: ERR_NO_PLUGIN_MENTIONED_IN_LOGICAL_NETWORK,
}
return &admissionResponse

}
if "" == logicalNetwork.Spec.SubSubnet {
admissionResponse.Result = &metav1.Status{
Reason: ERR_SUBNET_NOT_SPECIFIED,
}
return &admissionResponse
if "" == logicalNetwork.Spec.SubSubnet {
admissionResponse.Result = &metav1.Status{
Reason: ERR_SUBNET_NOT_SPECIFIED,
}
return &admissionResponse

}

Expand All @@ -224,13 +222,12 @@ func validateNetworkParas(logicalNetwork *genieUtils.LogicalNetwork) *v1beta1.Ad
/* Check whether the subnet is already part of any other logical network*/
if nil != PluginSubnetUsageDataList {
for i := range PluginSubnetUsageDataList {
if PluginSubnetUsageDataList[i].PluginName == selectedPluginName {
if PluginSubnetUsageDataList[i].PluginName == selectedPluginName {
isPluginFound = true
pluginSubnetUsageData = PluginSubnetUsageDataList[i]
break
break
}


}
}

Expand Down
2 changes: 1 addition & 1 deletion networkcrd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ type NetworkStatus struct {
Mac string `json:"mac,omitempty"`
Default bool `json:"default,omitempty"`
DNS types.DNS `json:"dns,omitempty"`
}
}
2 changes: 1 addition & 1 deletion utils/logicalnetwork.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ func (in *LogicalNetworkList) DeepCopyObject() runtime.Object {
return c
}
return nil
}
}

0 comments on commit eb3d316

Please sign in to comment.