diff --git a/.gitignore b/.gitignore index 05b8b568b8..fd1df87b5a 100644 --- a/.gitignore +++ b/.gitignore @@ -103,7 +103,6 @@ images/scorecard-test-kuttl/scorecard-test-kuttl # Test artifacts pkg/ansible/runner/testdata/valid.yaml /bin -test/test-framework/go.sum internal/scorecard/alpha/examples/custom-scorecard-tests/go.sum # Website diff --git a/.travis.yml b/.travis.yml index 071b7226cb..e31098fccc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -129,10 +129,12 @@ jobs: # Test subcommands - <<: *test - name: Subcommands on Kubernetes - script: make test-subcommand + name: Subcommands and Integration on Kubernetes + script: + - make test-subcommand + - make test-integration - # Build and test go + # Build and test go - <<: *test name: Go on Kubernetes before_script: @@ -140,7 +142,6 @@ jobs: script: - make test-unit - make test-e2e-go - - make test-integration after_success: - $GOPATH/bin/goveralls -service=travis-ci -coverprofile=coverage.out -repotoken=$COVERALLS_TOKEN @@ -216,7 +217,7 @@ jobs: - make image-build-helm - make image-push-helm - # Build and deploy arm64 scorecard-test docker image + # Build and deploy arm64 scorecard-test docker image - <<: *deploy name: Docker image for scorecard-test (arm64) arch: arm64 diff --git a/Makefile b/Makefile index 08765f9121..861e8d9455 100644 --- a/Makefile +++ b/Makefile @@ -96,16 +96,13 @@ setup-k8s: ##@ Generate -.PHONY: generate gen-cli-doc gen-test-framework gen-changelog +.PHONY: generate gen-cli-doc gen-changelog -generate: gen-cli-doc gen-test-framework ## Run all non-release generate targets +generate: gen-cli-doc ## Run all non-release generate targets gen-cli-doc: ## Generate CLI documentation ./hack/generate/cli-doc/gen-cli-doc.sh -gen-test-framework: build/operator-sdk ## Run generate commands to update test/test-framework - ./hack/generate/test-framework/gen-test-framework.sh - gen-changelog: ## Generate CHANGELOG.md and migration guide updates ./hack/generate/changelog/gen-changelog.sh @@ -269,8 +266,6 @@ test-ci: test-sanity test-unit install test-subcommand test-e2e ## Run the CI te .PHONY: test-subcommand test-subcommand-olm-install test-subcommand: test-subcommand-olm-install - ./hack/tests/subcommand-bundle.sh - ./hack/tests/subcommand-generate-csv.sh test-subcommand-olm-install: ./hack/tests/subcommand-olm-install.sh diff --git a/hack/ci/setup-build-dependencies.sh b/hack/ci/setup-build-dependencies.sh deleted file mode 100755 index 98e97392e1..0000000000 --- a/hack/ci/setup-build-dependencies.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# No-op since the release:golang-1.13 base image currently has all required -# depedencies to build and test operator-sdk. -# -# TODO: pre-fetch modules here with `make tidy` and figure out permissions -# issues in unit and sanity tests -# make tidy - - diff --git a/hack/ci/setup-k8s.sh b/hack/ci/setup-k8s.sh index 3e14e94474..9688594ea7 100755 --- a/hack/ci/setup-k8s.sh +++ b/hack/ci/setup-k8s.sh @@ -2,18 +2,15 @@ set -eux -# This image tag corresponds to a Kubernetes version that kind installs using -# images at: +source hack/lib/common.sh + +# This image tag corresponds to a Kubernetes version that kind installs using node images: # https://hub.docker.com/r/kindest/node/tags K8S_VERSION=$1 -KIND_VERSION="v0.8.1" KIND_IMAGE="docker.io/kindest/node:${K8S_VERSION}" -# Download the latest version of kind, which supports all versions of -# Kubernetes v1.11+. -curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 -chmod +x kind -sudo mv kind /usr/local/bin/ +# Download the latest version of kind, which supports all versions of Kubernetes v1.11+. +install_kind /usr/local # Create a cluster of version $K8S_VERSION. kind create cluster --image="$KIND_IMAGE" diff --git a/hack/generate/test-framework/gen-test-framework.sh b/hack/generate/test-framework/gen-test-framework.sh deleted file mode 100755 index 1303c1e735..0000000000 --- a/hack/generate/test-framework/gen-test-framework.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -############################# -# Make sure that test/test-framework is updated according to the current source code -############################# - -set -ex - -source hack/lib/test_lib.sh - -# Go inside of the mock data test project -cd test/test-framework - -sed -i".bak" -E -e "/github.com\/operator-framework\/operator-sdk .+/d" go.mod; rm -f go.mod.bak -echo -e "\nreplace github.com/operator-framework/operator-sdk => ../../" >> go.mod -go mod edit -require "github.com/operator-framework/operator-sdk@v0.0.0" -go build ./... -go mod tidy diff --git a/hack/lib/common.sh b/hack/lib/common.sh index 83dc6315f6..6528fb9398 100644 --- a/hack/lib/common.sh +++ b/hack/lib/common.sh @@ -74,7 +74,6 @@ function prepare_staging_dir { function fetch_tools { if [[ -z "$SKIP_FETCH_TOOLS" ]]; then fetch_envtest_tools $@ - install_kind $@ fi } diff --git a/hack/lib/test_lib.sh b/hack/lib/test_lib.sh index 51957ab225..3c29cac3bd 100644 --- a/hack/lib/test_lib.sh +++ b/hack/lib/test_lib.sh @@ -42,34 +42,6 @@ function trap_add() { done } -# add_go_mod_replace adds a "replace" directive from $1 to $2 with an -# optional version version $3 to the current working directory's go.mod file. -function add_go_mod_replace() { - local from_path="${1:?first path in replace statement is required}" - local to_path="${2:?second path in replace statement is required}" - local version="${3:-}" - - if [[ ! -d "$to_path" && -z "$version" ]]; then - echo "second replace path $to_path requires a version be set because it is not a directory" - exit 1 - fi - if [[ ! -e go.mod ]]; then - echo "go.mod file not found in $(pwd)" - exit 1 - fi - - # Check if a replace line already exists. If it does, remove. If not, append. - if grep -q "${from_path} =>" go.mod; then - sed -E -i 's|^.+'"${from_path} =>"'.+$||g' go.mod - fi - # Do not use "go mod edit" so formatting stays the same. - local replace="replace ${from_path} => ${to_path}" - if [[ -n "$version" ]]; then - replace="$replace $version" - fi - echo "$replace" >> go.mod -} - # check_dir accepts 3 args: # 1: test case string # 2: directory to test for existence diff --git a/hack/tests/e2e-go.sh b/hack/tests/e2e-go.sh index 69434d1407..83db91d4a4 100755 --- a/hack/tests/e2e-go.sh +++ b/hack/tests/e2e-go.sh @@ -18,7 +18,6 @@ fetch_tools $tmp_sdk_root # These envtest environment variables are required for the default unit tests # scaffolded in the test operator project. No e2e tests currently use envtest. setup_envs $tmp_sdk_root -build_sdk $tmp_sdk_root kubectl cluster-info diff --git a/hack/tests/integration.sh b/hack/tests/integration.sh index 05b9813621..4c47f9615a 100755 --- a/hack/tests/integration.sh +++ b/hack/tests/integration.sh @@ -2,15 +2,34 @@ set -eu +source hack/lib/common.sh +source hack/lib/test_lib.sh source hack/lib/image_lib.sh -export OSDK_INTEGRATION_IMAGE="quay.io/example/memcached-operator:latest" +TMPDIR="$(mktemp -d memcached-XXXX)" +trap_add 'rm -rf $TMPDIR' EXIT -# Build the operator image. -pushd test/test-framework -operator-sdk build "$OSDK_INTEGRATION_IMAGE" -# If using a kind cluster, load the image into all nodes. +pushd "$TMPDIR" + +# TODO: remove these setup steps if/when `create api --make=false` is added. +# These tools are required to run envtest tests, which are always run by `make`. +prepare_staging_dir $tmp_sdk_root +fetch_tools $tmp_sdk_root +setup_envs $tmp_sdk_root + +header_text "Initializing test project" + +# Initialize a basic memcached-operator project +operator-sdk init --repo github.com/example/memcached-operator --domain example.com --fetch-deps=false +operator-sdk create api --group cache --version v1alpha1 --kind Memcached --controller --resource +sed -i 's@Foo string `json:"foo,omitempty"`@// +optional\ + Count int `json:"count,omitempty"`@' api/v1alpha1/memcached_types.go + +# Build the operator's image. +export OSDK_INTEGRATION_IMAGE="quay.io/example/memcached-operator:integration" +make docker-build IMG="$OSDK_INTEGRATION_IMAGE" load_image_if_kind "$OSDK_INTEGRATION_IMAGE" + popd # Install OLM on the cluster if not installed. @@ -20,13 +39,17 @@ if ! operator-sdk olm status > /dev/null 2>&1; then olm_latest_exists=1 fi -# Integration tests will use default loading rules for the kubeconfig if -# KUBECONFIG is not set. +docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 +load_image_if_kind gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 + +header_text "Running integration tests" + +# Integration tests will use default loading rules for the kubeconfig if KUBECONFIG is not set. go test -v ./test/integration +header_text "Integration tests succeeded" + # Uninstall OLM if it was installed for test purposes. if eval "(( $olm_latest_exists ))"; then operator-sdk olm uninstall fi - -echo -e "\n=== Integration tests succeeded ===\n" diff --git a/hack/tests/sanity-check.sh b/hack/tests/sanity-check.sh index d68d0c2290..f09fd04c64 100755 --- a/hack/tests/sanity-check.sh +++ b/hack/tests/sanity-check.sh @@ -8,7 +8,6 @@ go fmt ./... ./hack/check-license.sh ./hack/check-error-log-msg-format.sh ./hack/generate/cli-doc/gen-cli-doc.sh -./hack/generate/test-framework/gen-test-framework.sh go run ./hack/generate/changelog/gen-changelog.go -validate-only # Make sure repo is still in a clean state. diff --git a/hack/tests/subcommand-bundle.sh b/hack/tests/subcommand-bundle.sh deleted file mode 100755 index 9d0f365c9b..0000000000 --- a/hack/tests/subcommand-bundle.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash - -source hack/lib/test_lib.sh - -function cleanup_case() { - git clean -dfxq . -} - -TEST_DIR="test/test-framework" -OPERATOR_NAME="memcached-operator" -OPERATOR_VERSION_1="0.0.2" -OPERATOR_VERSION_2="0.0.3" -OPERATOR_BUNDLE_IMAGE_2="quay.io/example/${OPERATOR_NAME}:${OPERATOR_VERSION_2}" -OPERATOR_ROOT_DIR="deploy/olm-catalog/${OPERATOR_NAME}" -OPERATOR_PACKAGE_MANIFEST_DIR_1="${OPERATOR_ROOT_DIR}/${OPERATOR_VERSION_1}" -OPERATOR_PACKAGE_MANIFEST_DIR_2="${OPERATOR_ROOT_DIR}/${OPERATOR_VERSION_2}" -OPERATOR_BUNDLE_MANIFESTS_DIR="${OPERATOR_ROOT_DIR}/manifests" -OPERATOR_BUNDLE_METADATA_DIR="${OPERATOR_ROOT_DIR}/metadata" -OUTPUT_DIR="foo" - -function create() { - echo_run operator-sdk bundle create $1 --directory $2 --package $OPERATOR_NAME ${@:3} -} - -function generate() { - echo_run operator-sdk bundle create --generate-only --directory $1 --package $OPERATOR_NAME ${@:2} -} - -function check_validate_pass() { - if ! operator-sdk bundle validate $2 ${@:3}; then - error_text "${1}: validate failed" - exit 1 - fi -} - -function check_validate_fail() { - if operator-sdk bundle validate $2 ${@:3}; then - error_text "${1}: validate passed" - exit 1 - fi -} - -pushd "$TEST_DIR" -trap_add "git clean -dfxq $TEST_DIR" EXIT -trap_add "popd" EXIT - -set -e - -header_text "Running 'operator-sdk bundle' subcommand tests." - -TEST_NAME="create with version ${OPERATOR_VERSION_2}" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -create $OPERATOR_BUNDLE_IMAGE_2 "$OPERATOR_BUNDLE_MANIFESTS_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 0 -check_file "$TEST_NAME" "bundle.Dockerfile" 0 -cleanup_case - -TEST_NAME="create with version ${OPERATOR_VERSION_2} and output-dir" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -create $OPERATOR_BUNDLE_IMAGE_2 "$OPERATOR_BUNDLE_MANIFESTS_DIR" --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "${OUTPUT_DIR}/manifests" 1 -check_dir "$TEST_NAME" "${OUTPUT_DIR}/metadata" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 0 -check_file "$TEST_NAME" "bundle.Dockerfile" 0 -check_validate_pass "$TEST_NAME" "$OUTPUT_DIR" -cleanup_case - -TEST_NAME="generate with version ${OPERATOR_VERSION_2}" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -check_validate_pass "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -TEST_NAME="generate with version ${OPERATOR_VERSION_2} and output-dir" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "${OUTPUT_DIR}/manifests" 1 -check_dir "$TEST_NAME" "${OUTPUT_DIR}/metadata" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 0 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -check_validate_pass "$TEST_NAME" "$OUTPUT_DIR" -cleanup_case - -TEST_NAME="create with version ${OPERATOR_VERSION_2} with existing metadata" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -create $OPERATOR_BUNDLE_IMAGE_2 "$OPERATOR_BUNDLE_MANIFESTS_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -check_validate_pass "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -TEST_NAME="create with version ${OPERATOR_VERSION_2} with existing metadata and output-dir" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -create $OPERATOR_BUNDLE_IMAGE_2 "$OPERATOR_BUNDLE_MANIFESTS_DIR" --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "${OUTPUT_DIR}/manifests" 1 -check_dir "$TEST_NAME" "${OUTPUT_DIR}/metadata" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -check_validate_pass "$TEST_NAME" "$OUTPUT_DIR" -check_validate_pass "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -TEST_NAME="create with version ${OPERATOR_VERSION_2} with existing manifests/metadata version ${OPERATOR_VERSION_1} and overwrite" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -create $OPERATOR_BUNDLE_IMAGE_2 "$OPERATOR_BUNDLE_MANIFESTS_DIR" --overwrite -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -check_validate_pass "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -TEST_NAME="error on validate invalid generated bundle content with version ${OPERATOR_VERSION_2}" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -# Change version to an invalid value. -sed -i 's/version: '$OPERATOR_VERSION_2'/version: a.b.c/g' "${OPERATOR_BUNDLE_MANIFESTS_DIR}"/*.clusterserviceversion.yaml -check_validate_fail "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -TEST_NAME="error on validate invalid generated bundle format with version ${OPERATOR_VERSION_2}" -header_text "$TEST_NAME" -cp -r "$OPERATOR_PACKAGE_MANIFEST_DIR_2" "$OPERATOR_BUNDLE_MANIFESTS_DIR" -generate "$OPERATOR_BUNDLE_MANIFESTS_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_MANIFESTS_DIR" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_METADATA_DIR" 1 -# Change annotations mediatype to the incorrect type. -sed -i 's/mediatype.v1: registry+v1/mediatype.v1: plain/g' "${OPERATOR_BUNDLE_METADATA_DIR}/annotations.yaml" -check_validate_fail "$TEST_NAME" "$OPERATOR_ROOT_DIR" -cleanup_case - -header_text "All 'operator-sdk bundle' subcommand tests passed." diff --git a/hack/tests/subcommand-generate-csv.sh b/hack/tests/subcommand-generate-csv.sh deleted file mode 100755 index d066dfe09d..0000000000 --- a/hack/tests/subcommand-generate-csv.sh +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bash - -set -ee - -source hack/lib/test_lib.sh - -function cleanup_case() { - git clean -dfxq . && git checkout -q . -} - -TEST_DIR="test/test-framework" -OPERATOR_NAME="memcached-operator" -OPERATOR_VERSION="0.0.4" -OPERATOR_BUNDLE_ROOT_DIR="deploy/olm-catalog/${OPERATOR_NAME}" -DEFAULT_BUNDLE_DIR="${OPERATOR_BUNDLE_ROOT_DIR}/${OPERATOR_VERSION}" -OUTPUT_DIR="foo" -OUTPUT_BUNDLE_ROOT_DIR="${OUTPUT_DIR}/olm-catalog/${OPERATOR_NAME}" -OUTPUT_BUNDLE_DIR="${OUTPUT_BUNDLE_ROOT_DIR}/${OPERATOR_VERSION}" - -function check_csv_file_legacy() { - check_file "$1" "${2}/${OPERATOR_NAME}.v${OPERATOR_VERSION}.clusterserviceversion.yaml" $3 -} - -function check_csv_file() { - check_file "$1" "${2}/${OPERATOR_NAME}.clusterserviceversion.yaml" $3 -} - -function check_package_file() { - check_file "$1" "${2}/${OPERATOR_NAME}.package.yaml" $3 -} - -function check_crd_files() { - local memcacheds_crd_file="${2}/cache.example.com_memcacheds_crd.yaml" - local memcachedrs_crd_file="${2}/cache.example.com_memcachedrs_crd.yaml" - for file in $memcacheds_crd_file $memcachedrs_crd_file; do check_file "$1" "$file" $3; done -} - -function generate_csv() { - echo_run operator-sdk generate csv --operator-name $OPERATOR_NAME --interactive=false $@ -} - -function generate_bundle() { - echo_run operator-sdk generate bundle --operator-name $OPERATOR_NAME --interactive=false $@ -} - -function generate_packagemanifests() { - echo_run operator-sdk generate packagemanifests --operator-name $OPERATOR_NAME --interactive=false $@ -} - -pushd "$TEST_DIR" > /dev/null -trap_add "git clean -dfxq $TEST_DIR" EXIT -trap_add "popd > /dev/null" EXIT - -header_text "Running 'operator-sdk generate csv' subcommand tests in $TEST_DIR." - -TEST_NAME="generate with version $OPERATOR_VERSION" -header_text "$TEST_NAME" -generate_csv --make-manifests=false --csv-version $OPERATOR_VERSION -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 1 -check_csv_file_legacy "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 1 -check_crd_files "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and output-dir" -header_text "$TEST_NAME" -generate_csv --make-manifests=false --csv-version $OPERATOR_VERSION --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 1 -check_csv_file_legacy "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 1 -check_crd_files "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 0 -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and output-dir, update-crds" -header_text "$TEST_NAME" -generate_csv --make-manifests=false --csv-version $OPERATOR_VERSION --output-dir "$OUTPUT_DIR" --update-crds -check_dir "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 1 -check_csv_file_legacy "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 1 -check_crd_files "$TEST_NAME" "$OUTPUT_BUNDLE_DIR" 1 -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and make-manifests" -header_text "$TEST_NAME" -generate_csv --csv-version $OPERATOR_VERSION -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_csv_file "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_crd_files "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and output-dir, make-manifests" -header_text "$TEST_NAME" -generate_csv --csv-version $OPERATOR_VERSION --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 0 -check_dir "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -check_csv_file "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -check_crd_files "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -cleanup_case - -header_text "All 'operator-sdk generate csv' subcommand tests passed." - -header_text "Running 'operator-sdk generate bundle' subcommand tests in $TEST_DIR." - -TEST_NAME="generate with version $OPERATOR_VERSION" -header_text "$TEST_NAME" -generate_bundle --version $OPERATOR_VERSION -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/metadata" 1 -check_csv_file "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_crd_files "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -cleanup_case - -TEST_NAME="generate manifests only with version $OPERATOR_VERSION" -header_text "$TEST_NAME" -generate_bundle --version $OPERATOR_VERSION --manifests -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 0 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/metadata" 0 -check_csv_file "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_crd_files "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 0 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and output-dir" -header_text "$TEST_NAME" -generate_bundle --version $OPERATOR_VERSION --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR/manifests" 0 -check_dir "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -check_dir "$TEST_NAME" "$OUTPUT_DIR/metadata" 1 -check_csv_file "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -check_crd_files "$TEST_NAME" "$OUTPUT_DIR/manifests" 1 -check_file "$TEST_NAME" "bundle.Dockerfile" 1 -cleanup_case - -header_text "All 'operator-sdk generate bundle' subcommand tests passed." - -header_text "Running 'operator-sdk generate packagemanifests' subcommand tests in $TEST_DIR." - -TEST_NAME="generate with version $OPERATOR_VERSION" -header_text "$TEST_NAME" -generate_packagemanifests --version $OPERATOR_VERSION -check_dir "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 1 -check_package_file "$TEST_NAME" "$OPERATOR_BUNDLE_ROOT_DIR" 1 -check_csv_file "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 1 -check_crd_files "$TEST_NAME" "$DEFAULT_BUNDLE_DIR" 1 -cleanup_case - -TEST_NAME="generate with version $OPERATOR_VERSION and output-dir" -header_text "$TEST_NAME" -generate_packagemanifests --version $OPERATOR_VERSION --output-dir "$OUTPUT_DIR" -check_dir "$TEST_NAME" "${OUTPUT_DIR}/${OPERATOR_VERSION}" 1 -check_package_file "$TEST_NAME" "$OUTPUT_DIR" 1 -check_csv_file "$TEST_NAME" "${OUTPUT_DIR}/${OPERATOR_VERSION}" 1 -check_crd_files "$TEST_NAME" "${OUTPUT_DIR}/${OPERATOR_VERSION}" 1 -cleanup_case - -header_text "All 'operator-sdk generate packagemanifests' subcommand tests passed." diff --git a/test/integration/integration_helpers.go b/test/integration/integration_helpers.go index bc0989a842..51ca18db3e 100644 --- a/test/integration/integration_helpers.go +++ b/test/integration/integration_helpers.go @@ -80,83 +80,121 @@ spec: displayName: {{ .OperatorName }} Application install: spec: + clusterPermissions: + - rules: + {{- range $i, $crd := .CRDKeys }} + - apiGroups: + - {{ $crd.Group }} + resources: + - {{ $crd.Kind | tolower }}s + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - {{ $crd.Group }} + resources: + - {{ $crd.Kind | tolower }}s/status + verbs: + - get + - patch + - update + {{- end}} + serviceAccountName: {{ .OperatorName }}-manager-role + - rules: + - apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create + - apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create + serviceAccountName: {{ .OperatorName }}-proxy-role + - rules: + - nonResourceURLs: + - /metrics + verbs: + - get + serviceAccountName: {{ .OperatorName }}-metrics-reader deployments: - - name: {{ .OperatorName }} + - name: {{ .OperatorName }}-controller-manager spec: replicas: 1 selector: matchLabels: - name: {{ .OperatorName }} + control-plane: controller-manager strategy: {} template: metadata: labels: - name: {{ .OperatorName }} + control-plane: controller-manager spec: containers: - - command: - - {{ .OperatorName }} - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.annotations['olm.targetNamespaces'] - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: {{ .OperatorName }} - image: {{ .TestImageTag }} - imagePullPolicy: Never - name: {{ .OperatorName }} + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=10 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https resources: {} - serviceAccountName: {{ .OperatorName }} + - args: + - --metrics-addr=127.0.0.1:8080 + - --enable-leader-election + command: + - /manager + image: {{ .TestImageTag }} + name: manager + resources: + limits: + cpu: 100m + memory: 30Mi + requests: + cpu: 100m + memory: 20Mi + terminationGracePeriodSeconds: 10 permissions: - rules: - apiGroups: - "" resources: - - pods - - services - - endpoints - - persistentvolumeclaims - - events - configmaps - - secrets verbs: - - '*' + - get + - list + - watch + - create + - update + - patch + - delete - apiGroups: - "" resources: - - namespaces + - configmaps/status verbs: - get + - update + - patch - apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - '*' - - apiGroups: - - monitoring.coreos.com + - "" resources: - - servicemonitors + - events verbs: - - get - create - - apiGroups: - - apps - resourceNames: - - {{ .OperatorName }} - resources: - - deployments/finalizers - verbs: - - update - serviceAccountName: {{ .OperatorName }} + - patch + serviceAccountName: {{ .OperatorName }}-leader-election-role strategy: deployment installModes: {{- range $i, $mode := .InstallModes }} @@ -195,18 +233,12 @@ func writeOperatorManifests(dir string, csvConfig CSVTemplateConfig) error { Versions: key.Versions, }, } - crdPath := filepath.Join(manifestDir, fmt.Sprintf("%s.crd.yaml", key.Name)) + crdPath := filepath.Join(manifestDir, fmt.Sprintf("%s_%ss.yaml", key.Name, strings.ToLower(key.Kind))) if err := writeManifest(crdPath, crd); err != nil { return err } } - csvPath := "" - if csvConfig.IsBundle { - csvPath = filepath.Join(manifestDir, fmt.Sprintf("%s.csv.yaml", csvConfig.OperatorName)) - } else { - csvPath = filepath.Join(manifestDir, fmt.Sprintf("%s.v%s.csv.yaml", - csvConfig.OperatorName, csvConfig.OperatorVersion)) - } + csvPath := filepath.Join(manifestDir, fmt.Sprintf("%s.clusterserviceversion.yaml", csvConfig.OperatorName)) if err := execTemplateOnFile(csvPath, csvTmpl, csvConfig); err != nil { return err } @@ -243,8 +275,11 @@ func execTemplateOnFile(path, tmplStr string, o interface{}) error { return err } defer w.Close() - tmpl, err := template.New(path).Parse(tmplStr) - if err != nil { + + tmpl := template.New(path).Funcs(map[string]interface{}{ + "tolower": strings.ToLower, + }) + if tmpl, err = tmpl.Parse(tmplStr); err != nil { return err } return tmpl.Execute(w, o) diff --git a/test/integration/operator_olm_test.go b/test/integration/operator_olm_test.go index c13dfc79de..f6d6bb4986 100644 --- a/test/integration/operator_olm_test.go +++ b/test/integration/operator_olm_test.go @@ -42,6 +42,8 @@ var ( kubeconfigPath = os.Getenv(k8sutil.KubeConfigEnvVar) ) +// TODO(estroz): rewrite these in the style of e2e tests (ginkgo/gomega + scaffold a project for each scenario). + func TestOLMIntegration(t *testing.T) { if image, ok := os.LookupEnv(imageEnvVar); ok && image != "" { testImageTag = image diff --git a/test/test-framework/.osdk-scorecard-bundle.yaml b/test/test-framework/.osdk-scorecard-bundle.yaml deleted file mode 100644 index bf19f7eab5..0000000000 --- a/test/test-framework/.osdk-scorecard-bundle.yaml +++ /dev/null @@ -1,11 +0,0 @@ -scorecard: - version: v1alpha2 - bundle: deploy/olm-catalog/memcached-operator - plugins: - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" diff --git a/test/test-framework/.osdk-scorecard-ci.yaml b/test/test-framework/.osdk-scorecard-ci.yaml deleted file mode 100644 index 333333faf0..0000000000 --- a/test/test-framework/.osdk-scorecard-ci.yaml +++ /dev/null @@ -1,17 +0,0 @@ -scorecard: - output: json - plugins: - - basic: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: REPLACE_IMAGE - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: REPLACE_IMAGE diff --git a/test/test-framework/.osdk-scorecard-invalid.yaml b/test/test-framework/.osdk-scorecard-invalid.yaml deleted file mode 100644 index b326ef73e1..0000000000 --- a/test/test-framework/.osdk-scorecard-invalid.yaml +++ /dev/null @@ -1,12 +0,0 @@ -scorecard: - output: json - plugins: - - basic: - invalid-option: "this is not correct" - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" diff --git a/test/test-framework/.osdk-scorecard-v1alpha2.yaml b/test/test-framework/.osdk-scorecard-v1alpha2.yaml deleted file mode 100644 index e47e288409..0000000000 --- a/test/test-framework/.osdk-scorecard-v1alpha2.yaml +++ /dev/null @@ -1,19 +0,0 @@ -scorecard: - version: v1alpha2 - plugins: - - basic: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" diff --git a/test/test-framework/.osdk-scorecard.yaml b/test/test-framework/.osdk-scorecard.yaml deleted file mode 100644 index c55246cc85..0000000000 --- a/test/test-framework/.osdk-scorecard.yaml +++ /dev/null @@ -1,19 +0,0 @@ -scorecard: - output: json - plugins: - - basic: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" diff --git a/test/test-framework/.test-osdk-scorecard-ci.yaml b/test/test-framework/.test-osdk-scorecard-ci.yaml deleted file mode 100644 index 99edfc824e..0000000000 --- a/test/test-framework/.test-osdk-scorecard-ci.yaml +++ /dev/null @@ -1,16 +0,0 @@ -scorecard: - plugins: - - basic: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: REPLACE_IMAGE - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: REPLACE_IMAGE diff --git a/test/test-framework/.test-osdk-scorecard.yaml b/test/test-framework/.test-osdk-scorecard.yaml deleted file mode 100644 index 4d357b29cf..0000000000 --- a/test/test-framework/.test-osdk-scorecard.yaml +++ /dev/null @@ -1,18 +0,0 @@ -scorecard: - plugins: - - basic: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" - - olm: - cr-manifest: - - "deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml" - - "deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml" - init-timeout: 60 - csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml" - proxy-image: "quay.io/example/scorecard-proxy" - proxy-pull-policy: "Never" diff --git a/test/test-framework/build/Dockerfile b/test/test-framework/build/Dockerfile deleted file mode 100644 index dfee3c4c36..0000000000 --- a/test/test-framework/build/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM registry.access.redhat.com/ubi8/ubi-minimal:latest - -ENV OPERATOR=/usr/local/bin/memcached-operator \ - USER_UID=1001 \ - USER_NAME=memcached-operator - -# install operator binary -COPY build/_output/bin/test-framework ${OPERATOR} - -COPY build/bin /usr/local/bin -RUN /usr/local/bin/user_setup - -ENTRYPOINT ["/usr/local/bin/entrypoint"] - -USER ${USER_UID} diff --git a/test/test-framework/build/bin/entrypoint b/test/test-framework/build/bin/entrypoint deleted file mode 100755 index 89cf2d587b..0000000000 --- a/test/test-framework/build/bin/entrypoint +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -e - -# This is documented here: -# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines - -if ! whoami &>/dev/null; then - if [ -w /etc/passwd ]; then - echo "${USER_NAME:-memcached-operator}:x:$(id -u):$(id -g):${USER_NAME:-memcached-operator} user:${HOME}:/sbin/nologin" >> /etc/passwd - fi -fi - -exec ${OPERATOR} $@ diff --git a/test/test-framework/build/bin/user_setup b/test/test-framework/build/bin/user_setup deleted file mode 100755 index 9cf9ea3e76..0000000000 --- a/test/test-framework/build/bin/user_setup +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -set -x - -# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be) -mkdir -p "${HOME}" -chown "${USER_UID}:0" "${HOME}" -chmod ug+rwx "${HOME}" - -# runtime user will need to be able to self-insert in /etc/passwd -chmod g+rw /etc/passwd - -# no need for this script to remain in the image after running -rm "$0" diff --git a/test/test-framework/cmd/manager/main.go b/test/test-framework/cmd/manager/main.go deleted file mode 100644 index 40a3fc642e..0000000000 --- a/test/test-framework/cmd/manager/main.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "context" - "errors" - "flag" - "fmt" - "os" - "runtime" - "sigs.k8s.io/controller-runtime/pkg/cache" - "strings" - - // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) - _ "k8s.io/client-go/plugin/pkg/client/auth" - "k8s.io/client-go/rest" - - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis" - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/controller" - - "github.com/operator-framework/operator-sdk/pkg/k8sutil" - kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics" - "github.com/operator-framework/operator-sdk/pkg/leader" - "github.com/operator-framework/operator-sdk/pkg/log/zap" - "github.com/operator-framework/operator-sdk/pkg/metrics" - sdkVersion "github.com/operator-framework/operator-sdk/version" - "github.com/spf13/pflag" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/controller-runtime/pkg/client/config" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" -) - -// Change below variables to serve metrics on different host or port. -var ( - metricsHost = "0.0.0.0" - metricsPort int32 = 8383 - operatorMetricsPort int32 = 8686 -) -var log = logf.Log.WithName("cmd") - -func printVersion() { - log.Info(fmt.Sprintf("Go Version: %s", runtime.Version())) - log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)) - log.Info(fmt.Sprintf("Version of operator-sdk: %v", sdkVersion.Version)) -} - -func main() { - // Add the zap logger flag set to the CLI. The flag set must - // be added before calling pflag.Parse(). - pflag.CommandLine.AddFlagSet(zap.FlagSet()) - - // Add flags registered by imported packages (e.g. glog and - // controller-runtime) - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - - pflag.Parse() - - // Use a zap logr.Logger implementation. If none of the zap - // flags are configured (or if the zap flag set is not being - // used), this defaults to a production zap logger. - // - // The logger instantiated here can be changed to any logger - // implementing the logr.Logger interface. This logger will - // be propagated through the whole operator, generating - // uniform and structured logs. - logf.SetLogger(zap.Logger()) - - printVersion() - - namespace, err := k8sutil.GetWatchNamespace() - if err != nil { - log.Error(err, "Failed to get watch namespace") - os.Exit(1) - } - - // Get a config to talk to the apiserver - cfg, err := config.GetConfig() - if err != nil { - log.Error(err, "") - os.Exit(1) - } - - ctx := context.TODO() - // Become the leader before proceeding - err = leader.Become(ctx, "memcached-operator-lock") - if err != nil { - log.Error(err, "") - os.Exit(1) - } - - // Set default manager options - options := manager.Options{ - Namespace: namespace, - MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort), - } - - // Add support for MultiNamespace set in WATCH_NAMESPACE (e.g ns1,ns2) - // Note that this is not intended to be used for excluding namespaces, this is better done via a Predicate - // Also note that you may face performance issues when using this with a high number of namespaces. - // More Info: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder - if strings.Contains(namespace, ",") { - options.Namespace = "" - options.NewCache = cache.MultiNamespacedCacheBuilder(strings.Split(namespace, ",")) - } - - // Create a new manager to provide shared dependencies and start components - mgr, err := manager.New(cfg, options) - if err != nil { - log.Error(err, "") - os.Exit(1) - } - - log.Info("Registering Components.") - - // Setup Scheme for all resources - if err := apis.AddToScheme(mgr.GetScheme()); err != nil { - log.Error(err, "") - os.Exit(1) - } - - // Setup all Controllers - if err := controller.AddToManager(mgr); err != nil { - log.Error(err, "") - os.Exit(1) - } - - // Add the Metrics Service - addMetrics(ctx, cfg) - - log.Info("Starting the Cmd.") - - // Start the Cmd - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - log.Error(err, "Manager exited non-zero") - os.Exit(1) - } -} - -// addMetrics will create the Services and Service Monitors to allow the operator export the metrics by using -// the Prometheus operator -func addMetrics(ctx context.Context, cfg *rest.Config) { - // Get the namespace the operator is currently deployed in. - operatorNs, err := k8sutil.GetOperatorNamespace() - if err != nil { - if errors.Is(err, k8sutil.ErrRunLocal) { - log.Info("Skipping CR metrics server creation; not running in a cluster.") - return - } - } - - if err := serveCRMetrics(cfg, operatorNs); err != nil { - log.Info("Could not generate and serve custom resource metrics", "error", err.Error()) - } - - // Add to the below struct any other metrics ports you want to expose. - servicePorts := []v1.ServicePort{ - {Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}}, - {Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}}, - } - - // Create Service object to expose the metrics port(s). - service, err := metrics.CreateMetricsService(ctx, cfg, servicePorts) - if err != nil { - log.Info("Could not create metrics Service", "error", err.Error()) - } - - // CreateServiceMonitors will automatically create the prometheus-operator ServiceMonitor resources - // necessary to configure Prometheus to scrape metrics from this operator. - services := []*v1.Service{service} - - // The ServiceMonitor is created in the same namespace where the operator is deployed - _, err = metrics.CreateServiceMonitors(cfg, operatorNs, services) - if err != nil { - log.Info("Could not create ServiceMonitor object", "error", err.Error()) - // If this operator is deployed to a cluster without the prometheus-operator running, it will return - // ErrServiceMonitorNotPresent, which can be used to safely skip ServiceMonitor creation. - if err == metrics.ErrServiceMonitorNotPresent { - log.Info("Install prometheus-operator in your cluster to create ServiceMonitor objects", "error", err.Error()) - } - } -} - -// serveCRMetrics gets the Operator/CustomResource GVKs and generates metrics based on those types. -// It serves those metrics on "http://metricsHost:operatorMetricsPort". -func serveCRMetrics(cfg *rest.Config, operatorNs string) error { - // The function below returns a list of filtered operator/CR specific GVKs. For more control, override the GVK list below - // with your own custom logic. Note that if you are adding third party API schemas, probably you will need to - // customize this implementation to avoid permissions issues. - filteredGVK, err := k8sutil.GetGVKsFromAddToScheme(apis.AddToScheme) - if err != nil { - return err - } - - // The metrics will be generated from the namespaces which are returned here. - // NOTE that passing nil or an empty list of namespaces in GenerateAndServeCRMetrics will result in an error. - ns, err := kubemetrics.GetNamespacesForMetrics(operatorNs) - if err != nil { - return err - } - - // Generate and serve custom resource specific metrics. - err = kubemetrics.GenerateAndServeCRMetrics(cfg, ns, filteredGVK, metricsHost, operatorMetricsPort) - if err != nil { - return err - } - return nil -} diff --git a/test/test-framework/deploy/crds/cache.example.com_dummys_crd.yaml b/test/test-framework/deploy/crds/cache.example.com_dummys_crd.yaml deleted file mode 100644 index 893ae623cb..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_dummys_crd.yaml +++ /dev/null @@ -1,101 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: dummys.cache.example.com -spec: - group: cache.example.com - names: - kind: Dummy - listKind: DummyList - plural: dummys - singular: dummy - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Dummy is the Schema for the dummy API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - size: - description: Should be in spec - format: int32 - type: integer - wheels: - description: Should be in spec, but should not have array index in path - items: - properties: - type: - description: Type should be in spec with path equal to wheels[0].type - type: string - required: - - type - type: object - type: array - required: - - size - - wheels - type: object - status: - properties: - hog: - description: Not included in status but children should be - properties: - brand: - description: Not in spec or status, no boolean annotation - type: string - engine: - description: Should be in status but not spec, since Hog isn't in - DummySpec - properties: - pistons: - description: Should not be included, no annotations. - items: - type: string - type: array - required: - - pistons - type: object - foo: - type: string - helmet: - description: Not in spec or status - type: string - seatMaterial: - type: string - required: - - brand - - engine - - foo - - helmet - - seatMaterial - type: object - nodes: - description: Should be in status but not spec, since DummyStatus isn't - in DummySpec - items: - type: string - type: array - required: - - hog - - nodes - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/crds/cache.example.com_memcachedrs_crd.yaml b/test/test-framework/deploy/crds/cache.example.com_memcachedrs_crd.yaml deleted file mode 100644 index ca07cd368e..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_memcachedrs_crd.yaml +++ /dev/null @@ -1,57 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: memcachedrs.cache.example.com -spec: - group: cache.example.com - names: - kind: MemcachedRS - listKind: MemcachedRSList - plural: memcachedrs - singular: memcachedrs - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: MemcachedRS is the Schema for the memcachedrs API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedRSSpec defines the desired state of MemcachedRS - properties: - numNodes: - format: int32 - type: integer - required: - - numNodes - type: object - status: - description: MemcachedRSStatus defines the observed state of MemcachedRS - properties: - nodeList: - items: - type: string - type: array - test: - type: boolean - required: - - nodeList - - test - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/test-framework/deploy/crds/cache.example.com_memcacheds_crd.yaml b/test/test-framework/deploy/crds/cache.example.com_memcacheds_crd.yaml deleted file mode 100644 index acc41fb954..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_memcacheds_crd.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: Memcached is the Schema for the memcacheds API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedSpec defines the desired state of Memcached - properties: - size: - description: Size is the size of the memcached deployment - format: int32 - type: integer - required: - - size - type: object - status: - description: MemcachedStatus defines the observed state of Memcached - properties: - nodes: - description: Nodes are the names of the memcached pods - items: - type: string - type: array - required: - - nodes - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/test/test-framework/deploy/crds/cache.example.com_otherdummies_crd.yaml b/test/test-framework/deploy/crds/cache.example.com_otherdummies_crd.yaml deleted file mode 100644 index e94d0d0bd3..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_otherdummies_crd.yaml +++ /dev/null @@ -1,73 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: otherdummies.cache.example.com -spec: - group: cache.example.com - names: - kind: OtherDummy - listKind: OtherDummyList - plural: otherdummies - singular: otherdummy - scope: Namespaced - validation: - openAPIV3Schema: - description: OtherDummy is the Schema for the other dummy API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - brand: - description: Not in spec or status, no boolean annotation - type: string - engine: - description: Should be in status but not spec, since Hog isn't in DummySpec - properties: - pistons: - description: Should not be included, no annotations. - items: - type: string - type: array - required: - - pistons - type: object - foo: - type: string - helmet: - description: Not in spec or status - type: string - seatMaterial: - type: string - required: - - brand - - engine - - foo - - helmet - - seatMaterial - type: object - status: - properties: - nothing: - description: Should be in status but not spec, since this isn't a spec - type - type: string - required: - - nothing - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml b/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml deleted file mode 100644 index 2b8f17c399..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: cache.example.com/v1alpha1 -kind: Memcached -metadata: - name: example-memcached -spec: - # Add fields here - size: 3 diff --git a/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml b/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml deleted file mode 100644 index 92861ed5fe..0000000000 --- a/test/test-framework/deploy/crds/cache.example.com_v1alpha1_memcachedrs_cr.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: cache.example.com/v1alpha1 -kind: MemcachedRS -metadata: - name: example-memcachedrs -spec: - numNodes: 4 diff --git a/test/test-framework/deploy/namespace-init.yaml b/test/test-framework/deploy/namespace-init.yaml deleted file mode 100644 index fc9b93f90d..0000000000 --- a/test/test-framework/deploy/namespace-init.yaml +++ /dev/null @@ -1,97 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: memcached-operator - ---- - -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: memcached-operator -rules: -- apiGroups: - - "" - resources: - - pods - - services - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - verbs: - - '*' -- apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - '*' -- apiGroups: - - cache.example.com - resources: - - '*' - verbs: - - '*' -- apiGroups: - - apps - resources: - - deployments/finalizers - resourceNames: - - memcached-operator - verbs: - - "update" - ---- - -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: memcached-operator -subjects: -- kind: ServiceAccount - name: memcached-operator -roleRef: - kind: Role - name: memcached-operator - apiGroup: rbac.authorization.k8s.io - ---- - -apiVersion: apps/v1 -kind: Deployment -metadata: - creationTimestamp: null - name: memcached-operator -spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - strategy: {} - template: - metadata: - creationTimestamp: null - labels: - name: memcached-operator - spec: - containers: - - command: - - memcached-operator - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: OPERATOR_NAME - value: memcached-operator - image: quay.io/coreos/operator-sdk-dev:test-framework-operator-runtime - imagePullPolicy: Always - name: memcached-operator - resources: {} - serviceAccountName: memcached-operator -status: {} diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcachedrs_crd.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcachedrs_crd.yaml deleted file mode 100644 index 9ffb3fab46..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcachedrs_crd.yaml +++ /dev/null @@ -1,58 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: memcachedrs.cache.example.com -spec: - group: cache.example.com - names: - kind: MemcachedRS - listKind: MemcachedRSList - plural: memcachedrs - singular: memcachedrs - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: MemcachedRS is the Schema for the memcachedrs API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedRSSpec defines the desired state of MemcachedRS - properties: - numNodes: - format: int32 - type: integer - required: - - numNodes - type: object - status: - description: MemcachedRSStatus defines the observed state of MemcachedRS - properties: - nodeList: - items: - type: string - type: array - test: - type: boolean - required: - - nodeList - - test - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcacheds_crd.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcacheds_crd.yaml deleted file mode 100644 index 0109edbab9..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/cache.example.com_memcacheds_crd.yaml +++ /dev/null @@ -1,57 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Memcached is the Schema for the memcacheds API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedSpec defines the desired state of Memcached - properties: - size: - description: Size is the size of the memcached deployment - format: int32 - type: integer - required: - - size - type: object - status: - description: MemcachedStatus defines the observed state of Memcached - properties: - nodes: - description: Nodes are the names of the memcached pods - items: - type: string - type: array - required: - - nodes - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml deleted file mode 100644 index 663ab2647d..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.2/memcached-operator.v0.0.2.clusterserviceversion.yaml +++ /dev/null @@ -1,167 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: ClusterServiceVersion -metadata: - annotations: - alm-examples: |- - [ - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "Memcached", - "metadata": { - "name": "example-memcached" - }, - "spec": { - "size": 3 - } - }, - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "MemcachedRS", - "metadata": { - "name": "example-memcachedrs" - }, - "spec": { - "numNodes": 4 - } - } - ] - capabilities: Basic Install - name: memcached-operator.v0.0.2 - namespace: placeholder -spec: - apiservicedefinitions: {} - customresourcedefinitions: - owned: - - kind: MemcachedRS - name: memcachedrs.cache.example.com - version: v1alpha1 - - description: Represents a cluster of Memcached apps - displayName: Memcached App - kind: Memcached - name: memcacheds.cache.example.com - resources: - - kind: Deployment - name: "" - version: v1 - - kind: ReplicaSet - name: "" - version: v1 - - kind: Pod - name: "" - version: v1 - specDescriptors: - - description: The desired number of member Pods for the deployment. - displayName: Size - path: size - x-descriptors: - - urn:alm:descriptor:com.tectonic.ui:podCount - statusDescriptors: - - description: The current status of the application. - displayName: Status - path: phase - x-descriptors: - - urn:alm:descriptor:io.kubernetes.phase - - description: Explanation for the current status of the application. - displayName: Status Details - path: reason - x-descriptors: - - urn:alm:descriptor:io.kubernetes.phase:reason - version: v1alpha1 - - kind: NotExistKind - name: notexist.example.com - version: v1alpha1 - description: Main enterprise application providing business critical features with - high availability and no manual intervention. - displayName: Memcached Application - install: - spec: - deployments: - - name: memcached-operator - spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - template: - metadata: - labels: - name: memcached-operator - spec: - containers: - - command: - - memcached-operator - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.annotations['olm.targetNamespaces'] - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: memcached-operator - image: quay.io/coreos/operator-sdk-dev:test-framework-operator - imagePullPolicy: Always - name: memcached-operator - serviceAccountName: memcached-operator - permissions: - - rules: - - apiGroups: - - "" - resources: - - pods - - services - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - - namespaces - verbs: - - '*' - - apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - '*' - - apiGroups: - - cache.example.com - resources: - - '*' - verbs: - - '*' - - apiGroups: - - apps - resourceNames: - - memcached-operator - resources: - - deployments/finalizers - verbs: - - update - serviceAccountName: memcached-operator - strategy: deployment - installModes: - - supported: true - type: OwnNamespace - - supported: true - type: SingleNamespace - - supported: false - type: MultiNamespace - - supported: true - type: AllNamespaces - keywords: - - memcached - - app - maintainers: - - email: corp@example.com - name: Some Corp - maturity: alpha - provider: - name: Example - url: www.example.com - version: 0.0.2 diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcachedrs_crd.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcachedrs_crd.yaml deleted file mode 100644 index 9ffb3fab46..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcachedrs_crd.yaml +++ /dev/null @@ -1,58 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: memcachedrs.cache.example.com -spec: - group: cache.example.com - names: - kind: MemcachedRS - listKind: MemcachedRSList - plural: memcachedrs - singular: memcachedrs - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: MemcachedRS is the Schema for the memcachedrs API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedRSSpec defines the desired state of MemcachedRS - properties: - numNodes: - format: int32 - type: integer - required: - - numNodes - type: object - status: - description: MemcachedRSStatus defines the observed state of MemcachedRS - properties: - nodeList: - items: - type: string - type: array - test: - type: boolean - required: - - nodeList - - test - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcacheds_crd.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcacheds_crd.yaml deleted file mode 100644 index 0109edbab9..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/cache.example.com_memcacheds_crd.yaml +++ /dev/null @@ -1,57 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Memcached is the Schema for the memcacheds API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedSpec defines the desired state of Memcached - properties: - size: - description: Size is the size of the memcached deployment - format: int32 - type: integer - required: - - size - type: object - status: - description: MemcachedStatus defines the observed state of Memcached - properties: - nodes: - description: Nodes are the names of the memcached pods - items: - type: string - type: array - required: - - nodes - type: object - type: object - version: v1alpha1 - versions: - - name: v1alpha1 - served: true - storage: true diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml deleted file mode 100644 index e2e61f4a81..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml +++ /dev/null @@ -1,189 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: ClusterServiceVersion -metadata: - annotations: - alm-examples: |- - [ - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "Memcached", - "metadata": { - "name": "example-memcached" - }, - "spec": { - "size": 3 - } - }, - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "MemcachedRS", - "metadata": { - "name": "example-memcachedrs" - }, - "spec": { - "numNodes": 4 - } - } - ] - capabilities: Basic Install - name: memcached-operator.v0.0.3 - namespace: placeholder -spec: - apiservicedefinitions: {} - customresourcedefinitions: - owned: - - description: Represents a cluster of MemcachedRS apps - displayName: MemcachedRS App - kind: MemcachedRS - name: memcachedrs.cache.example.com - statusDescriptors: - - description: List of the pod names running Memcached in the cluster - displayName: Nodes - path: nodeList - - description: A useless testing variable - displayName: Test - path: test - version: v1alpha1 - - description: Represents a cluster of Memcached apps - displayName: Memcached App - kind: Memcached - name: memcacheds.cache.example.com - resources: - - kind: Deployment - name: "" - version: v1 - - kind: ReplicaSet - name: "" - version: v1 - - kind: Pod - name: "" - version: v1 - specDescriptors: - - description: The desired number of member Pods for the deployment. - displayName: Size - path: size - x-descriptors: - - urn:alm:descriptor:com.tectonic.ui:podCount - statusDescriptors: - - description: The current status of the application. - displayName: Status - path: phase - x-descriptors: - - urn:alm:descriptor:io.kubernetes.phase - - description: Explanation for the current status of the application. - displayName: Status Details - path: reason - x-descriptors: - - urn:alm:descriptor:io.kubernetes.phase:reason - version: v1alpha1 - description: Main enterprise application providing business critical features with - high availability and no manual intervention. - displayName: Memcached Application - install: - spec: - deployments: - - name: memcached-operator - spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - strategy: {} - template: - metadata: - labels: - name: memcached-operator - spec: - containers: - - command: - - memcached-operator - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.annotations['olm.targetNamespaces'] - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: memcached-operator - image: quay.io/example/memcached-operator:v0.0.1 - imagePullPolicy: Never - name: memcached-operator - resources: {} - serviceAccountName: memcached-operator - permissions: - - rules: - - apiGroups: - - "" - resources: - - pods - - services - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - verbs: - - '*' - - apiGroups: - - "" - resources: - - namespaces - verbs: - - get - - apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - '*' - - apiGroups: - - monitoring.coreos.com - resources: - - servicemonitors - verbs: - - get - - create - - apiGroups: - - apps - resourceNames: - - memcached-operator - resources: - - deployments/finalizers - verbs: - - update - - apiGroups: - - cache.example.com - resources: - - '*' - - memcachedrs - verbs: - - '*' - serviceAccountName: memcached-operator - strategy: deployment - installModes: - - supported: true - type: OwnNamespace - - supported: true - type: SingleNamespace - - supported: false - type: MultiNamespace - - supported: true - type: AllNamespaces - keywords: - - memcached - - app - maintainers: - - email: corp@example.com - name: Some Corp - maturity: alpha - provider: - name: Example - url: www.example.com - replaces: memcached-operator.v0.0.2 - version: 0.0.3 diff --git a/test/test-framework/deploy/olm-catalog/memcached-operator/memcached-operator.package.yaml b/test/test-framework/deploy/olm-catalog/memcached-operator/memcached-operator.package.yaml deleted file mode 100644 index e3a059e4fb..0000000000 --- a/test/test-framework/deploy/olm-catalog/memcached-operator/memcached-operator.package.yaml +++ /dev/null @@ -1,7 +0,0 @@ -packageName: memcached-operator -channels: -- currentCSV: memcached-operator.v0.0.2 - name: alpha -- currentCSV: memcached-operator.v0.0.3 - name: beta -defaultChannel: beta diff --git a/test/test-framework/deploy/operator.yaml b/test/test-framework/deploy/operator.yaml deleted file mode 100644 index 15fd67730b..0000000000 --- a/test/test-framework/deploy/operator.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: memcached-operator -spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - template: - metadata: - labels: - name: memcached-operator - spec: - serviceAccountName: memcached-operator - containers: - - name: memcached-operator - # Replace this with the built image name - image: quay.io/coreos/operator-sdk-dev:test-framework-operator-multi - command: - - memcached-operator - imagePullPolicy: Always - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: "memcached-operator" diff --git a/test/test-framework/deploy/role.yaml b/test/test-framework/deploy/role.yaml deleted file mode 100644 index e97b451991..0000000000 --- a/test/test-framework/deploy/role.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: memcached-operator -rules: -- apiGroups: - - "" - resources: - - pods - - services - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - verbs: - - '*' -- apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - '*' -- apiGroups: - - cache.example.com - resources: - - '*' - verbs: - - '*' -- apiGroups: - - apps - resources: - - deployments/finalizers - resourceNames: - - memcached-operator - verbs: - - "update" diff --git a/test/test-framework/deploy/role_binding.yaml b/test/test-framework/deploy/role_binding.yaml deleted file mode 100644 index 322ecc9e6a..0000000000 --- a/test/test-framework/deploy/role_binding.yaml +++ /dev/null @@ -1,11 +0,0 @@ -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: memcached-operator -subjects: -- kind: ServiceAccount - name: memcached-operator -roleRef: - kind: Role - name: memcached-operator - apiGroup: rbac.authorization.k8s.io diff --git a/test/test-framework/deploy/service_account.yaml b/test/test-framework/deploy/service_account.yaml deleted file mode 100644 index 8d58bc7832..0000000000 --- a/test/test-framework/deploy/service_account.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: memcached-operator diff --git a/test/test-framework/deploy/test-pod.yaml b/test/test-framework/deploy/test-pod.yaml deleted file mode 100644 index bb7e325158..0000000000 --- a/test/test-framework/deploy/test-pod.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: -test -spec: - restartPolicy: Never - containers: - - name: -test - image: - imagePullPolicy: Always - command: ["/go-test.sh"] - env: - - name: - valueFrom: - fieldRef: - fieldPath: metadata.namespace diff --git a/test/test-framework/go.mod b/test/test-framework/go.mod deleted file mode 100644 index 9c5ca8c8a5..0000000000 --- a/test/test-framework/go.mod +++ /dev/null @@ -1,19 +0,0 @@ -module github.com/operator-framework/operator-sdk/test/test-framework - -go 1.13 - -require ( - github.com/operator-framework/operator-sdk v0.0.0 - github.com/spf13/pflag v1.0.5 - k8s.io/api v0.18.2 - k8s.io/apimachinery v0.18.2 - k8s.io/client-go v12.0.0+incompatible - sigs.k8s.io/controller-runtime v0.6.0 -) - -replace ( - github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.2+incompatible // Required by OLM - k8s.io/client-go => k8s.io/client-go v0.18.2 // Required by prometheus-operator -) - -replace github.com/operator-framework/operator-sdk => ../../ diff --git a/test/test-framework/pkg/apis/addtoscheme_cache_v1alpha1.go b/test/test-framework/pkg/apis/addtoscheme_cache_v1alpha1.go deleted file mode 100644 index 117b8dfb53..0000000000 --- a/test/test-framework/pkg/apis/addtoscheme_cache_v1alpha1.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apis - -import ( - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) -} diff --git a/test/test-framework/pkg/apis/apis.go b/test/test-framework/pkg/apis/apis.go deleted file mode 100644 index 6f79149168..0000000000 --- a/test/test-framework/pkg/apis/apis.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apis - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// AddToSchemes may be used to add all resources defined in the project to a Scheme -var AddToSchemes runtime.SchemeBuilder - -// AddToScheme adds all Resources to the Scheme -func AddToScheme(s *runtime.Scheme) error { - return AddToSchemes.AddToScheme(s) -} diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/doc.go b/test/test-framework/pkg/apis/cache/v1alpha1/doc.go deleted file mode 100644 index 84fd6d207f..0000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v1alpha1 contains API Schema definitions for the cache v1alpha1 API group -// +k8s:deepcopy-gen=package,register -// +groupName=cache.example.com -package v1alpha1 diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/memcached_types.go b/test/test-framework/pkg/apis/cache/v1alpha1/memcached_types.go deleted file mode 100644 index 7bf2b35b8f..0000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/memcached_types.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// MemcachedSpec defines the desired state of Memcached -type MemcachedSpec struct { - // Size is the size of the memcached deployment - Size int32 `json:"size"` -} - -// MemcachedStatus defines the observed state of Memcached -type MemcachedStatus struct { - // Nodes are the names of the memcached pods - Nodes []string `json:"nodes"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Memcached is the Schema for the memcacheds API -// +kubebuilder:subresource:status -// +kubebuilder:resource:path=memcacheds,scope=Namespaced -// +kubebuilder:storageversion -type Memcached struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec MemcachedSpec `json:"spec,omitempty"` - Status MemcachedStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// MemcachedList contains a list of Memcached -type MemcachedList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Memcached `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Memcached{}, &MemcachedList{}) -} diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/memcachedrs_types.go b/test/test-framework/pkg/apis/cache/v1alpha1/memcachedrs_types.go deleted file mode 100644 index 6633bb64d6..0000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/memcachedrs_types.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2019 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// MemcachedRSSpec defines the desired state of MemcachedRS -type MemcachedRSSpec struct { - NumNodes int32 `json:"numNodes"` -} - -// MemcachedRSStatus defines the observed state of MemcachedRS -type MemcachedRSStatus struct { - NodeList []string `json:"nodeList"` - Test bool `json:"test"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// MemcachedRS is the Schema for the memcachedrs API -// +kubebuilder:subresource:status -// +kubebuilder:resource:path=memcachedrs,scope=Namespaced -// +kubebuilder:storageversion -type MemcachedRS struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec MemcachedRSSpec `json:"spec,omitempty"` - Status MemcachedRSStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// MemcachedRSList contains a list of MemcachedRS -type MemcachedRSList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []MemcachedRS `json:"items"` -} - -func init() { - SchemeBuilder.Register(&MemcachedRS{}, &MemcachedRSList{}) -} diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/register.go b/test/test-framework/pkg/apis/cache/v1alpha1/register.go deleted file mode 100644 index f2a2d17ab7..0000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/register.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1alpha1 contains API Schema definitions for the cache v1alpha1 API group -// +k8s:deepcopy-gen=package,register -// +groupName=cache.example.com -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "cache.example.com", Version: "v1alpha1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} -) diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.deepcopy.go b/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index a9a4c89c63..0000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,205 +0,0 @@ -// +build !ignore_autogenerated - -// Code generated by operator-sdk. DO NOT EDIT. - -package v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Memcached) DeepCopyInto(out *Memcached) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Memcached. -func (in *Memcached) DeepCopy() *Memcached { - if in == nil { - return nil - } - out := new(Memcached) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Memcached) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedList) DeepCopyInto(out *MemcachedList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Memcached, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedList. -func (in *MemcachedList) DeepCopy() *MemcachedList { - if in == nil { - return nil - } - out := new(MemcachedList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MemcachedList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedRS) DeepCopyInto(out *MemcachedRS) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedRS. -func (in *MemcachedRS) DeepCopy() *MemcachedRS { - if in == nil { - return nil - } - out := new(MemcachedRS) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MemcachedRS) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedRSList) DeepCopyInto(out *MemcachedRSList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MemcachedRS, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedRSList. -func (in *MemcachedRSList) DeepCopy() *MemcachedRSList { - if in == nil { - return nil - } - out := new(MemcachedRSList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MemcachedRSList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedRSSpec) DeepCopyInto(out *MemcachedRSSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedRSSpec. -func (in *MemcachedRSSpec) DeepCopy() *MemcachedRSSpec { - if in == nil { - return nil - } - out := new(MemcachedRSSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedRSStatus) DeepCopyInto(out *MemcachedRSStatus) { - *out = *in - if in.NodeList != nil { - in, out := &in.NodeList, &out.NodeList - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedRSStatus. -func (in *MemcachedRSStatus) DeepCopy() *MemcachedRSStatus { - if in == nil { - return nil - } - out := new(MemcachedRSStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedSpec) DeepCopyInto(out *MemcachedSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedSpec. -func (in *MemcachedSpec) DeepCopy() *MemcachedSpec { - if in == nil { - return nil - } - out := new(MemcachedSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemcachedStatus) DeepCopyInto(out *MemcachedStatus) { - *out = *in - if in.Nodes != nil { - in, out := &in.Nodes, &out.Nodes - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedStatus. -func (in *MemcachedStatus) DeepCopy() *MemcachedStatus { - if in == nil { - return nil - } - out := new(MemcachedStatus) - in.DeepCopyInto(out) - return out -} diff --git a/test/test-framework/pkg/controller/add_memcached.go b/test/test-framework/pkg/controller/add_memcached.go deleted file mode 100644 index 4747af143a..0000000000 --- a/test/test-framework/pkg/controller/add_memcached.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package controller - -import ( - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/controller/memcached" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, memcached.Add) -} diff --git a/test/test-framework/pkg/controller/add_memcachedrs.go b/test/test-framework/pkg/controller/add_memcachedrs.go deleted file mode 100644 index bb83fb9f3a..0000000000 --- a/test/test-framework/pkg/controller/add_memcachedrs.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2019 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package controller - -import ( - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/controller/memcachedrs" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, memcachedrs.Add) -} diff --git a/test/test-framework/pkg/controller/controller.go b/test/test-framework/pkg/controller/controller.go deleted file mode 100644 index c678b7f9c6..0000000000 --- a/test/test-framework/pkg/controller/controller.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package controller - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -} diff --git a/test/test-framework/pkg/controller/memcached/memcached_controller.go b/test/test-framework/pkg/controller/memcached/memcached_controller.go deleted file mode 100644 index 86ce246852..0000000000 --- a/test/test-framework/pkg/controller/memcached/memcached_controller.go +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package memcached - -import ( - "context" - "reflect" - - cachev1alpha1 "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1" - - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/handler" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" -) - -var log = logf.Log.WithName("controller_memcached") - -// Add creates a new Memcached Controller and adds it to the Manager. The Manager will set fields on the Controller -// and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileMemcached{client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("memcached-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to primary resource Memcached - err = c.Watch(&source.Kind{Type: &cachev1alpha1.Memcached{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create that are owned by the primary resource - // Watch for changes to secondary resource Pods and requeue the owner Memcached - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &cachev1alpha1.Memcached{}, - }) - if err != nil { - return err - } - - return nil -} - -// blank assignment to verify that ReconcileMemcached implements reconcile.Reconciler -var _ reconcile.Reconciler = &ReconcileMemcached{} - -// ReconcileMemcached reconciles a Memcached object -type ReconcileMemcached struct { - // TODO: Clarify the split client - // This client, initialized using mgr.Client() above, is a split client - // that reads objects from the cache and writes to the apiserver - client client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a Memcached object and makes changes based on the state read -// and what is in the Memcached.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. This example creates -// a Memcached Deployment for each Memcached CR -// Note: -// The Controller will requeue the Request to be processed again if the returned error is non-nil or -// Result.Requeue is true, otherwise upon completion it will remove the work from the queue. -func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Result, error) { - reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) - reqLogger.Info("Reconciling Memcached.") - - // Fetch the Memcached instance - memcached := &cachev1alpha1.Memcached{} - err := r.client.Get(context.TODO(), request.NamespacedName, memcached) - if err != nil { - if errors.IsNotFound(err) { - // Request object not found, could have been deleted after reconcile request. - // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. - // Return and don't requeue - reqLogger.Info("Memcached resource not found. Ignoring since object must be deleted.") - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - reqLogger.Error(err, "Failed to get Memcached.") - return reconcile.Result{}, err - } - - // Check if the deployment already exists, if not create a new one - found := &appsv1.Deployment{} - err = r.client.Get(context.TODO(), types.NamespacedName{Name: memcached.Name, Namespace: memcached.Namespace}, found) - if err != nil && errors.IsNotFound(err) { - // Define a new deployment - dep := r.deploymentForMemcached(memcached) - reqLogger.Info("Creating a new Deployment.", "Deployment.Namespace", dep.Namespace, "Deployment.Name", dep.Name) - err = r.client.Create(context.TODO(), dep) - if err != nil { - reqLogger.Error(err, "Failed to create new Deployment.", "Deployment.Namespace", dep.Namespace, "Deployment.Name", dep.Name) - return reconcile.Result{}, err - } - // Deployment created successfully - return and requeue - return reconcile.Result{Requeue: true}, nil - } else if err != nil { - reqLogger.Error(err, "Failed to get Deployment.") - return reconcile.Result{}, err - } - - // Ensure the deployment size is the same as the spec - size := memcached.Spec.Size - if *found.Spec.Replicas != size { - found.Spec.Replicas = &size - err = r.client.Update(context.TODO(), found) - if err != nil { - reqLogger.Error(err, "Failed to update Deployment.", "Deployment.Namespace", found.Namespace, "Deployment.Name", found.Name) - return reconcile.Result{}, err - } - // Spec updated - return and requeue - return reconcile.Result{Requeue: true}, nil - } - - // Update the Memcached status with the pod names - // List the pods for this memcached's deployment - podList := &corev1.PodList{} - listOpts := []client.ListOption{ - client.InNamespace(memcached.Namespace), - client.MatchingLabels(labelsForMemcached(memcached.Name)), - } - err = r.client.List(context.TODO(), podList, listOpts...) - if err != nil { - reqLogger.Error(err, "Failed to list pods.", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) - return reconcile.Result{}, err - } - podNames := getPodNames(podList.Items) - - // Update status.Nodes if needed - if !reflect.DeepEqual(podNames, memcached.Status.Nodes) { - memcached.Status.Nodes = podNames - err := r.client.Status().Update(context.TODO(), memcached) - if err != nil { - reqLogger.Error(err, "Failed to update Memcached status.") - return reconcile.Result{}, err - } - } - - return reconcile.Result{}, nil -} - -// deploymentForMemcached returns a memcached Deployment object -func (r *ReconcileMemcached) deploymentForMemcached(m *cachev1alpha1.Memcached) *appsv1.Deployment { - ls := labelsForMemcached(m.Name) - replicas := m.Spec.Size - - dep := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: m.Name, - Namespace: m.Namespace, - }, - Spec: appsv1.DeploymentSpec{ - Replicas: &replicas, - Selector: &metav1.LabelSelector{ - MatchLabels: ls, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: ls, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Image: "memcached:1.4.36-alpine", - Name: "memcached", - Command: []string{"memcached", "-m=64", "-o", "modern", "-v"}, - Ports: []corev1.ContainerPort{{ - ContainerPort: 11211, - Name: "memcached", - }}, - }}, - }, - }, - }, - } - // Set Memcached instance as the owner and controller - if err := controllerutil.SetControllerReference(m, dep, r.scheme); err != nil { - log.Error(err, "Failed to set controller reference for memcached deployment") - } - return dep -} - -// labelsForMemcached returns the labels for selecting the resources -// belonging to the given memcached CR name. -func labelsForMemcached(name string) map[string]string { - return map[string]string{"app": "memcached", "memcached_cr": name} -} - -// getPodNames returns the pod names of the array of pods passed in -func getPodNames(pods []corev1.Pod) []string { - var podNames []string - for _, pod := range pods { - podNames = append(podNames, pod.Name) - } - return podNames -} diff --git a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go b/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go deleted file mode 100644 index ebc2274219..0000000000 --- a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2019 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package memcachedrs - -import ( - "context" - "reflect" - - cachev1alpha1 "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1" - - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/handler" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" -) - -var log = logf.Log.WithName("controller_memcachedrs") - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new MemcachedRS Controller and adds it to the Manager. The Manager will set fields on the Controller -// and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileMemcachedRS{client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("memcachedrs-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to primary resource MemcachedRS - err = c.Watch(&source.Kind{Type: &cachev1alpha1.MemcachedRS{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create that are owned by the primary resource - // Watch for changes to secondary resource Pods and requeue the owner MemcachedRS - err = c.Watch(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &cachev1alpha1.MemcachedRS{}, - }) - if err != nil { - return err - } - - return nil -} - -// blank assignment to verify that ReconcileMemcachedRS implements reconcile.Reconciler -var _ reconcile.Reconciler = &ReconcileMemcachedRS{} - -// ReconcileMemcachedRS reconciles a MemcachedRS object -type ReconcileMemcachedRS struct { - // This client, initialized using mgr.Client() above, is a split client - // that reads objects from the cache and writes to the apiserver - client client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a MemcachedRS object and makes changes based on the state read -// and what is in the MemcachedRS.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. This example creates -// a Pod as an example -// Note: -// The Controller will requeue the Request to be processed again if the returned error is non-nil or -// Result.Requeue is true, otherwise upon completion it will remove the work from the queue. -func (r *ReconcileMemcachedRS) Reconcile(request reconcile.Request) (reconcile.Result, error) { - reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) - reqLogger.Info("Reconciling MemcachedRS") - - // Fetch the MemcachedRS instance - memcachedrs := &cachev1alpha1.MemcachedRS{} - err := r.client.Get(context.TODO(), request.NamespacedName, memcachedrs) - if err != nil { - if errors.IsNotFound(err) { - // Request object not found, could have been deleted after reconcile request. - // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. - // Return and don't requeue - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - // Check if the replicaSet already exists, if not create a new one - found := &appsv1.ReplicaSet{} - err = r.client.Get(context.TODO(), types.NamespacedName{Name: memcachedrs.Name, Namespace: memcachedrs.Namespace}, found) - if err != nil && errors.IsNotFound(err) { - // Define a new replicaSet - dep, err := r.replicaSetForMemcached(memcachedrs) - reqLogger.Info("Creating a new ReplicaSet", "ReplicaSet.Namespace", dep.Namespace, "ReplicaSet.Name", dep.Name) - if err != nil { - return reconcile.Result{}, err - } - err = r.client.Create(context.TODO(), dep) - if err != nil { - reqLogger.Error(err, "Failed to create new ReplicaSet", "ReplicaSet.Namespace", dep.Namespace, "ReplicaSet.Name", dep.Name) - return reconcile.Result{}, err - } - // ReplicaSet created successfully - return and requeue - return reconcile.Result{Requeue: true}, nil - } else if err != nil { - reqLogger.Error(err, "Failed to get ReplicaSet") - return reconcile.Result{}, err - } - - // Ensure the replicaSet size is the same as the spec - size := memcachedrs.Spec.NumNodes - if *found.Spec.Replicas != size { - found.Spec.Replicas = &size - err = r.client.Update(context.TODO(), found) - if err != nil { - reqLogger.Error(err, "Failed to update ReplicaSet", "ReplicaSet.Namespace", found.Namespace, "ReplicaSet.Name", found.Name) - return reconcile.Result{}, err - } - // Spec updated - return and requeue - return reconcile.Result{Requeue: true}, nil - } - - // Update the Memcached status with the pod names - // List the pods for this memcached's replicaSet - podList := &corev1.PodList{} - listOpts := []client.ListOption{ - client.InNamespace(memcachedrs.Namespace), - client.MatchingLabels(labelsForMemcached(memcachedrs.Name)), - } - err = r.client.List(context.TODO(), podList, listOpts...) - if err != nil { - reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcachedrs.Namespace, "Memcached.Name", memcachedrs.Name) - return reconcile.Result{}, err - } - podNames := getPodNames(podList.Items) - - // Update status.Nodes if needed - if !reflect.DeepEqual(podNames, memcachedrs.Status.NodeList) { - memcachedrs.Status.NodeList = podNames - err := r.client.Status().Update(context.TODO(), memcachedrs) - if err != nil { - reqLogger.Error(err, "Failed to update Memcached status") - return reconcile.Result{}, err - } - } - - // Switch testing bool - if memcachedrs.Status.Test { - memcachedrs.Status.Test = false - } else { - memcachedrs.Status.Test = true - } - err = r.client.Status().Update(context.TODO(), memcachedrs) - if err != nil { - reqLogger.Error(err, "Failed to update Memcached status") - return reconcile.Result{}, err - } - - return reconcile.Result{}, nil -} - -// rsForMemcached returns a memcached ReplicaSet object -func (r *ReconcileMemcachedRS) replicaSetForMemcached(m *cachev1alpha1.MemcachedRS) (*appsv1.ReplicaSet, error) { - ls := labelsForMemcached(m.Name) - replicas := m.Spec.NumNodes - - replicaSet := &appsv1.ReplicaSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: m.Name, - Namespace: m.Namespace, - }, - Spec: appsv1.ReplicaSetSpec{ - Replicas: &replicas, - Selector: &metav1.LabelSelector{ - MatchLabels: ls, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: ls, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Image: "memcached:1.4.36-alpine", - Name: "memcached", - Command: []string{"memcached", "-m=64", "-o", "modern", "-v"}, - Ports: []corev1.ContainerPort{{ - ContainerPort: 11211, - Name: "memcached", - }}, - }}, - }, - }, - }, - } - // Set Memcached instance as the owner and controller - if err := controllerutil.SetControllerReference(m, replicaSet, r.scheme); err != nil { - return nil, err - } - return replicaSet, nil -} - -// labelsForMemcached returns the labels for selecting the resources -// belonging to the given memcached CR name. -func labelsForMemcached(name string) map[string]string { - return map[string]string{"app": "memcached-rs", "memcached_cr": name} -} - -// getPodNames returns the pod names of the array of pods passed in -func getPodNames(pods []corev1.Pod) []string { - var podNames []string - for _, pod := range pods { - podNames = append(podNames, pod.Name) - } - return podNames -}