From d913c07a2a3e088487c1ff082f07eec0cb13afc5 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Fri, 26 Apr 2024 12:00:38 -0400 Subject: [PATCH] Update tests Signed-off-by: David Kwon --- .../creates-home-vm-when-enabled.yaml | 1 + ...es-initcontainer-from-first-component.yaml | 82 +++++++++++++++++++ .../creates-initcontainer-when-enabled.yaml | 68 +++++++++++++++ .../noop-if-home-vm-exists.yaml | 1 + .../noop-if-home-vm-name-used.yaml | 1 + .../noop-if-init-command-already-defined.yaml | 29 +++++++ ...oop-if-init-component-already-defined.yaml | 55 +++++++++++++ ...if-init-prestartevent-already-defined.yaml | 19 +++++ .../noop-if-no-components.yaml | 14 ++++ 9 files changed, 270 insertions(+) create mode 100644 pkg/library/home/testdata/persistent-home/creates-initcontainer-from-first-component.yaml create mode 100644 pkg/library/home/testdata/persistent-home/creates-initcontainer-when-enabled.yaml create mode 100644 pkg/library/home/testdata/persistent-home/noop-if-init-command-already-defined.yaml create mode 100644 pkg/library/home/testdata/persistent-home/noop-if-init-component-already-defined.yaml create mode 100644 pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml create mode 100644 pkg/library/home/testdata/persistent-home/noop-if-no-components.yaml diff --git a/pkg/library/home/testdata/persistent-home/creates-home-vm-when-enabled.yaml b/pkg/library/home/testdata/persistent-home/creates-home-vm-when-enabled.yaml index 973ab916d..091700216 100644 --- a/pkg/library/home/testdata/persistent-home/creates-home-vm-when-enabled.yaml +++ b/pkg/library/home/testdata/persistent-home/creates-home-vm-when-enabled.yaml @@ -6,6 +6,7 @@ input: workspace: persistUserHome: enabled: true + disableInitContainer: true workspace: components: - name: testing-container-1 diff --git a/pkg/library/home/testdata/persistent-home/creates-initcontainer-from-first-component.yaml b/pkg/library/home/testdata/persistent-home/creates-initcontainer-from-first-component.yaml new file mode 100644 index 000000000..60b5f8fbd --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/creates-initcontainer-from-first-component.yaml @@ -0,0 +1,82 @@ +name: "Creates init container from the first component when persistUserHome is enabled" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: testing-container-2 + container: + image: testing-image-2 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: my-defined-volume + volume: {} + +output: + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: persistent-home + path: /home/user/ + - name: testing-container-2 + container: + image: testing-image-2 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: persistent-home + path: /home/user/ + - name: my-defined-volume + volume: {} + - name: init-persistent-home + container: + image: testing-image-1 + volumeMounts: + - name: persistent-home + path: /home/user/ + command: + - /bin/sh + - -c + args: + - | + (echo "Checking for stow command" + STOW_COMPLETE=/home/user/.stow_completed + if command -v stow &> /dev/null; then + if [ ! -f $STOW_COMPLETE ]; then + echo "Running stow command" + stow . -t /home/user/ -d /home/tooling/ --no-folding -v 2 > /home/user/.stow.log 2>&1 + cp -n /home/tooling/.viminfo /home/user/.viminfo + cp -n /home/tooling/.bashrc /home/user/.bashrc + cp -n /home/tooling/.bash_profile /home/user/.bash_profile + touch $STOW_COMPLETE + else + echo "Stow command already run. If you wish to re-run it, delete $STOW_COMPLETE from the persistent volume and restart the workspace." + fi + else + echo "Stow command not found" + fi) || true + - name: persistent-home + volume: {} + commands: + - id: init-persistent-home + apply: + component: init-persistent-home + events: + prestart: + - init-persistent-home diff --git a/pkg/library/home/testdata/persistent-home/creates-initcontainer-when-enabled.yaml b/pkg/library/home/testdata/persistent-home/creates-initcontainer-when-enabled.yaml new file mode 100644 index 000000000..13e6a4bfa --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/creates-initcontainer-when-enabled.yaml @@ -0,0 +1,68 @@ +name: "Creates init container when persistUserHome is enabled" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: my-defined-volume + volume: {} + +output: + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: persistent-home + path: /home/user/ + - name: my-defined-volume + volume: {} + - name: init-persistent-home + container: + image: testing-image-1 + volumeMounts: + - name: persistent-home + path: /home/user/ + command: + - /bin/sh + - -c + args: + - | + (echo "Checking for stow command" + STOW_COMPLETE=/home/user/.stow_completed + if command -v stow &> /dev/null; then + if [ ! -f $STOW_COMPLETE ]; then + echo "Running stow command" + stow . -t /home/user/ -d /home/tooling/ --no-folding -v 2 > /home/user/.stow.log 2>&1 + cp -n /home/tooling/.viminfo /home/user/.viminfo + cp -n /home/tooling/.bashrc /home/user/.bashrc + cp -n /home/tooling/.bash_profile /home/user/.bash_profile + touch $STOW_COMPLETE + else + echo "Stow command already run. If you wish to re-run it, delete $STOW_COMPLETE from the persistent volume and restart the workspace." + fi + else + echo "Stow command not found" + fi) || true + - name: persistent-home + volume: {} + commands: + - id: init-persistent-home + apply: + component: init-persistent-home + events: + prestart: + - init-persistent-home diff --git a/pkg/library/home/testdata/persistent-home/noop-if-home-vm-exists.yaml b/pkg/library/home/testdata/persistent-home/noop-if-home-vm-exists.yaml index 36ba3fb35..dc896b4ab 100644 --- a/pkg/library/home/testdata/persistent-home/noop-if-home-vm-exists.yaml +++ b/pkg/library/home/testdata/persistent-home/noop-if-home-vm-exists.yaml @@ -6,6 +6,7 @@ input: workspace: persistUserHome: enabled: true + disableInitContainer: true workspace: components: - name: testing-container-1 diff --git a/pkg/library/home/testdata/persistent-home/noop-if-home-vm-name-used.yaml b/pkg/library/home/testdata/persistent-home/noop-if-home-vm-name-used.yaml index d7a886cab..5c406d365 100644 --- a/pkg/library/home/testdata/persistent-home/noop-if-home-vm-name-used.yaml +++ b/pkg/library/home/testdata/persistent-home/noop-if-home-vm-name-used.yaml @@ -6,6 +6,7 @@ input: workspace: persistUserHome: enabled: true + disableInitContainer: true workspace: components: - name: testing-container-1 diff --git a/pkg/library/home/testdata/persistent-home/noop-if-init-command-already-defined.yaml b/pkg/library/home/testdata/persistent-home/noop-if-init-command-already-defined.yaml new file mode 100644 index 000000000..e7af9fe45 --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/noop-if-init-command-already-defined.yaml @@ -0,0 +1,29 @@ +name: "Does not create persistent home volume if command with an id of 'init-persistent-home' is already defined" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + commands: + - id: init-persistent-home + apply: + component: testing-container-1 + +output: + error: "failed to add init container for home persistence setup: command with id init-persistent-home already exists in the devworkspace" + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + commands: + - id: init-persistent-home + apply: + component: testing-container-1 diff --git a/pkg/library/home/testdata/persistent-home/noop-if-init-component-already-defined.yaml b/pkg/library/home/testdata/persistent-home/noop-if-init-component-already-defined.yaml new file mode 100644 index 000000000..e56064647 --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/noop-if-init-component-already-defined.yaml @@ -0,0 +1,55 @@ +name: "Does not create persistent home volume if component named 'init-persistent-home' is already defined" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: my-defined-volume + volume: {} + - name: init-persistent-home + container: + image: testing-image-1 + command: + - echo helloworld + commands: + - id: init-persistent-home + apply: + component: init-persistent-home + events: + prestart: + - init-persistent-home + +output: + error: "failed to add init container for home persistence setup: component named init-persistent-home already exists in the devworkspace" + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + volumeMounts: + - name: my-defined-volume + path: /my-defined-volume-path + - name: my-defined-volume + volume: {} + - name: init-persistent-home + container: + image: testing-image-1 + command: + - echo helloworld + commands: + - id: init-persistent-home + apply: + component: init-persistent-home + events: + prestart: + - init-persistent-home diff --git a/pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml b/pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml new file mode 100644 index 000000000..33fd9f541 --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/noop-if-init-prestartevent-already-defined.yaml @@ -0,0 +1,19 @@ +name: "Does not create persistent home volume if prestart event with an id of 'init-persistent-home' is already defined" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + events: + prestart: + - init-persistent-home + +output: + error: "failed to add init container for home persistence setup: command with id init-persistent-home already exists in the devworkspace" + workspace: + events: + prestart: + - init-persistent-home diff --git a/pkg/library/home/testdata/persistent-home/noop-if-no-components.yaml b/pkg/library/home/testdata/persistent-home/noop-if-no-components.yaml new file mode 100644 index 000000000..f82bad9c5 --- /dev/null +++ b/pkg/library/home/testdata/persistent-home/noop-if-no-components.yaml @@ -0,0 +1,14 @@ +name: "No op if there are no components" + +input: + devworkspaceId: "test-workspaceid" + config: + workspace: + persistUserHome: + enabled: true + workspace: + components: [] + +output: + workspace: + components: []