@@ -25,6 +25,7 @@ import (
2525 dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
2626 "k8s.io/klog/v2"
2727 pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
28+ cdispec "tags.cncf.io/container-device-interface/specs-go"
2829)
2930
3031const (
@@ -38,18 +39,20 @@ const (
3839)
3940
4041type devicePlugin struct {
41- scanDone chan bool
42- devfsDir string
43- nEnclave uint
44- nProvision uint
42+ scanDone chan bool
43+ devfsDir string
44+ nEnclave uint
45+ nProvision uint
46+ dcapInfraResources bool
4547}
4648
47- func newDevicePlugin (devfsDir string , nEnclave , nProvision uint ) * devicePlugin {
49+ func newDevicePlugin (devfsDir string , nEnclave , nProvision uint , dcapInfraResources bool ) * devicePlugin {
4850 return & devicePlugin {
49- devfsDir : devfsDir ,
50- nEnclave : nEnclave ,
51- nProvision : nProvision ,
52- scanDone : make (chan bool , 1 ),
51+ devfsDir : devfsDir ,
52+ nEnclave : nEnclave ,
53+ nProvision : nProvision ,
54+ dcapInfraResources : dcapInfraResources ,
55+ scanDone : make (chan bool , 1 ),
5356 }
5457}
5558
@@ -96,6 +99,40 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
9699 devTree .AddDevice (deviceTypeProvision , devID , dpapi .NewDeviceInfoWithTopologyHints (pluginapi .Healthy , nodes , nil , nil , nil , nil , nil ))
97100 }
98101
102+ if ! dp .dcapInfraResources {
103+ return devTree , nil
104+ }
105+
106+ tdQeNodes := []pluginapi.DeviceSpec {
107+ {HostPath : sgxEnclavePath , ContainerPath : sgxEnclavePath , Permissions : "rw" },
108+ {HostPath : sgxProvisionPath , ContainerPath : sgxProvisionPath , Permissions : "rw" },
109+ }
110+
111+ devTree .AddDevice ("tdqe" , "tdqe-1" , dpapi .NewDeviceInfoWithTopologyHints (pluginapi .Healthy , tdQeNodes , nil , nil , nil , nil , nil ))
112+
113+ regNodes := []pluginapi.DeviceSpec {
114+ {HostPath : sgxEnclavePath , ContainerPath : sgxEnclavePath , Permissions : "rw" },
115+ {HostPath : sgxProvisionPath , ContainerPath : sgxProvisionPath , Permissions : "rw" },
116+ }
117+
118+ // TODO: /sys/firmware is a maskedPath. Test /run/efivars with a patched PCK-ID-Retrieval-Tool.
119+ efiVarFsMount := & cdispec.Spec {
120+ Version : dpapi .CDIVersion ,
121+ Kind : dpapi .CDIVendor + "/sgx" ,
122+ Devices : []cdispec.Device {
123+ {
124+ Name : "efivarfs" ,
125+ ContainerEdits : cdispec.ContainerEdits {
126+ Mounts : []* cdispec.Mount {
127+ {HostPath : "efivarfs" , ContainerPath : "/run/efivars" , Type : "efivarfs" , Options : []string {"rw" , "nosuid" , "nodev" , "noexec" , "relatime" }},
128+ },
129+ },
130+ },
131+ },
132+ }
133+
134+ devTree .AddDevice ("registration" , "registration-1" , dpapi .NewDeviceInfoWithTopologyHints (pluginapi .Healthy , regNodes , nil , nil , nil , nil , efiVarFsMount ))
135+
99136 return devTree , nil
100137}
101138
@@ -121,15 +158,18 @@ func getDefaultPodCount(nCPUs uint) uint {
121158func main () {
122159 var enclaveLimit , provisionLimit uint
123160
161+ var dcapInfraResources bool
162+
124163 podCount := getDefaultPodCount (uint (runtime .NumCPU ()))
125164
126165 flag .UintVar (& enclaveLimit , "enclave-limit" , podCount , "Number of \" enclave\" resources" )
127166 flag .UintVar (& provisionLimit , "provision-limit" , podCount , "Number of \" provision\" resources" )
167+ flag .BoolVar (& dcapInfraResources , "dcap-infra-resources" , false , "add special resources for DCAP infrastructure daemonSet pods" )
128168 flag .Parse ()
129169
130170 klog .V (4 ).Infof ("SGX device plugin started with %d \" %s/enclave\" resources and %d \" %s/provision\" resources." , enclaveLimit , namespace , provisionLimit , namespace )
131171
132- plugin := newDevicePlugin (devicePath , enclaveLimit , provisionLimit )
172+ plugin := newDevicePlugin (devicePath , enclaveLimit , provisionLimit , dcapInfraResources )
133173 manager := dpapi .NewManager (namespace , plugin )
134174 manager .Run ()
135175}
0 commit comments