mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-10-22 07:52:12 +00:00
k8sclient: Network -> NetworkAttachmentDefinition
To align with latest spec change clarifying the name of the CRD object.
This commit is contained in:
committed by
Kuralamudhan Ramakrishnan
parent
c8fbcf3358
commit
4f8c285520
33
README.md
33
README.md
@@ -90,25 +90,24 @@ Multus is compatible to work with both CRD and TPR(deprecated in K8s 1.7).
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
# name must match the spec fields below, and be in the form: <plural>.<group>
|
||||
name: networks.kubernetes.cni.cncf.io
|
||||
name: network-attachment-definitions.kubernetes.cni.cncf.io
|
||||
spec:
|
||||
# group name to use for REST API: /apis/<group>/<version>
|
||||
group: kubernetes.cni.cncf.io
|
||||
# version name to use for REST API: /apis/<group>/<version>
|
||||
version: v1
|
||||
# either Namespaced or Cluster
|
||||
scope: Namespaced
|
||||
names:
|
||||
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
|
||||
plural: networks
|
||||
# singular name to be used as an alias on the CLI and for display
|
||||
singular: network
|
||||
# kind is normally the CamelCased singular type. Your resource manifests use this.
|
||||
kind: Network
|
||||
# shortNames allow shorter string to match your resource on the CLI
|
||||
plural: network-attachment-definitions
|
||||
singular: network-attachment-definition
|
||||
kind: NetworkAttachmentDefinition
|
||||
shortNames:
|
||||
- net
|
||||
- net-attach-def
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
spec:
|
||||
properties:
|
||||
config:
|
||||
type: string
|
||||
```
|
||||
2. Run kubectl create command for the Custom Resource Definition
|
||||
```
|
||||
@@ -162,7 +161,7 @@ network.kubernetes.cni.cncf.io A specification of a Network obj in the kuberne
|
||||
|
||||
```
|
||||
apiVersion: "kubernetes.cni.cncf.io/v1"
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
name: flannel-networkobj
|
||||
spec:
|
||||
@@ -189,7 +188,7 @@ flannel-networkobj 26s
|
||||
4. Get the custom network object details
|
||||
```
|
||||
apiVersion: kubernetes.cni.cncf.io/v1
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
clusterName: ""
|
||||
creationTimestamp: 2018-05-17T09:13:20Z
|
||||
@@ -208,7 +207,7 @@ spec:
|
||||
5. Save the following YAML to sriov-network.yaml to creating sriov network object. ( Refer to [Intel - SR-IOV CNI](https://github.com/Intel-Corp/sriov-cni) or contact @kural in [Intel-Corp Slack](https://intel-corp.herokuapp.com/) for running the DPDK based workloads in Kubernetes)
|
||||
```
|
||||
apiVersion: "kubernetes.cni.cncf.io/v1"
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
name: sriov-conf
|
||||
spec:
|
||||
@@ -231,7 +230,7 @@ spec:
|
||||
|
||||
```
|
||||
apiVersion: "kubernetes.cni.cncf.io/v1"
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
name: sriov-vlanid-l2enable-conf
|
||||
spec:
|
||||
|
@@ -1,22 +1,21 @@
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
# name must match the spec fields below, and be in the form: <plural>.<group>
|
||||
name: networks.kubernetes.cni.cncf.io
|
||||
name: network-attachment-definitions.kubernetes.cni.cncf.io
|
||||
spec:
|
||||
# group name to use for REST API: /apis/<group>/<version>
|
||||
group: kubernetes.cni.cncf.io
|
||||
# version name to use for REST API: /apis/<group>/<version>
|
||||
version: v1
|
||||
# either Namespaced or Cluster
|
||||
scope: Namespaced
|
||||
names:
|
||||
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
|
||||
plural: networks
|
||||
# singular name to be used as an alias on the CLI and for display
|
||||
singular: network
|
||||
# kind is normally the CamelCased singular type. Your resource manifests use this.
|
||||
kind: Network
|
||||
# shortNames allow shorter string to match your resource on the CLI
|
||||
plural: network-attachment-definitions
|
||||
singular: network-attachment-definition
|
||||
kind: NetworkAttachmentDefinition
|
||||
shortNames:
|
||||
- net
|
||||
- net-attach-def
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
spec:
|
||||
properties:
|
||||
config:
|
||||
type: string
|
||||
|
@@ -1,5 +1,5 @@
|
||||
apiVersion: "kubernetes.cni.cncf.io/v1"
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
name: flannel-conf
|
||||
spec:
|
||||
|
@@ -1,5 +1,5 @@
|
||||
apiVersion: "kubernetes.cni.cncf.io/v1"
|
||||
kind: Network
|
||||
kind: NetworkAttachmentDefinition
|
||||
metadata:
|
||||
name: macvlan-conf
|
||||
spec:
|
||||
|
@@ -229,7 +229,7 @@ func getConfig(config string, ifname string) string {
|
||||
|
||||
}
|
||||
|
||||
func getNetSpec(ns types.NetworkSpec, name string, ifname string) (string, error) {
|
||||
func getNetSpec(ns types.NetworkAttachmentDefinitionSpec, name string, ifname string) (string, error) {
|
||||
|
||||
if ns.Plugin == "" && ns.Config == "" {
|
||||
return "", fmt.Errorf("Network Object spec plugin and config can't be empty")
|
||||
@@ -259,11 +259,11 @@ func getNetSpec(ns types.NetworkSpec, name string, ifname string) (string, error
|
||||
|
||||
}
|
||||
|
||||
func cniConfigFromNetworkResource(customResource *types.Network, net *types.NetworkSelectionElement, confdir string) (string, error) {
|
||||
func cniConfigFromNetworkResource(customResource *types.NetworkAttachmentDefinition, net *types.NetworkSelectionElement, confdir string) (string, error) {
|
||||
var config string
|
||||
var err error
|
||||
|
||||
if (types.NetworkSpec{}) == customResource.Spec {
|
||||
if (types.NetworkAttachmentDefinitionSpec{}) == customResource.Spec {
|
||||
// Network Spec empty; generate delegate from CNI JSON config
|
||||
// from the configuration directory that has the same network
|
||||
// name as the custom resource
|
||||
@@ -284,13 +284,13 @@ func cniConfigFromNetworkResource(customResource *types.Network, net *types.Netw
|
||||
}
|
||||
|
||||
func getKubernetesDelegate(client KubeClient, net *types.NetworkSelectionElement, confdir string) (*types.DelegateNetConf, error) {
|
||||
rawPath := fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/networks/%s", net.Namespace, net.Name)
|
||||
rawPath := fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/network-attachment-definitions/%s", net.Namespace, net.Name)
|
||||
netData, err := client.GetRawWithPath(rawPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getKubernetesDelegate: failed to get network resource, refer Multus README.md for the usage guide: %v", err)
|
||||
}
|
||||
|
||||
customResource := &types.Network{}
|
||||
customResource := &types.NetworkAttachmentDefinition{}
|
||||
if err := json.Unmarshal(netData, customResource); err != nil {
|
||||
return nil, fmt.Errorf("getKubernetesDelegate: failed to get the netplugin data: %v", err)
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ func (f *FakeKubeClient) AddNetConfig(namespace, name, data string) {
|
||||
}`, namespace, name, strings.Replace(data, "\"", "\\\"", -1))
|
||||
cr = strings.Replace(cr, "\n", "", -1)
|
||||
cr = strings.Replace(cr, "\t", "", -1)
|
||||
f.nets[fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/networks/%s", namespace, name)] = cr
|
||||
f.nets[fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/network-attachment-definitions/%s", namespace, name)] = cr
|
||||
}
|
||||
|
||||
func (f *FakeKubeClient) AddNetFile(namespace, name, filePath, fileData string) {
|
||||
@@ -76,7 +76,7 @@ func (f *FakeKubeClient) AddNetFile(namespace, name, filePath, fileData string)
|
||||
"name": "%s"
|
||||
}
|
||||
}`, namespace, name)
|
||||
f.nets[fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/networks/%s", namespace, name)] = cr
|
||||
f.nets[fmt.Sprintf("/apis/kubernetes.cni.cncf.io/v1/namespaces/%s/network-attachment-definitions/%s", namespace, name)] = cr
|
||||
|
||||
err := ioutil.WriteFile(filePath, []byte(fileData), 0600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@@ -52,7 +52,7 @@ type DelegateNetConf struct {
|
||||
Bytes []byte
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
type NetworkAttachmentDefinition struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
// Note that ObjectMeta is mandatory, as an object
|
||||
// name is required
|
||||
@@ -65,10 +65,10 @@ type Network struct {
|
||||
// or .config (in that order) file on-disk whose JSON
|
||||
// “name” key matches this Network object’s name.
|
||||
// +optional
|
||||
Spec NetworkSpec `json:"spec"`
|
||||
Spec NetworkAttachmentDefinitionSpec `json:"spec"`
|
||||
}
|
||||
|
||||
type NetworkSpec struct {
|
||||
type NetworkAttachmentDefinitionSpec struct {
|
||||
// Config contains a standard JSON-encoded CNI configuration
|
||||
// or configuration list which defines the plugin chain to
|
||||
// execute. If present, this key takes precedence over
|
||||
|
Reference in New Issue
Block a user