From d3cdea796655f37b6e5c6cbd96bc91cfac2f407e Mon Sep 17 00:00:00 2001 From: John Rowley Date: Fri, 23 Feb 2024 02:52:32 +0000 Subject: [PATCH] feature: added operator-sdk --- src/operator-sdk/README.md | 23 +++++++++++ src/operator-sdk/devcontainer-feature.json | 22 ++++++++++ src/operator-sdk/install.sh | 47 ++++++++++++++++++++++ test/operator-sdk/operatorsdk-v1.30.0.sh | 14 +++++++ test/operator-sdk/operatorsdk-v1.31.0.sh | 14 +++++++ test/operator-sdk/operatorsdk-v1.32.0.sh | 14 +++++++ test/operator-sdk/operatorsdk-v1.33.0.sh | 14 +++++++ test/operator-sdk/scenarios.json | 34 ++++++++++++++++ test/operator-sdk/test.sh | 47 ++++++++++++++++++++++ 9 files changed, 229 insertions(+) create mode 100644 src/operator-sdk/README.md create mode 100644 src/operator-sdk/devcontainer-feature.json create mode 100644 src/operator-sdk/install.sh create mode 100644 test/operator-sdk/operatorsdk-v1.30.0.sh create mode 100644 test/operator-sdk/operatorsdk-v1.31.0.sh create mode 100644 test/operator-sdk/operatorsdk-v1.32.0.sh create mode 100644 test/operator-sdk/operatorsdk-v1.33.0.sh create mode 100644 test/operator-sdk/scenarios.json create mode 100644 test/operator-sdk/test.sh diff --git a/src/operator-sdk/README.md b/src/operator-sdk/README.md new file mode 100644 index 000000000..335ca4491 --- /dev/null +++ b/src/operator-sdk/README.md @@ -0,0 +1,23 @@ + +# OperatorSDK (operator-sdk) + +A feature adding [operator-sdk](https://sdk.operatorframework.io/), a component of the [Operator Framework](https://github.com/operator-framework), an open source toolkit to manage kubernetes operators. + +## Example Usage + +```json +"features": { + "ghcr.io/robbert229/devcontainer-features/operator-sdk:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select the major version of postgres | string | v1.33.0 | + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/robbert229/devcontainer-features/blob/main/src/postgresql-client/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/operator-sdk/devcontainer-feature.json b/src/operator-sdk/devcontainer-feature.json new file mode 100644 index 000000000..69c08769d --- /dev/null +++ b/src/operator-sdk/devcontainer-feature.json @@ -0,0 +1,22 @@ +{ + "name": "OperatorSDK", + "id": "operator-sdk", + "version": "1.0.0", + "description": "A feature adding [operator-sdk](https://sdk.operatorframework.io/), a component of the [Operator Framework](https://github.com/operator-framework), an open source toolkit to manage kubernetes operators.", + "options": { + "version": { + "type": "string", + "proposals": [ + "v1.33.0", + "v1.32.0", + "v1.31.0", + "v1.30.0" + ], + "default": "v1.33.0", + "description": "Select the version of operator-sdk to install" + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/operator-sdk/install.sh b/src/operator-sdk/install.sh new file mode 100644 index 000000000..b0c55facd --- /dev/null +++ b/src/operator-sdk/install.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Maintainer: John Rowley + +set -e + +# Clean up +rm -rf /var/lib/apt/lists/* + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +# Ensure apt is in non-interactive to avoid prompts +export DEBIAN_FRONTEND=noninteractive + +# ensure that the required packages are installed +check_packages curl gpg ca-certificates + + +export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) +export OS=$(uname | awk '{print tolower($0)}') +export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/${VERSION} +curl -L -o ./operator-sdk ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} + +install ./operator-sdk /usr/local/bin/ + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" \ No newline at end of file diff --git a/test/operator-sdk/operatorsdk-v1.30.0.sh b/test/operator-sdk/operatorsdk-v1.30.0.sh new file mode 100644 index 000000000..7dbea36f2 --- /dev/null +++ b/test/operator-sdk/operatorsdk-v1.30.0.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "execute command" bash -c "operator-sdk version" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/operator-sdk/operatorsdk-v1.31.0.sh b/test/operator-sdk/operatorsdk-v1.31.0.sh new file mode 100644 index 000000000..7dbea36f2 --- /dev/null +++ b/test/operator-sdk/operatorsdk-v1.31.0.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "execute command" bash -c "operator-sdk version" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/operator-sdk/operatorsdk-v1.32.0.sh b/test/operator-sdk/operatorsdk-v1.32.0.sh new file mode 100644 index 000000000..7dbea36f2 --- /dev/null +++ b/test/operator-sdk/operatorsdk-v1.32.0.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "execute command" bash -c "operator-sdk version" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/operator-sdk/operatorsdk-v1.33.0.sh b/test/operator-sdk/operatorsdk-v1.33.0.sh new file mode 100644 index 000000000..7dbea36f2 --- /dev/null +++ b/test/operator-sdk/operatorsdk-v1.33.0.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "execute command" bash -c "operator-sdk version" + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/operator-sdk/scenarios.json b/test/operator-sdk/scenarios.json new file mode 100644 index 000000000..dbca399cc --- /dev/null +++ b/test/operator-sdk/scenarios.json @@ -0,0 +1,34 @@ +{ + "operatorsdk-v1.30.0": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "operator-sdk": { + "version":"v1.30.0" + } + } + }, + "operatorsdk-v1.31.0": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "operator-sdk": { + "version":"v1.31.0" + } + } + }, + "operatorsdk-v1.32.0": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "operator-sdk": { + "version":"v1.32.0" + } + } + }, + "operatorsdk-v1.33.0": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "operator-sdk": { + "version":"v1.33.0" + } + } + } +} diff --git a/test/operator-sdk/test.sh b/test/operator-sdk/test.sh new file mode 100644 index 000000000..248d98d19 --- /dev/null +++ b/test/operator-sdk/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# This test file will be executed against an auto-generated devcontainer.json that +# includes the 'hello' Feature with no options. +# +# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md +# +# Eg: +# { +# "image": "<..some-base-image...>", +# "features": { +# "hello": {} +# }, +# "remoteUser": "root" +# } +# +# Thus, the value of all options will fall back to the default value in +# the Feature's 'devcontainer-feature.json'. +# For the 'hello' feature, that means the default favorite greeting is 'hey'. +# +# These scripts are run as 'root' by default. Although that can be changed +# with the '--remote-user' flag. +# +# This test can be run with the following command: +# +# devcontainer features test \ +# --features hello \ +# --remote-user root \ +# --skip-scenarios \ +# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ +# /path/to/this/repo + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check