Skip to content

webhooks: make SGX mutator registration to follow other webhooks #1677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lib-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
runner: simics-spr
images: intel-qat-plugin intel-qat-initcontainer openssl-qat-engine
- name: e2e-sgx
targetjob: e2e-sgx FOCUS="|(SGX Admission)"
runner: sgx
images: intel-sgx-plugin intel-sgx-initcontainer intel-sgx-admissionwebhook sgx-sdk-demo intel-deviceplugin-operator

Expand Down
7 changes: 1 addition & 6 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"strings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -44,7 +43,6 @@ import (
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller"
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpgacontroller/patcher"
sgxwebhook "github.com/intel/intel-device-plugins-for-kubernetes/pkg/webhooks/sgx"
"sigs.k8s.io/controller-runtime/pkg/builder"
)

var (
Expand Down Expand Up @@ -176,10 +174,7 @@ func main() {
}

if contains(devices, "sgx") {
if err = builder.WebhookManagedBy(mgr).
For(&corev1.Pod{}).
WithDefaulter(&sgxwebhook.Mutator{}).
Complete(); err != nil {
if err = (&sgxwebhook.Mutator{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
os.Exit(1)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/sgx_admissionwebhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"os"

sgxwebhook "github.com/intel/intel-device-plugins-for-kubernetes/pkg/webhooks/sgx"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog/v2/textlogger"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand Down Expand Up @@ -59,10 +57,7 @@ func main() {
os.Exit(1)
}

if err := builder.WebhookManagedBy(mgr).
For(&corev1.Pod{}).
WithDefaulter(&sgxwebhook.Mutator{}).
Complete(); err != nil {
if err := (&sgxwebhook.Mutator{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
os.Exit(1)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/webhooks/sgx/sgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/intel/intel-device-plugins-for-kubernetes/pkg/internal/containers"
Expand All @@ -34,6 +35,13 @@ var ErrObjectType = errors.New("invalid runtime object type")
// Mutator annotates Pods.
type Mutator struct{}

func (s *Mutator) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&corev1.Pod{}).
WithDefaulter(s).
Complete()
}

const (
namespace = "sgx.intel.com"
encl = namespace + "/enclave"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/iaa/iaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func describe() {
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-f", demoPath)

ginkgo.By("waiting for the IAA demo to succeed")
err := e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, f.ClientSet, podName, f.Namespace.Name, 300*time.Second)
err := e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, f.ClientSet, podName, f.Namespace.Name, 360*time.Second)
gomega.Expect(err).To(gomega.BeNil(), utils.GetPodLogs(ctx, f, podName, podName))
})

Expand Down