Skip to content
Draft
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
814 changes: 814 additions & 0 deletions test/extended/node/node_swap_cnv.go

Large diffs are not rendered by default.

812 changes: 812 additions & 0 deletions test/extended/node/node_utils.go

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions test/extended/testdata/node/cnv-swap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# CNV Swap Configuration Test Data

This directory contains YAML and configuration files used by the CNV swap tests (`node_swap_cnv.go`).

## Files

### CNV Operator Installation

- `cnv-namespace.yaml` - Namespace for CNV operator (openshift-cnv)
- `cnv-operatorgroup.yaml` - OperatorGroup for CNV
- `cnv-subscription.yaml` - Subscription to install CNV operator from OperatorHub
- `cnv-hyperconverged.yaml` - HyperConverged CR to deploy CNV components

### Kubelet Drop-in Configurations

- `kubelet-limitedswap-dropin.yaml` - Kubelet config with LimitedSwap enabled
- `kubelet-noswap-dropin.yaml` - Kubelet config with NoSwap (default)
- `kubelet-malformed-dropin.yaml` - Intentionally malformed config for error testing

### MachineConfig Resources

- `machineconfig-swap-dropin-dir.yaml` - Creates the drop-in directory on workers
- `machineconfig-limitedswap.yaml` - Full MachineConfig with LimitedSwap configuration

## Drop-in Directory Paths

- CNV uses: `/etc/openshift/kubelet.conf.d/`
- Drop-in file: `99-kubelet-limited-swap.conf`

## Usage

### Manual CNV Installation

```bash
# Create namespace
oc apply -f cnv-namespace.yaml

# Create operator group
oc apply -f cnv-operatorgroup.yaml

# Subscribe to CNV operator
oc apply -f cnv-subscription.yaml

# Wait for operator to install
oc get csv -n openshift-cnv -w

# Create HyperConverged CR
oc apply -f cnv-hyperconverged.yaml

# Wait for CNV to be ready
oc get hyperconverged -n openshift-cnv -w
```

### Enable LimitedSwap via MachineConfig

```bash
# Apply MachineConfig (nodes will reboot)
oc apply -f machineconfig-limitedswap.yaml

# Monitor rollout
watch oc get mcp
```

### Manual Drop-in Configuration

```bash
# Debug into a node
oc debug node/<node-name>

# Create drop-in file
chroot /host
mkdir -p /etc/openshift/kubelet.conf.d
cat > /etc/openshift/kubelet.conf.d/99-kubelet-limited-swap.conf << 'EOF'
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
memorySwap:
swapBehavior: LimitedSwap
EOF

# Restart kubelet
systemctl restart kubelet
```

## Test Cases

The configuration files support testing:

- TC1: Drop-in directory creation and ownership
- TC2: Drop-in directory behavior on non-CNV nodes
- TC3: LimitedSwap configuration application
- TC4-TC5: swapBehavior value validation
- TC6: Configuration file priority (precedence)
- TC7: Kubelet restart with drop-in
- TC8: Drop-in file removal handling
- TC9: Drop-in directory permissions
- TC10: Malformed YAML handling
- TC11-TC13: Swap usage validation
- TC14: Multiple drop-in files
- TC15: Kubelet logs for swap configuration
- TC16: Swap status persistence across restarts
- TC17: Various swap sizes
9 changes: 9 additions & 0 deletions test/extended/testdata/node/cnv-swap/cnv-hyperconverged.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: hco.kubevirt.io/v1beta1
kind: HyperConverged
metadata:
name: kubevirt-hyperconverged
namespace: openshift-cnv
spec:
BareMetalPlatform: true
infra: {}
workloads: {}
6 changes: 6 additions & 0 deletions test/extended/testdata/node/cnv-swap/cnv-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: openshift-cnv
labels:
openshift.io/cluster-monitoring: "true"
8 changes: 8 additions & 0 deletions test/extended/testdata/node/cnv-swap/cnv-operatorgroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: kubevirt-hyperconverged-group
namespace: openshift-cnv
spec:
targetNamespaces:
- openshift-cnv
13 changes: 13 additions & 0 deletions test/extended/testdata/node/cnv-swap/cnv-subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: hco-operatorhub
namespace: openshift-cnv
spec:
source: redhat-operators
sourceNamespace: openshift-marketplace
name: kubevirt-hyperconverged
channel: "stable"
installPlanApproval: Automatic
# Uncomment to pin to a specific version:
# startingCSV: kubevirt-hyperconverged-operator.v4.17.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Kubelet drop-in configuration for LimitedSwap
# Place this file at: /etc/openshift/kubelet.conf.d/99-kubelet-limited-swap.conf
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
memorySwap:
swapBehavior: LimitedSwap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Malformed kubelet drop-in configuration for testing error handling
# This file has intentional syntax errors
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
memorySwap
swapBehavior LimitedSwap
invalid_field: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Kubelet drop-in configuration for NoSwap (default behavior)
# Place this file at: /etc/openshift/kubelet.conf.d/99-kubelet-no-swap.conf
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
memorySwap:
swapBehavior: NoSwap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MachineConfig to enable LimitedSwap on worker nodes via drop-in file
# Base64 encoded content of kubelet-limitedswap-dropin.yaml
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: worker
name: 99-cnv-kubelet-limited-swap
spec:
config:
ignition:
version: 3.2.0
storage:
directories:
- path: /etc/openshift/kubelet.conf.d
mode: 0755
overwrite: true
files:
- path: /etc/openshift/kubelet.conf.d/99-kubelet-limited-swap.conf
mode: 0644
overwrite: true
contents:
# Base64 encoded: apiVersion: kubelet.config.k8s.io/v1beta1\nkind: KubeletConfiguration\nmemorySwap:\n swapBehavior: LimitedSwap\n
source: data:text/plain;charset=utf-8;base64,YXBpVmVyc2lvbjoga3ViZWxldC5jb25maWcuazhzLmlvL3YxYmV0YTEKa2luZDogS3ViZWxldENvbmZpZ3VyYXRpb24KbWVtb3J5U3dhcDoKICBzd2FwQmVoYXZpb3I6IExpbWl0ZWRTd2FwCg==
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# MachineConfig to create the kubelet drop-in directory on worker nodes
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: worker
name: 99-cnv-kubelet-swap-dropin-dir
spec:
config:
ignition:
version: 3.2.0
storage:
directories:
- path: /etc/openshift/kubelet.conf.d
mode: 0755
overwrite: true