Skip to content

Commit

Permalink
Deploy hard-coded configmap and SR-IOV Device Plugin daemonset
Browse files Browse the repository at this point in the history
NOTE: temporary added "//nolint:dupl" to test functionality.

Signed-off-by: Ivan Kolodiazhnyi <ikolodiazhny@nvidia.com>
  • Loading branch information
e0ne committed Mar 2, 2021
1 parent fee44f2 commit 4ddc2d2
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 46 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/hostdevicenetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type HostDeviceNetwork struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec HostDeviceNetworkSpec `json:"spec,omitempty"`
Spec *HostDeviceNetworkSpec `json:"spec,omitempty"`
Status HostDeviceNetworkStatus `json:"status,omitempty"`
}

Expand Down
11 changes: 5 additions & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions manifests/stage-hostdevice-network/0010-hostdevice-net-cr.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: {{.NetworkName}}
namespace: {{.NetworkNamespace}}
name: {{.HostDeviceNetworkName}}
namespace: {{.CrSpec.NetworkNamespace}}
spec:
config: '{
"cniVersion":"0.4.0",
"name":"{{.NetworkName}}",
"name":"{{.HostDeviceNetworkName}}",
"type":"host-devive",
{{- if .pciBusID -}}
"pciBusID": "{{.pciBusID}}",
{{- end -}}
{{.Ipam}}
#if .CrSpec.pciBusID}
"pciBusID": "3b:00.0",
# end
{{.CrSpec.IPAM}}
}'
19 changes: 19 additions & 0 deletions manifests/stage-hostdevice-network/0020-sriov-dp-configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sriovdp-config
namespace: {{ .RuntimeSpec.Namespace }}
data:
config.json: |
{
"resourceList": [
{
"resourcePrefix": "nvidia.com",
"resourceName": "mlnx_sriov_rdma",
"selectors": {
"vendors": ["15b3"],
"isRdma": true
}
}
]
}
71 changes: 71 additions & 0 deletions manifests/stage-hostdevice-network/0030-sriov-dp-daemonset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sriov-device-plugin
namespace: {{ .RuntimeSpec.Namespace }}

