Skip to content

Commit 11c9753

Browse files
authored
Merge pull request #1745 from bart0sh/PR155-fpga-support-CDI
FPGA: support CDI
2 parents 8c885da + e58369e commit 11c9753

34 files changed

+184
-168
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The FPGA plugin comes as three parts.
6666

6767
- the [device plugin](#device-plugin)
6868
- the [admission controller](#admission-controller)
69-
- the [CRIO-O prestart hook](#cri-o-prestart-hook)
69+
- the [OCI createRuntime hook](#OCI-createRuntime-hook)
7070

7171
Refer to each individual sub-components documentation for more details.
7272
Brief overviews of the sub-components are below.
@@ -88,9 +88,9 @@ is responsible for performing mapping from user-friendly function IDs to the
8888
Interface ID and Bitstream ID that are required for FPGA programming. It also
8989
implements access control by namespacing FPGA configuration information.
9090

91-
#### CRI-O Prestart Hook
91+
#### OCI createRuntime Hook
9292

93-
The [FPGA prestart CRI-O hook](cmd/fpga_crihook/README.md) performs discovery
93+
The [FPGA OCI createRuntime hook](cmd/fpga_crihook/README.md) performs discovery
9494
of the requested FPGA function bitstream and programs FPGA devices based on the
9595
environment variables in the workload description.
9696

build/docker/intel-fpga-initcontainer.Dockerfile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ RUN install -D ${DIR}/LICENSE /install_root/licenses/intel-device-plugins-for-ku
6666
--save_path /install_root/licenses/$CMD/go-licenses ; \
6767
else mkdir -p /install_root/licenses/$CMD/go-licenses/ && cd licenses/$CMD && cp -r * /install_root/licenses/$CMD/go-licenses/ ; fi
6868
###
69-
ARG SRC_DIR=/usr/local/fpga-sw
70-
ARG DST_DIR=/opt/intel/fpga-sw
71-
RUN echo "{\n\
72-
\"hook\" : \"$DST_DIR/$CRI_HOOK\",\n\
73-
\"stage\" : [ \"prestart\" ],\n\
74-
\"annotation\": [ \"fpga.intel.com/region\" ]\n\
75-
}\n">>/install_root/$SRC_DIR/$CRI_HOOK.json
7669
ARG TOYBOX_VERSION="0.8.11"
7770
ARG TOYBOX_SHA256="83a3a88cbe1fa30f099c2f58295baef4637aaf988085aaea56e03aa29168175d"
7871
ARG ROOT=/install_root
@@ -93,7 +86,7 @@ LABEL vendor='Intel®'
9386
LABEL version='devel'
9487
LABEL release='1'
9588
LABEL name='intel-fpga-initcontainer'
96-
LABEL summary='Intel® FPGA programming CRI hook for Kubernetes'
97-
LABEL description='The FPGA prestart CRI-O hook performs discovery of the requested FPGA function bitstream and programs FPGA devices based on the environment variables in the workload description'
89+
LABEL summary='Intel® FPGA programming CDI hook for Kubernetes'
90+
LABEL description='The FPGA OCI createRuntime hook performs discovery of the requested FPGA function bitstream and programs FPGA devices based on the environment variables in the workload description'
9891
COPY --from=builder /install_root /
99-
ENTRYPOINT [ "/usr/bin/sh", "-c", "cp -a /usr/local/fpga-sw/* /opt/intel/fpga-sw/ && ln -sf /opt/intel/fpga-sw/intel-fpga-crihook.json /etc/containers/oci/hooks.d/" ]
92+
ENTRYPOINT [ "/usr/bin/sh", "-c", "cp -a /usr/local/fpga-sw/* /opt/intel/fpga-sw/" ]

build/docker/templates/intel-fpga-initcontainer.Dockerfile.in

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,16 @@ ARG CMD=fpga_tool
1414
ARG EP=/usr/local/fpga-sw/$CMD
1515
#include "default_build.docker"
1616

17-
ARG SRC_DIR=/usr/local/fpga-sw
18-
ARG DST_DIR=/opt/intel/fpga-sw
19-
20-
RUN echo "{\n\N
21-
\"hook\" : \"$DST_DIR/$CRI_HOOK\",\n\N
22-
\"stage\" : [ \"prestart\" ],\n\N
23-
\"annotation\": [ \"fpga.intel.com/region\" ]\n\N
24-
}\n">>/install_root/$SRC_DIR/$CRI_HOOK.json
25-
2617
#include "toybox_build.docker"
2718

2819
FROM ${FINAL_BASE}
2920

3021
#include "default_labels.docker"
3122

3223
LABEL name='intel-fpga-initcontainer'
33-
LABEL summary='Intel® FPGA programming CRI hook for Kubernetes'
34-
LABEL description='The FPGA prestart CRI-O hook performs discovery of the requested FPGA function bitstream and programs FPGA devices based on the environment variables in the workload description'
24+
LABEL summary='Intel® FPGA programming CDI hook for Kubernetes'
25+
LABEL description='The FPGA OCI createRuntime hook performs discovery of the requested FPGA function bitstream and programs FPGA devices based on the environment variables in the workload description'
3526

3627
COPY --from=builder /install_root /
3728

38-
ENTRYPOINT [ "/usr/bin/sh", "-c", "cp -a /usr/local/fpga-sw/* /opt/intel/fpga-sw/ && ln -sf /opt/intel/fpga-sw/intel-fpga-crihook.json /etc/containers/oci/hooks.d/" ]
29+
ENTRYPOINT [ "/usr/bin/sh", "-c", "cp -a /usr/local/fpga-sw/* /opt/intel/fpga-sw/" ]

cmd/dlb_plugin/dlb_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (dp *DevicePlugin) scan() dpapi.DeviceTree {
8888
ContainerPath: file,
8989
Permissions: "rw",
9090
}}
91-
deviceInfo := dpapi.NewDeviceInfo(pluginapi.Healthy, devs, nil, nil, nil)
91+
deviceInfo := dpapi.NewDeviceInfo(pluginapi.Healthy, devs, nil, nil, nil, nil)
9292

9393
sysfsDev := filepath.Join(dp.sysfsDir, filepath.Base(file))
9494
sriovNumVFs := pluginutils.GetSriovNumVFs(sysfsDev)

cmd/fpga_admissionwebhook/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ devices to Kubernetes.
2323
2424
The FPGA admission controller webhook is responsible for performing mapping from user-friendly
2525
function IDs to the Interface ID and Bitstream ID that are required for FPGA programming by
26-
the [FPGA CRI-O hook](../fpga_crihook/README.md).
26+
the [FPGA OCI createRuntime hook](../fpga_crihook/README.md).
2727

2828
Mappings are stored in namespaced custom resource definition (CRD) objects, therefore the admission
2929
controller also performs access control, determining which bitstream can be used for which namespace.
3030
More details can be found in the [Mappings](#mappings) section.
3131

3232
The admission controller also keeps the user from bypassing namespaced mapping restrictions,
3333
by denying admission of any pods that are trying to use internal knowledge of InterfaceID or
34-
Bitstream ID environment variables used by the prestart hook.
34+
Bitstream ID environment variables used by the createRuntime hook.
3535

3636
## Dependencies
3737

3838
This component is one of a set of components that work together. You may also want to
3939
install the following:
4040

4141
- [FPGA device plugin](../fpga_plugin/README.md)
42-
- [FPGA prestart CRI-O hook](../fpga_crihook/README.md)
42+
- [FPGA OCI createRuntime hook](../fpga_crihook/README.md)
4343

4444
All components have the same basic dependencies as the
4545
[generic plugin framework dependencies](../../README.md#about)
@@ -129,7 +129,7 @@ The same mapping, but with its mode field set to `region`, would translate
129129
and the corresponding AF IDs are set in environment variables for the container.
130130
Though in this case the cluster administrator would probably want to rename
131131
the mapping `arria10.dcp1.2-nlb0-preprogrammed` to something like `arria10.dcp1.2-nlb0-orchestrated`
132-
to reflect its mode. The [FPGA CRI-O hook](../fpga_crihook/README.md) then loads the requested
132+
to reflect its mode. The [FPGA OCI createRuntime hook](../fpga_crihook/README.md) then loads the requested
133133
bitstream to a region before the container is started.
134134

135135
Mappings of resource names are configured with objects of `AcceleratorFunction` and
@@ -183,4 +183,4 @@ and they are applicable to pods created in the corresponding namespaces.
183183

184184
## Next steps
185185

186-
Continue with [FPGA prestart CRI-O hook](../fpga_crihook/README.md).
186+
Continue with [FPGA OCI createRuntime hook](../fpga_crihook/README.md).

cmd/fpga_crihook/README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
# Intel FPGA prestart CRI-O webhook for Kubernetes
1+
# Intel FPGA OCI createRuntime hook for Kubernetes
22

33
Table of Contents
44

55
* [Introduction](#introduction)
66
* [Dependencies](#dependencies)
7-
* [Configuring CRI-O](#configuring-cri-o)
7+
* [Configuring CRI runtimes](#configuring-cri-runtimes)
88

99
## Introduction
1010

11-
The FPGA CRI-O webhook is one of the components used to add support for Intel FPGA
11+
The FPGA CDI hook is one of the components used to add support for Intel FPGA
1212
devices to Kubernetes.
1313

14-
The FPGA prestart CRI-O hook is triggered by container annotations, such as set by the
15-
[FPGA device plugin](../fpga_plugin/README.md). It performs discovery of the requested FPGA
16-
function bitstream and then programs FPGA devices based on the environment variables
17-
in the workload description.
14+
The FPGA OCI createRuntime hook is passed by the [FPGA device plugin](../fpga_plugin/README.md) as
15+
a CDI device attribute to the Kubelet and then to the CRI runtime.
16+
It performs discovery of the requested FPGA function bitstream and then programs FPGA devices
17+
based on the environment variables in the workload description.
1818

19-
The CRI-O prestart hook is only *required* when the
20-
[FPGA admission webhook](../fpga_admissionwebhook/README.md) is configured for orchestration
21-
programmed mode, and is benign (un-used) otherwise.
19+
The hook is only *required* when the [FPGA admission webhook](../fpga_admissionwebhook/README.md)
20+
is configured for orchestration programmed mode, and is benign (un-used) otherwise.
2221

23-
> **Note:** The fpga CRI-O webhook is usually installed by the same DaemonSet as the
24-
> FPGA device plugin. If building and installing the CRI-O webhook by hand, it is
22+
> **Note:** The fpga CDI hook is usually installed by the same DaemonSet as the
23+
> FPGA device plugin. If building and installing the hook by hand, it is
2524
> recommended you reference the
2625
> [fpga plugin DaemonSet YAML](/deployments/fpga_plugin/base/intel-fpga-plugin-daemonset.yaml ) for
2726
> more details.
@@ -39,11 +38,8 @@ All components have the same basic dependencies as the
3938

4039
See [the development guide](../../DEVEL.md) for details if you want to deploy a customized version of the CRI hook.
4140

42-
## Configuring CRI-O
41+
## Configuring CRI runtimes
4342

44-
Recent versions of [CRI-O](https://github.com/cri-o/cri-o) are shipped with default configuration
45-
file that prevents CRI-O to discover and configure hooks automatically.
46-
For FPGA orchestration programmed mode, the OCI hooks are the key component.
47-
Please ensure that your `/etc/crio/crio.conf` parameter `hooks_dir` is either unset
48-
(to enable default search paths for OCI hooks configuration) or contains the directory
49-
`/etc/containers/oci/hooks.d`.
43+
CDI should be enabled for the CRI runtime to call the hook. CRI-O has it enabled by
44+
default and for Containerd it should be enabled explicitly in its configuration file as
45+
explained in the [CDI documentation](https://github.com/cncf-tags/container-device-interface?tab=readme-ov-file#how-to-configure-cdi)

cmd/fpga_crihook/main.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ const (
3232
configJSON = "config.json"
3333
fpgaRegionEnvPrefix = "FPGA_REGION_"
3434
fpgaAfuEnvPrefix = "FPGA_AFU_"
35-
36-
annotationName = "com.intel.fpga.mode"
37-
annotationValue = "fpga.intel.com/region"
3835
)
3936

4037
// Stdin defines structure for standard JSONed input of the OCI platform hook.
@@ -220,16 +217,6 @@ func getStdin(reader io.Reader) (*Stdin, error) {
220217
return nil, err
221218
}
222219

223-
// Check if device plugin annotation is set
224-
if stdinJ.Annotations.ComIntelFpgaMode == "" {
225-
return nil, errors.Errorf("annotation %s is not set", annotationName)
226-
}
227-
228-
// Check if device plugin annotation is set
229-
if stdinJ.Annotations.ComIntelFpgaMode != annotationValue {
230-
return nil, errors.Errorf("annotation %s has incorrect value '%s'", annotationName, stdinJ.Annotations.ComIntelFpgaMode)
231-
}
232-
233220
if stdinJ.Bundle == "" {
234221
return nil, errors.New("'bundle' field is not set in the stdin JSON")
235222
}

cmd/fpga_crihook/main_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ func TestGetStdin(t *testing.T) {
7373
stdinJSON: "stdin-incorrect-JSON.json",
7474
expectedErr: true,
7575
},
76-
{
77-
name: "no annotations",
78-
stdinJSON: "stdin-no-annotations.json",
79-
expectedErr: true,
80-
},
81-
{
82-
name: "annotation is not set",
83-
stdinJSON: "stdin-incorrect-intel-annotation.json",
84-
expectedErr: true,
85-
},
8676
}
8777
for _, tc := range tcases {
8878
t.Run(tc.name, func(t *testing.T) {

cmd/fpga_crihook/testdata/config-correct.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
}
5353
],
5454
"hooks": {
55-
"prestart": [
55+
"createRuntime": [
5656
{
5757
"path": "/usr/local/bin/fpga_crihook",
5858
"args": [
5959
"/usr/local/bin/fpga_crihook"
6060
],
6161
"env": [
62-
"stage=prestart"
62+
"stage=createRuntime"
6363
]
6464
}
6565
]

cmd/fpga_crihook/testdata/config-no-FPGA-devices.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
}
5353
],
5454
"hooks": {
55-
"prestart": [
55+
"createRuntime": [
5656
{
5757
"path": "/usr/local/bin/fpga_crihook",
5858
"args": [
5959
"/usr/local/bin/fpga_crihook"
6060
],
6161
"env": [
62-
"stage=prestart"
62+
"stage=createRuntime"
6363
]
6464
}
6565
]

cmd/fpga_crihook/testdata/config-no-afu.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
}
5252
],
5353
"hooks": {
54-
"prestart": [
54+
"createRuntime": [
5555
{
5656
"path": "/usr/local/bin/fpga_crihook",
5757
"args": [
5858
"/usr/local/bin/fpga_crihook"
5959
],
6060
"env": [
61-
"stage=prestart"
61+
"stage=createRuntime"
6262
]
6363
}
6464
]

cmd/fpga_crihook/testdata/config-no-devices.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
}
5353
],
5454
"hooks": {
55-
"prestart": [
55+
"createRuntime": [
5656
{
5757
"path": "/usr/local/bin/fpga_crihook",
5858
"args": [
5959
"/usr/local/bin/fpga_crihook"
6060
],
6161
"env": [
62-
"stage=prestart"
62+
"stage=createRuntime"
6363
]
6464
}
6565
]

cmd/fpga_crihook/testdata/config-no-env.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
}
4343
],
4444
"hooks": {
45-
"prestart": [
45+
"createRuntime": [
4646
{
4747
"path": "/usr/local/bin/fpga_crihook",
4848
"args": [
4949
"/usr/local/bin/fpga_crihook"
5050
],
5151
"env": [
52-
"stage=prestart"
52+
"stage=createRuntime"
5353
]
5454
}
5555
]

cmd/fpga_crihook/testdata/config-no-linux.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
}
5353
],
5454
"hooks": {
55-
"prestart": [
55+
"createRuntime": [
5656
{
5757
"path": "/usr/local/bin/fpga_crihook",
5858
"args": [
5959
"/usr/local/bin/fpga_crihook"
6060
],
6161
"env": [
62-
"stage=prestart"
62+
"stage=createRuntime"
6363
]
6464
}
6565
]

cmd/fpga_crihook/testdata/config-no-process.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
}
3232
],
3333
"hooks": {
34-
"prestart": [
34+
"createRuntime": [
3535
{
3636
"path": "/usr/local/bin/fpga_crihook",
3737
"args": [
3838
"/usr/local/bin/fpga_crihook"
3939
],
4040
"env": [
41-
"stage=prestart"
41+
"stage=createRuntime"
4242
]
4343
}
4444
]

cmd/fpga_crihook/testdata/config-no-region.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
}
5252
],
5353
"hooks": {
54-
"prestart": [
54+
"createRuntime": [
5555
{
5656
"path": "/usr/local/bin/fpga_crihook",
5757
"args": [
5858
"/usr/local/bin/fpga_crihook"
5959
],
6060
"env": [
61-
"stage=prestart"
61+
"stage=createRuntime"
6262
]
6363
}
6464
]

cmd/fpga_crihook/testdata/config-non-existing-bitstream.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
}
5353
],
5454
"hooks": {
55-
"prestart": [
55+
"createRuntime": [
5656
{
5757
"path": "/usr/local/bin/fpga_crihook",
5858
"args": [
5959
"/usr/local/bin/fpga_crihook"
6060
],
6161
"env": [
62-
"stage=prestart"
62+
"stage=createRuntime"
6363
]
6464
}
6565
]

cmd/fpga_crihook/testdata/config-region-afu-dont-match.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
}
5454
],
5555
"hooks": {
56-
"prestart": [
56+
"createRuntime": [
5757
{
5858
"path": "/usr/local/bin/fpga_crihook",
5959
"args": [
6060
"/usr/local/bin/fpga_crihook"
6161
],
6262
"env": [
63-
"stage=prestart"
63+
"stage=createRuntime"
6464
]
6565
}
6666
]

0 commit comments

Comments
 (0)