Skip to content
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
8 changes: 8 additions & 0 deletions manifests/openshift/ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ spec:
quay.io/openshift-virtualization/wasp-agent:v4.17
imagePullPolicy: Always
name: wasp-agent
lifecycle:
preStop:
exec:
command:
- rm
- -f
- /host/opt/oci-hook-swap.sh
- /host/run/containers/oci/hooks.d/swap-for-burstable.json
resources:
requests:
cpu: 100m
Expand Down
10 changes: 10 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package consts

const (
HookTemplateFile = "/app/OCI-hook/hookscript.template"
HookScriptPath = "/host/opt/oci-hook-swap.sh"
HookConfigSource = "/app/OCI-hook/swap-for-burstable.json"
HookConfigPath = "/host/run/containers/oci/hooks.d/swap-for-burstable.json"
CrioConfigPath = "/host/etc/crio/crio.conf"
CrioConfigDropInPath = "/host/etc/crio/crio.conf.d"
)
4 changes: 2 additions & 2 deletions pkg/wasp/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"context"
"flag"
"fmt"
"io"
"os"
"github.com/openshift-virtualization/wasp-agent/pkg/client"
"github.com/openshift-virtualization/wasp-agent/pkg/informers"
"github.com/openshift-virtualization/wasp-agent/pkg/log"
limited_swap_manager "github.com/openshift-virtualization/wasp-agent/pkg/wasp/limited-swap-manager"
"io"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
"os"
)

type WaspApp struct {
Expand Down
22 changes: 8 additions & 14 deletions pkg/wasp/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ package wasp

import (
"fmt"
"os"

"github.com/openshift-virtualization/wasp-agent/pkg/consts"
"github.com/openshift-virtualization/wasp-agent/pkg/wasp/config"
oci_hook_render "github.com/openshift-virtualization/wasp-agent/pkg/wasp/oci-hook-render"
"k8s.io/klog/v2"
"os"
)

const (
hookTemplateFile = "/app/OCI-hook/hookscript.template"
hookScriptPath = "/host/opt/oci-hook-swap.sh"
// CrioConfigPath is the default location for the conf file.
CrioConfigPath = "/host/etc/crio/crio.conf"
// CrioConfigDropInPath is the default location for the drop-in config files.
CrioConfigDropInPath = "/host/etc/crio/crio.conf.d"
)

type crioConfiguration interface {
Expand All @@ -31,28 +24,29 @@ func setOCIHook() error {
return err
}

err = moveFile("/app/OCI-hook/swap-for-burstable.json", "/host/run/containers/oci/hooks.d/swap-for-burstable.json")
err = moveFile(consts.HookConfigSource, consts.HookConfigPath)
if err != nil {
return err
}

return nil
}


func setupHookScript() error {
crioConfig := crioConfiguration(config.New(CrioConfigPath, CrioConfigDropInPath))
crioConfig := crioConfiguration(config.New(consts.CrioConfigPath, consts.CrioConfigDropInPath))
runtime, err := crioConfig.GetRuntime()
if err != nil {
return err
}
klog.Infof("detected runtime " + runtime)

renderer := hookRenderer(oci_hook_render.New(hookTemplateFile, hookScriptPath, runtime))
renderer := hookRenderer(oci_hook_render.New(consts.HookTemplateFile, consts.HookScriptPath, runtime))
if err := renderer.Render(); err != nil {
return err
}

err = os.Chmod(hookScriptPath, 0755)
err = os.Chmod(consts.HookScriptPath, 0755)
if err != nil {
return fmt.Errorf("Couldn't set file permissions: %v", err)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/wasp/resources/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package operator

import (
"fmt"

"github.com/openshift-virtualization/wasp-agent/pkg/consts"
"github.com/openshift-virtualization/wasp-agent/pkg/monitoring/rules"
utils2 "github.com/openshift-virtualization/wasp-agent/pkg/util"

Expand Down Expand Up @@ -117,6 +119,17 @@ func createWaspDaemonSet(namespace, verbosity, waspImage, pullPolicy string) *ap
SecurityContext: &corev1.SecurityContext{
Privileged: boolPtr(true),
},
Lifecycle: &corev1.Lifecycle{
PreStop: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{
"rm", "-f",
consts.HookScriptPath,
consts.HookConfigPath,
},
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "host",
Expand Down
Loading