Skip to content

Commit

Permalink
chore: fix go-report golint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Apr 22, 2019
1 parent be65181 commit bc66671
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 119 deletions.
6 changes: 3 additions & 3 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func cmdDel(args *skel.CmdArgs) error {
NetNs: args.Netns})
}

type NetConf struct {
type netConf struct {
types.NetConf
ServerSocket string `json:"server_socket"`
}

func loadNetConf(bytes []byte) (*NetConf, string, error) {
n := &NetConf{}
func loadNetConf(bytes []byte) (*netConf, string, error) {
n := &netConf{}
if err := json.Unmarshal(bytes, n); err != nil {
return nil, "", fmt.Errorf("failed to load netconf: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func startOvnNbctlDaemon(nbHost string, nbPort int) (string, error) {
if err != nil {
klog.Errorf("start ovn-nbctl daemon failed, %s", string(output))
return "", err
} else {
daemonSocket := strings.TrimSpace(string(output))
os.Setenv("OVN_NB_DAEMON", daemonSocket)
return daemonSocket, nil
}

daemonSocket := strings.TrimSpace(string(output))
os.Setenv("OVN_NB_DAEMON", daemonSocket)
return daemonSocket, nil
}
2 changes: 2 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/klog"
)

// Configuration is the controller conf
type Configuration struct {
BindAddress string
OvnNbSocket string
Expand All @@ -36,6 +37,7 @@ type Configuration struct {
PodNamespace string
}

// ParseFlags parses cmd args then init kubeclient and conf
// TODO: validate configuration
func ParseFlags() (*Configuration, error) {
var (
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

const controllerAgentName = "ovn-controller"

// Controller is kube-ovn main controller that watch ns/pod/node/svc/ep and operate ovn
type Controller struct {
config *Configuration
ovnClient *ovs.Client
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/klog"
)

// InitDefaultLogicalSwitch int the default logical switch for ovn network
func InitDefaultLogicalSwitch(config *Configuration) error {
namespace := os.Getenv("KUBE_NAMESPACE")
if namespace == "" {
Expand Down Expand Up @@ -49,6 +50,7 @@ func InitDefaultLogicalSwitch(config *Configuration) error {
return err
}

// InitNodeSwitch init node switch to connect host and pod
func InitNodeSwitch(config *Configuration) error {
client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR)
ss, err := client.ListLogicalSwitch()
Expand All @@ -69,6 +71,7 @@ func InitNodeSwitch(config *Configuration) error {
return nil
}

// InitClusterRouter init cluster router to connect different logical switches
func InitClusterRouter(config *Configuration) error {
client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR)
lrs, err := client.ListLogicalRouter()
Expand All @@ -84,6 +87,7 @@ func InitClusterRouter(config *Configuration) error {
return client.CreateLogicalRouter(config.ClusterRouter)
}

// InitLoadBalancer init the default tcp and udp cluster loadbalancer
func InitLoadBalancer(config *Configuration) error {
client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR)
tcpLb, err := client.FindLoadbalancer(config.ClusterTcpLoadBalancer)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ func (c *Controller) handleAddNamespace(key string) error {

if private == "true" {
return c.ovnClient.SetPrivateLogicalSwitch(ls, strings.Split(allow, ","))
} else {
return c.ovnClient.CleanLogicalSwitchAcl(ls)
}

return c.ovnClient.CleanLogicalSwitchAcl(ls)
}

func (c *Controller) handleDeleteNamespace(key string) error {
Expand Down Expand Up @@ -281,7 +281,7 @@ func (c *Controller) handleUpdateNamespace(key string) error {
allow := ns.Annotations[util.AllowAccessAnnotation]
if private != "true" {
return c.ovnClient.CleanLogicalSwitchAcl(ls)
} else {
return c.ovnClient.SetPrivateLogicalSwitch(ls, strings.Split(allow, ","))
}

return c.ovnClient.SetPrivateLogicalSwitch(ls, strings.Split(allow, ","))
}
2 changes: 2 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/klog"
)

// Configuration is the daemon conf
type Configuration struct {
BindSocket string
OvsSocket string
Expand All @@ -21,6 +22,7 @@ type Configuration struct {
ServiceClusterIPRange string
}

// ParseFlags will parse cmd args then init kubeClient and configuration
// TODO: validate configuration
func ParseFlags() (*Configuration, error) {
var (
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/klog"
)

// Controller watch pod and namespace changes to update iptables, ipset and ovs qos
type Controller struct {
config *Configuration
kubeclientset kubernetes.Interface
Expand All @@ -41,6 +42,7 @@ type Controller struct {
iptablesMgr *iptables.IPTables
}

// NewController init a daemon controller
func NewController(config *Configuration, informerFactory informers.SharedInformerFactory) (*Controller, error) {
namespaceInformer := informerFactory.Core().V1().Namespaces()
podInformer := informerFactory.Core().V1().Pods()
Expand Down Expand Up @@ -302,6 +304,7 @@ func (c *Controller) handlePod(key string) error {
return ovs.SetPodBandwidth(pod.Name, pod.Namespace, pod.Annotations[util.IngressRateAnnotation], pod.Annotations[util.EgressRateAnnotation])
}

// Run starts controller
func (c *Controller) Run(stopCh <-chan struct{}) error {
defer utilruntime.HandleCrash()
defer c.namespaceQueue.ShutDown()
Expand Down
10 changes: 5 additions & 5 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"time"
)

type CniServerHandler struct {
type cniServerHandler struct {
Config *Configuration
KubeClient kubernetes.Interface
}

func createCniServerHandler(config *Configuration) *CniServerHandler {
csh := &CniServerHandler{KubeClient: config.KubeClient, Config: config}
func createCniServerHandler(config *Configuration) *cniServerHandler {
csh := &cniServerHandler{KubeClient: config.KubeClient, Config: config}
return csh
}

func (csh CniServerHandler) handleAdd(req *restful.Request, resp *restful.Response) {
func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Response) {
podRequest := request.PodRequest{}
err := req.ReadEntity(&podRequest)
if err != nil {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (csh CniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
resp.WriteHeaderAndEntity(http.StatusOK, request.PodResponse{IpAddress: strings.Split(ipAddr, "/")[0], MacAddress: macAddr, CIDR: cidr, Gateway: gw})
}

func (csh CniServerHandler) handleDel(req *restful.Request, resp *restful.Response) {
func (csh cniServerHandler) handleDel(req *restful.Request, resp *restful.Response) {
podRequest := request.PodRequest{}
err := req.ReadEntity(&podRequest)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"k8s.io/klog"
)

// InitNodeGateway init ovn0
func InitNodeGateway(config *Configuration) error {
nodeName := config.NodeName
node, err := config.KubeClient.CoreV1().Nodes().Get(nodeName, v1.GetOptions{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os/exec"
)

func (csh CniServerHandler) configureNic(podName, podNamespace, netns, containerID, mac, ip, gateway, ingress, egress string) error {
func (csh cniServerHandler) configureNic(podName, podNamespace, netns, containerID, mac, ip, gateway, ingress, egress string) error {
var err error
hostNicName, containerNicName := generateNicName(containerID)
// Create a veth pair, put one end to container ,the other to ovs port
Expand Down Expand Up @@ -66,7 +66,7 @@ func (csh CniServerHandler) configureNic(podName, podNamespace, netns, container
return nil
}

func (csh CniServerHandler) deleteNic(netns, podName, podNamespace, containerID string) error {
func (csh cniServerHandler) deleteNic(netns, podName, podNamespace, containerID string) error {
hostNicName, _ := generateNicName(containerID)
// Remove ovs port
output, err := exec.Command("ovs-vsctl", "--if-exists", "--with-iface", "del-port", "br-int", hostNicName).CombinedOutput()
Expand Down
11 changes: 6 additions & 5 deletions pkg/daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"time"
)

var RequestLogString = "[%s] Incoming %s %s %s request"
var ResponseLogString = "[%s] Outcoming response %s %s with %d status code in %vms"
var requestLogString = "[%s] Incoming %s %s %s request"
var responseLogString = "[%s] Outcoming response %s %s with %d status code in %vms"

// RunServer runs the cniserver
func RunServer(config *Configuration) {
csh := createCniServerHandler(config)
server := http.Server{
Expand All @@ -29,7 +30,7 @@ func RunServer(config *Configuration) {
klog.Fatal(server.Serve(unixListener))
}

func createHandler(csh *CniServerHandler) http.Handler {
func createHandler(csh *cniServerHandler) http.Handler {
wsContainer := restful.NewContainer()
wsContainer.EnableContentEncoding(true)

Expand Down Expand Up @@ -70,7 +71,7 @@ func formatRequestLog(request *restful.Request) string {
uri = request.Request.URL.RequestURI()
}

return fmt.Sprintf(RequestLogString, time.Now().Format(time.RFC3339), request.Request.Proto,
return fmt.Sprintf(requestLogString, time.Now().Format(time.RFC3339), request.Request.Proto,
request.Request.Method, uri)
}

Expand All @@ -80,6 +81,6 @@ func formatResponseLog(response *restful.Response, request *restful.Request, req
if request.Request.URL != nil {
uri = request.Request.URL.RequestURI()
}
return fmt.Sprintf(ResponseLogString, time.Now().Format(time.RFC3339),
return fmt.Sprintf(responseLogString, time.Now().Format(time.RFC3339),
request.Request.Method, uri, response.StatusCode(), reqTime)
}

0 comments on commit bc66671

Please sign in to comment.