k8sclient: Network -> NetworkAttachmentDefinition

To align with latest spec change clarifying the name of the CRD object.
This commit is contained in:
Dan Williams
2018-07-12 08:42:56 -05:00
committed by Kuralamudhan Ramakrishnan
parent c8fbcf3358
commit 4f8c285520
7 changed files with 42 additions and 44 deletions

View File

@@ -90,25 +90,24 @@ Multus is compatible to work with both CRD and TPR(deprecated in K8s 1.7).
apiVersion: apiextensions.k8s.io/v1beta1 apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition kind: CustomResourceDefinition
metadata: metadata:
# name must match the spec fields below, and be in the form: <plural>.<group> name: network-attachment-definitions.kubernetes.cni.cncf.io
name: networks.kubernetes.cni.cncf.io
spec: spec:
# group name to use for REST API: /apis/<group>/<version>
group: kubernetes.cni.cncf.io group: kubernetes.cni.cncf.io
# version name to use for REST API: /apis/<group>/<version>
version: v1 version: v1
# either Namespaced or Cluster
scope: Namespaced scope: Namespaced
names: names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural> plural: network-attachment-definitions
plural: networks singular: network-attachment-definition
# singular name to be used as an alias on the CLI and for display kind: NetworkAttachmentDefinition
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
shortNames: shortNames:
- net - net-attach-def
validation:
openAPIV3Schema:
properties:
spec:
properties:
config:
type: string
``` ```
2. Run kubectl create command for the Custom Resource Definition 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" apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
name: flannel-networkobj name: flannel-networkobj
spec: spec:
@@ -189,7 +188,7 @@ flannel-networkobj 26s
4. Get the custom network object details 4. Get the custom network object details
``` ```
apiVersion: kubernetes.cni.cncf.io/v1 apiVersion: kubernetes.cni.cncf.io/v1
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
clusterName: "" clusterName: ""
creationTimestamp: 2018-05-17T09:13:20Z 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) 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" apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
name: sriov-conf name: sriov-conf
spec: spec:
@@ -231,7 +230,7 @@ spec:
``` ```
apiVersion: "kubernetes.cni.cncf.io/v1" apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
name: sriov-vlanid-l2enable-conf name: sriov-vlanid-l2enable-conf
spec: spec:

View File

@@ -1,22 +1,21 @@
apiVersion: apiextensions.k8s.io/v1beta1 apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition kind: CustomResourceDefinition
metadata: metadata:
# name must match the spec fields below, and be in the form: <plural>.<group> name: network-attachment-definitions.kubernetes.cni.cncf.io
name: networks.kubernetes.cni.cncf.io
spec: spec:
# group name to use for REST API: /apis/<group>/<version>
group: kubernetes.cni.cncf.io group: kubernetes.cni.cncf.io
# version name to use for REST API: /apis/<group>/<version>
version: v1 version: v1
# either Namespaced or Cluster
scope: Namespaced scope: Namespaced
names: names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural> plural: network-attachment-definitions
plural: networks singular: network-attachment-definition
# singular name to be used as an alias on the CLI and for display kind: NetworkAttachmentDefinition
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
shortNames: shortNames:
- net - net-attach-def
validation:
openAPIV3Schema:
properties:
spec:
properties:
config:
type: string

View File

@@ -1,5 +1,5 @@
apiVersion: "kubernetes.cni.cncf.io/v1" apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
name: flannel-conf name: flannel-conf
spec: spec:

View File

@@ -1,5 +1,5 @@
apiVersion: "kubernetes.cni.cncf.io/v1" apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network kind: NetworkAttachmentDefinition
metadata: metadata:
name: macvlan-conf name: macvlan-conf
spec: spec:

View File

@@ -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 == "" { if ns.Plugin == "" && ns.Config == "" {
return "", fmt.Errorf("Network Object spec plugin and config can't be empty") 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 config string
var err error var err error
if (types.NetworkSpec{}) == customResource.Spec { if (types.NetworkAttachmentDefinitionSpec{}) == customResource.Spec {
// Network Spec empty; generate delegate from CNI JSON config // Network Spec empty; generate delegate from CNI JSON config
// from the configuration directory that has the same network // from the configuration directory that has the same network
// name as the custom resource // 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) { 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) netData, err := client.GetRawWithPath(rawPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("getKubernetesDelegate: failed to get network resource, refer Multus README.md for the usage guide: %v", err) 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 { if err := json.Unmarshal(netData, customResource); err != nil {
return nil, fmt.Errorf("getKubernetesDelegate: failed to get the netplugin data: %v", err) return nil, fmt.Errorf("getKubernetesDelegate: failed to get the netplugin data: %v", err)
} }

View File

@@ -64,7 +64,7 @@ func (f *FakeKubeClient) AddNetConfig(namespace, name, data string) {
}`, namespace, name, strings.Replace(data, "\"", "\\\"", -1)) }`, namespace, name, strings.Replace(data, "\"", "\\\"", -1))
cr = strings.Replace(cr, "\n", "", -1) cr = strings.Replace(cr, "\n", "", -1)
cr = strings.Replace(cr, "\t", "", -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) { func (f *FakeKubeClient) AddNetFile(namespace, name, filePath, fileData string) {
@@ -76,7 +76,7 @@ func (f *FakeKubeClient) AddNetFile(namespace, name, filePath, fileData string)
"name": "%s" "name": "%s"
} }
}`, namespace, name) }`, 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) err := ioutil.WriteFile(filePath, []byte(fileData), 0600)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@@ -52,7 +52,7 @@ type DelegateNetConf struct {
Bytes []byte Bytes []byte
} }
type Network struct { type NetworkAttachmentDefinition struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
// Note that ObjectMeta is mandatory, as an object // Note that ObjectMeta is mandatory, as an object
// name is required // name is required
@@ -65,10 +65,10 @@ type Network struct {
// or .config (in that order) file on-disk whose JSON // or .config (in that order) file on-disk whose JSON
// “name” key matches this Network objects name. // “name” key matches this Network objects name.
// +optional // +optional
Spec NetworkSpec `json:"spec"` Spec NetworkAttachmentDefinitionSpec `json:"spec"`
} }
type NetworkSpec struct { type NetworkAttachmentDefinitionSpec struct {
// Config contains a standard JSON-encoded CNI configuration // Config contains a standard JSON-encoded CNI configuration
// or configuration list which defines the plugin chain to // or configuration list which defines the plugin chain to
// execute. If present, this key takes precedence over // execute. If present, this key takes precedence over