@@ -25,6 +25,7 @@ import (
25
25
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
26
26
"k8s.io/klog/v2"
27
27
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
28
+ cdispec "tags.cncf.io/container-device-interface/specs-go"
28
29
)
29
30
30
31
const (
@@ -38,18 +39,20 @@ const (
38
39
)
39
40
40
41
type 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
45
47
}
46
48
47
- func newDevicePlugin (devfsDir string , nEnclave , nProvision uint ) * devicePlugin {
49
+ func newDevicePlugin (devfsDir string , nEnclave , nProvision uint , dcapInfraResources bool ) * devicePlugin {
48
50
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 ),
53
56
}
54
57
}
55
58
@@ -96,6 +99,39 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
96
99
devTree .AddDevice (deviceTypeProvision , devID , dpapi .NewDeviceInfoWithTopologyHints (pluginapi .Healthy , nodes , nil , nil , nil , nil , nil ))
97
100
}
98
101
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
+ }
116
+
117
+ // TODO: /sys/firmware is a maskedPath. Test /run/efivars with a patched PCK-ID-Retrieval-Tool.
118
+ efiVarFsMount := & cdispec.Spec {
119
+ Version : dpapi .CDIVersion ,
120
+ Kind : dpapi .CDIVendor + "/sgx" ,
121
+ Devices : []cdispec.Device {
122
+ {
123
+ Name : "efivarfs" ,
124
+ ContainerEdits : cdispec.ContainerEdits {
125
+ Mounts : []* cdispec.Mount {
126
+ {HostPath : "efivarfs" , ContainerPath : "/run/efivars" , Type : "efivarfs" , Options : []string {"rw" , "nosuid" , "nodev" , "noexec" , "relatime" }},
127
+ },
128
+ },
129
+ },
130
+ },
131
+ }
132
+
133
+ devTree .AddDevice ("registration" , "registration-1" , dpapi .NewDeviceInfoWithTopologyHints (pluginapi .Healthy , regNodes , nil , nil , nil , nil , efiVarFsMount ))
134
+
99
135
return devTree , nil
100
136
}
101
137
@@ -121,15 +157,18 @@ func getDefaultPodCount(nCPUs uint) uint {
121
157
func main () {
122
158
var enclaveLimit , provisionLimit uint
123
159
160
+ var dcapInfraResources bool
161
+
124
162
podCount := getDefaultPodCount (uint (runtime .NumCPU ()))
125
163
126
164
flag .UintVar (& enclaveLimit , "enclave-limit" , podCount , "Number of \" enclave\" resources" )
127
165
flag .UintVar (& provisionLimit , "provision-limit" , podCount , "Number of \" provision\" resources" )
166
+ flag .BoolVar (& dcapInfraResources , "dcap-infra-resources" , false , "add special resources for DCAP infrastructure daemonSet pods" )
128
167
flag .Parse ()
129
168
130
169
klog .V (4 ).Infof ("SGX device plugin started with %d \" %s/enclave\" resources and %d \" %s/provision\" resources." , enclaveLimit , namespace , provisionLimit , namespace )
131
170
132
- plugin := newDevicePlugin (devicePath , enclaveLimit , provisionLimit )
171
+ plugin := newDevicePlugin (devicePath , enclaveLimit , provisionLimit , dcapInfraResources )
133
172
manager := dpapi .NewManager (namespace , plugin )
134
173
manager .Run ()
135
174
}
0 commit comments