---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: sriov-device-plugin
namespace: {{ .RuntimeSpec.Namespace }}
labels:
tier: node
app: sriovdp
spec:
selector:
matchLabels:
name: sriov-device-plugin
template:
metadata:
labels:
name: sriov-device-plugin
tier: node
app: sriovdp
spec:
hostNetwork: true
nodeSelector:
beta.kubernetes.io/arch: amd64
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
serviceAccountName: sriov-device-plugin
containers:
- name: kube-sriovdp
image: docker.io/nfvpe/sriov-device-plugin:v3.3
imagePullPolicy: IfNotPresent
args:
- --log-dir=sriovdp
- --log-level=10
securityContext:
privileged: true
volumeMounts:
- name: devicesock
mountPath: /var/lib/kubelet/
readOnly: false
- name: log
mountPath: /var/log
- name: config-volume
mountPath: /etc/pcidp
- name: device-info
mountPath: /var/run/k8s.cni.cncf.io/devinfo/dp
volumes:
- name: devicesock
hostPath:
path: /var/lib/kubelet/
- name: log
hostPath:
path: /var/log
- name: device-info
hostPath:
path: /var/run/k8s.cni.cncf.io/devinfo/dp
type: DirectoryOrCreate
- name: config-volume
configMap:
name: sriovdp-config
items:
- key: config.json
path: config.json
2 changes: 1 addition & 1 deletion pkg/state/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func newHostDeviceNetworkStates(k8sAPIClient client.Client, scheme *runtime.Sche
hostdeviceNetworkState, err := NewStateHostDeviceNetwork(
k8sAPIClient, scheme, filepath.Join(manifestBaseDir, "stage-hostdevice-network"))
if err != nil {
return nil, errors.Wrapf(err, "failed to create MacvlanNetwork CRD State")
return nil, errors.Wrapf(err, "failed to create HostDeviceNetwork CRD State")
}
return []Group{
NewStateGroup([]State{hostdeviceNetworkState}),
Expand Down
35 changes: 15 additions & 20 deletions pkg/state/state_hostdevice_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package state
package state //nolint:dupl

import (
"strings"

netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -60,6 +58,12 @@ type stateHostDeviceNetwork struct {
stateSkel
}

type HostDeviceManifestRenderData struct {
HostDeviceNetworkName string
CrSpec *mellanoxv1alpha1.HostDeviceNetworkSpec
RuntimeSpec *runtimeSpec
}

// Sync attempt to get the system to match the desired state which State represent.
// a sync operation must be relatively short and must not block the execution thread.
func (s *stateHostDeviceNetwork) Sync(customResource interface{}, _ InfoCatalog) (SyncState, error) {
Expand Down Expand Up @@ -118,26 +122,17 @@ func (s *stateHostDeviceNetwork) GetWatchSources() map[string]*source.Kind {

func (s *stateHostDeviceNetwork) getManifestObjects(
cr *mellanoxv1alpha1.HostDeviceNetwork) ([]*unstructured.Unstructured, error) {
data := map[string]interface{}{}
data["NetworkName"] = cr.Name
if cr.Spec.NetworkNamespace == "" {
data["NetworkNamespace"] = "default"
} else {
data["NetworkNamespace"] = cr.Spec.NetworkNamespace
}

data["sriovdp-configmap"] = cr.Spec.SriovDevicePluginConfigmap
data["pciBusID"] = cr.Spec.PciBusID

if cr.Spec.IPAM != "" {
data["Ipam"] = "\"ipam\":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
} else {
data["Ipam"] = "\"ipam\":{}"
renderData := &HostDeviceManifestRenderData{
HostDeviceNetworkName: cr.Name,
CrSpec: cr.Spec,
RuntimeSpec: &runtimeSpec{
Namespace: consts.NetworkOperatorResourceNamespace,
},
}

// render objects
log.V(consts.LogLevelDebug).Info("Rendering objects", "data:", data)
objs, err := s.renderer.RenderObjects(&render.TemplatingData{Data: data})
log.V(consts.LogLevelDebug).Info("Rendering objects", "data:", renderData)
objs, err := s.renderer.RenderObjects(&render.TemplatingData{Data: renderData})
if err != nil {
return nil, errors.Wrap(err, "failed to render objects")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/state_macvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package state
package state //nolint:dupl

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/state_multus_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package state
package state //nolint:dupl

import (
"github.com/pkg/errors"
Expand Down
10 changes: 3 additions & 7 deletions pkg/state/state_whereabouts_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package state
package state //nolint:dupl

import (
"github.com/pkg/errors"
Expand Down Expand Up @@ -53,13 +53,9 @@ type stateWhereaboutsCNI struct {
stateSkel
}

type WhereaboutsRuntimeSpec struct {
Namespace string
}

type WhereaboutsManifestRenderData struct {
CrSpec *mellanoxv1alpha1.ImageSpec
RuntimeSpec *WhereaboutsRuntimeSpec
RuntimeSpec *runtimeSpec
}

// Sync attempt to get the system to match the desired state which State represent.
Expand Down Expand Up @@ -115,7 +111,7 @@ func (s *stateWhereaboutsCNI) getManifestObjects(
cr *mellanoxv1alpha1.NicClusterPolicy) ([]*unstructured.Unstructured, error) {
renderData := &WhereaboutsManifestRenderData{
CrSpec: cr.Spec.SecondaryNetwork.IpamPlugin,
RuntimeSpec: &WhereaboutsRuntimeSpec{
RuntimeSpec: &runtimeSpec{
Namespace: consts.NetworkOperatorResourceNamespace,
},
}
Expand Down

0 comments on commit 4ddc2d2

Please sign in to comment.