mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-10 13:22:14 +00:00
adding type package in multus
This commit is contained in:
committed by
Kuralamudhan Ramakrishnan
parent
5cb6c38786
commit
122dbfb345
@@ -23,7 +23,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -34,7 +33,8 @@ import (
|
|||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||||
|
"github.com/Intel-Corp/multus-cni/types"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,30 +43,6 @@ const defaultCNIDir = "/var/lib/cni/multus"
|
|||||||
var masterpluginEnabled bool
|
var masterpluginEnabled bool
|
||||||
var defaultcninetwork bool
|
var defaultcninetwork bool
|
||||||
|
|
||||||
// NetConf for cni config file written in json
|
|
||||||
type NetConf struct {
|
|
||||||
types.NetConf
|
|
||||||
CNIDir string `json:"cniDir"`
|
|
||||||
Delegates []map[string]interface{} `json:"delegates"`
|
|
||||||
Kubeconfig string `json:"kubeconfig"`
|
|
||||||
UseDefault bool `json:"always_use_default"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type netplugin struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty" description:"standard object metadata"`
|
|
||||||
Plugin string `json:"plugin"`
|
|
||||||
Args string `json:"args"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// K8sArgs is the valid CNI_ARGS used for Kubernetes
|
|
||||||
type K8sArgs struct {
|
|
||||||
types.CommonArgs
|
|
||||||
IP net.IP
|
|
||||||
K8S_POD_NAME types.UnmarshallableString
|
|
||||||
K8S_POD_NAMESPACE types.UnmarshallableString
|
|
||||||
K8S_POD_INFRA_CONTAINER_ID types.UnmarshallableString
|
|
||||||
}
|
|
||||||
|
|
||||||
//taken from cni/plugins/meta/flannel/flannel.go
|
//taken from cni/plugins/meta/flannel/flannel.go
|
||||||
func isString(i interface{}) bool {
|
func isString(i interface{}) bool {
|
||||||
@@ -79,8 +55,8 @@ func isBool(i interface{}) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadNetConf(bytes []byte) (*NetConf, error) {
|
func loadNetConf(bytes []byte) (*types.NetConf, error) {
|
||||||
netconf := &NetConf{}
|
netconf := &types.NetConf{}
|
||||||
if err := json.Unmarshal(bytes, netconf); err != nil {
|
if err := json.Unmarshal(bytes, netconf); err != nil {
|
||||||
return nil, fmt.Errorf("failed to load netconf: %v", err)
|
return nil, fmt.Errorf("failed to load netconf: %v", err)
|
||||||
}
|
}
|
||||||
@@ -290,7 +266,7 @@ func createK8sClient(kubeconfig string) (*kubernetes.Clientset, error) {
|
|||||||
return kubernetes.NewForConfig(config)
|
return kubernetes.NewForConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPodNetworkAnnotation(client *kubernetes.Clientset, k8sArgs K8sArgs) (string, error) {
|
func getPodNetworkAnnotation(client *kubernetes.Clientset, k8sArgs types.K8sArgs) (string, error) {
|
||||||
var annot string
|
var annot string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -414,7 +390,7 @@ func getnetplugin(client *kubernetes.Clientset, networkinfo map[string]interface
|
|||||||
return "", fmt.Errorf("getnetplugin: failed to get CRD (result: %s), refer Multus README.md for the usage guide: %v", netobjdata, err)
|
return "", fmt.Errorf("getnetplugin: failed to get CRD (result: %s), refer Multus README.md for the usage guide: %v", netobjdata, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
np := netplugin{}
|
np := types.Netplugin{}
|
||||||
if err := json.Unmarshal(netobjdata, &np); err != nil {
|
if err := json.Unmarshal(netobjdata, &np); err != nil {
|
||||||
return "", fmt.Errorf("getnetplugin: failed to get the netplugin data: %v", err)
|
return "", fmt.Errorf("getnetplugin: failed to get the netplugin data: %v", err)
|
||||||
}
|
}
|
||||||
@@ -464,7 +440,7 @@ func getPodNetworkObj(client *kubernetes.Clientset, netObjs []map[string]interfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMultusDelegates(delegate string) ([]map[string]interface{}, error) {
|
func getMultusDelegates(delegate string) ([]map[string]interface{}, error) {
|
||||||
tmpNetconf := &NetConf{}
|
tmpNetconf := &types.NetConf{}
|
||||||
tmpDelegate := "{\"delegates\": " + delegate + "}"
|
tmpDelegate := "{\"delegates\": " + delegate + "}"
|
||||||
|
|
||||||
if delegate == "" {
|
if delegate == "" {
|
||||||
@@ -488,10 +464,10 @@ type NoK8sNetworkError string
|
|||||||
func (e NoK8sNetworkError) Error() string { return string(e) }
|
func (e NoK8sNetworkError) Error() string { return string(e) }
|
||||||
|
|
||||||
func getK8sNetwork(args *skel.CmdArgs, kubeconfig string) ([]map[string]interface{}, error) {
|
func getK8sNetwork(args *skel.CmdArgs, kubeconfig string) ([]map[string]interface{}, error) {
|
||||||
k8sArgs := K8sArgs{}
|
k8sArgs := types.K8sArgs{}
|
||||||
var podNet []map[string]interface{}
|
var podNet []map[string]interface{}
|
||||||
|
|
||||||
err := types.LoadArgs(args.Args, &k8sArgs)
|
err := cnitypes.LoadArgs(args.Args, &k8sArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return podNet, err
|
return podNet, err
|
||||||
}
|
}
|
||||||
|
49
types/types.go
Normal file
49
types/types.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (c) 2017 Intel Corporation
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NetConf for cni config file written in json
|
||||||
|
type NetConf struct {
|
||||||
|
types.NetConf
|
||||||
|
CNIDir string `json:"cniDir"`
|
||||||
|
Delegates []map[string]interface{} `json:"delegates"`
|
||||||
|
Kubeconfig string `json:"kubeconfig"`
|
||||||
|
UseDefault bool `json:"always_use_default"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Netplugin struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata,omitempty" description:"standard object metadata"`
|
||||||
|
Plugin string `json:"plugin"`
|
||||||
|
Args string `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// K8sArgs is the valid CNI_ARGS used for Kubernetes
|
||||||
|
type K8sArgs struct {
|
||||||
|
types.CommonArgs
|
||||||
|
IP net.IP
|
||||||
|
K8S_POD_NAME types.UnmarshallableString
|
||||||
|
K8S_POD_NAMESPACE types.UnmarshallableString
|
||||||
|
K8S_POD_INFRA_CONTAINER_ID types.UnmarshallableString
|
||||||
|
}
|
Reference in New Issue
Block a user