Skip to content

Commit 66288ca

Browse files
committed
sgx: set epc limits via NRI annotations
Signed-off-by: Mikko Ylinen <[email protected]>
1 parent 48fd7b8 commit 66288ca

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

deployments/sgx_plugin/base/intel-sgx-plugin.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ spec:
1515
spec:
1616
automountServiceAccountToken: false
1717
containers:
18+
- name: nri-sgx-epc
19+
image: ghcr.io/containers/nri-plugins/nri-sgx-epc:unstable
20+
securityContext:
21+
readOnlyRootFilesystem: true
22+
allowPrivilegeEscalation: false
23+
imagePullPolicy: IfNotPresent
24+
volumeMounts:
25+
- name: nrisockets
26+
mountPath: /var/run/nri
1827
- name: intel-sgx-plugin
1928
image: intel/intel-sgx-plugin:devel
2029
securityContext:
@@ -36,6 +45,9 @@ spec:
3645
- name: kubeletsockets
3746
hostPath:
3847
path: /var/lib/kubelet/device-plugins
48+
- name: nrisockets
49+
hostPath:
50+
path: /var/run/nri
3951
- name: sgx-enclave
4052
hostPath:
4153
path: /dev/sgx_enclave

pkg/controllers/sgx/controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
131131

132132
daemonSet.ObjectMeta.Namespace = c.ns
133133

134-
daemonSet.Spec.Template.Spec.Containers[0].Args = getPodArgs(devicePlugin)
135-
daemonSet.Spec.Template.Spec.Containers[0].Image = devicePlugin.Spec.Image
134+
daemonSet.Spec.Template.Spec.Containers[1].Args = getPodArgs(devicePlugin)
135+
daemonSet.Spec.Template.Spec.Containers[1].Image = devicePlugin.Spec.Image
136136

137137
// add the optional init container
138138
if devicePlugin.Spec.InitImage != "" {
@@ -157,8 +157,8 @@ func removeVolume(volumes []v1.Volume, name string) []v1.Volume {
157157
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
158158
dp := rawObj.(*devicepluginv1.SgxDevicePlugin)
159159

160-
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
161-
ds.Spec.Template.Spec.Containers[0].Image = dp.Spec.Image
160+
if ds.Spec.Template.Spec.Containers[1].Image != dp.Spec.Image {
161+
ds.Spec.Template.Spec.Containers[1].Image = dp.Spec.Image
162162
updated = true
163163
}
164164

@@ -184,8 +184,8 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
184184
}
185185

186186
newargs := getPodArgs(dp)
187-
if strings.Join(ds.Spec.Template.Spec.Containers[0].Args, " ") != strings.Join(newargs, " ") {
188-
ds.Spec.Template.Spec.Containers[0].Args = newargs
187+
if strings.Join(ds.Spec.Template.Spec.Containers[1].Args, " ") != strings.Join(newargs, " ") {
188+
ds.Spec.Template.Spec.Containers[1].Args = newargs
189189
updated = true
190190
}
191191

pkg/controllers/sgx/controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
6565
Spec: v1.PodSpec{
6666
AutomountServiceAccountToken: &no,
6767
Containers: []v1.Container{
68+
{
69+
Name: "nri-sgx-epc",
70+
Image: "ghcr.io/containers/nri-plugins/nri-sgx-epc:unstable",
71+
ImagePullPolicy: "IfNotPresent",
72+
SecurityContext: &v1.SecurityContext{
73+
ReadOnlyRootFilesystem: &yes,
74+
AllowPrivilegeEscalation: &no,
75+
},
76+
VolumeMounts: []v1.VolumeMount{
77+
{
78+
Name: "nrisockets",
79+
MountPath: "/var/run/nri",
80+
},
81+
},
82+
},
6883
{
6984
Name: appLabel,
7085
Args: getPodArgs(devicePlugin),
@@ -105,6 +120,14 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
105120
},
106121
},
107122
},
123+
{
124+
Name: "nrisockets",
125+
VolumeSource: v1.VolumeSource{
126+
HostPath: &v1.HostPathVolumeSource{
127+
Path: "/var/run/nri",
128+
},
129+
},
130+
},
108131
{
109132
Name: "sgx-enclave",
110133
VolumeSource: v1.VolumeSource{

pkg/webhooks/sgx/sgx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var ErrObjectType = errors.New("invalid runtime object type")
3535
type Mutator struct{}
3636

3737
const (
38+
epcLimitKey = "epc-limit.nri.io"
3839
namespace = "sgx.intel.com"
3940
encl = namespace + "/enclave"
4041
epc = namespace + "/epc"
@@ -148,6 +149,9 @@ func (s *Mutator) Default(ctx context.Context, obj runtime.Object) error {
148149
continue
149150
}
150151

152+
epcLimitAnnotation := fmt.Sprintf("%s/container.%s", epcLimitKey, container.Name)
153+
pod.Annotations[epcLimitAnnotation] = fmt.Sprintf("%d", epcSize)
154+
151155
totalEpc += epcSize
152156

153157
// Quote Generation Modes:

test/e2e/sgxadmissionwebhook/sgxaadmissionwebhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func describe() {
6969

7070
ginkgo.By("checking the pod total EPC size annotation is correctly set")
7171
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
72+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1Mi"))
7273
})
7374
ginkgo.It("mutates created pods when the container contains the quote generation libraries", func(ctx context.Context) {
7475
ginkgo.By("submitting the pod")
@@ -79,6 +80,7 @@ func describe() {
7980

8081
ginkgo.By("checking the pod total EPC size annotation is correctly set")
8182
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
83+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1Mi"))
8284
})
8385
ginkgo.It("mutates created pods when the container uses aesmd from a side-car container to generate quotes", func(ctx context.Context) {
8486
ginkgo.By("submitting the pod")
@@ -93,6 +95,8 @@ func describe() {
9395
gomega.Expect(pod.Spec.Containers[0].Env[0].Value).To(gomega.Equal("1"))
9496
ginkgo.By("checking the pod total EPC size annotation is correctly set")
9597
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("2Mi"))
98+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1Mi"))
99+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.aesmd"]).To(gomega.Equal("1Mi"))
96100
})
97101
ginkgo.It("mutates created pods where one container uses host/daemonset aesmd to generate quotes", func(ctx context.Context) {
98102
ginkgo.By("submitting the pod")
@@ -106,6 +110,7 @@ func describe() {
106110
gomega.Expect(pod.Spec.Containers[0].Env[0].Value).To(gomega.Equal("1"))
107111
ginkgo.By("checking the pod total EPC size annotation is correctly set")
108112
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
113+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1Mi"))
109114
})
110115
ginkgo.It("mutates created pods where three containers use host/daemonset aesmd to generate quotes", func(ctx context.Context) {
111116
ginkgo.By("submitting the pod")
@@ -125,6 +130,9 @@ func describe() {
125130
gomega.Expect(pod.Spec.Containers[2].Env[0].Value).To(gomega.Equal("1"))
126131
ginkgo.By("checking the pod total EPC size annotation is correctly set")
127132
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("3Mi"))
133+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test1"]).To(gomega.Equal("1Mi"))
134+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test2"]).To(gomega.Equal("1Mi"))
135+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test3"]).To(gomega.Equal("1Mi"))
128136
})
129137
ginkgo.It("checks that Volumes and VolumeMounts are created only once", func(ctx context.Context) {
130138
ginkgo.By("submitting the pod")

0 commit comments

Comments
 (0)