Skip to content
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

change pod mutation webhook logic for kubevirt v1.1.x support #70

Merged
merged 1 commit into from
Mar 18, 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
19 changes: 12 additions & 7 deletions pkg/webhook/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package webhook
import (
"fmt"

kubevirtctl "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1"
"github.com/harvester/harvester/pkg/webhook/types"
"github.com/sirupsen/logrus"
admissionregv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"

kubevirtctl "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1"
"github.com/harvester/harvester/pkg/webhook/types"

"github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io/v1beta1"
)

const (
VMLabel = "harvesterhci.io/vmName"
VMLabel = "harvesterhci.io/vmName"
defaultComputeContainerName = "compute"
)

var matchingLabels = []labels.Set{
Expand Down Expand Up @@ -131,11 +133,14 @@ func (m *podMutator) Create(_ *types.Request, newObj runtime.Object) (types.Patc
func createCapabilityPatch(pod *corev1.Pod) (types.PatchOps, error) {
var patchOps types.PatchOps
for idx, container := range pod.Spec.Containers {
addPatch, err := resourcePatch(container.SecurityContext.Capabilities.Add, fmt.Sprintf("/spec/containers/%d/securityContext/capabilities/add", idx))
if err != nil {
return nil, err
if container.Name == defaultComputeContainerName {

addPatch, err := resourcePatch(container.SecurityContext.Capabilities.Add, fmt.Sprintf("/spec/containers/%d/securityContext/capabilities/add", idx))
if err != nil {
return nil, err
}
patchOps = append(patchOps, addPatch...)
}
patchOps = append(patchOps, addPatch...)
}

return patchOps, nil
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("validate mutator by sending a mock pod request needing mutatio
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "fakepod",
Name: "compute",
Image: "fakeimage",
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Expand Down
Loading