From cc1aa3cd8e548f0a714eec3b7784ee8ec98a6ff2 Mon Sep 17 00:00:00 2001 From: Marc Brown Date: Mon, 24 Jun 2024 17:14:45 -0400 Subject: [PATCH] HOSTEDCP-1716: When running the HO locally it should no required a running pod This PR covers the steps to run the HyperShift Operator locally without needing access to a full production environment. Fixes #HOSTEDCP-1716 --- HACKING.md | 2 +- Makefile | 12 +++++ .../run-hypershift-operator-locally.md | 51 +++++++++++++++++++ docs/content/contribute/run-locally.md | 22 -------- docs/mkdocs.yml | 3 +- hack/dev/aws/hypershift-install-aws-dev.sh | 18 +++++++ hack/dev/aws/run-operator-locally-aws-dev.sh | 25 +++++++++ 7 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 docs/content/contribute/run-hypershift-operator-locally.md delete mode 100644 docs/content/contribute/run-locally.md create mode 100755 hack/dev/aws/hypershift-install-aws-dev.sh create mode 100755 hack/dev/aws/run-operator-locally-aws-dev.sh diff --git a/HACKING.md b/HACKING.md index 29de7b7f40..4d93121a7b 100644 --- a/HACKING.md +++ b/HACKING.md @@ -9,7 +9,7 @@ 2. Build HyperShift. - # requires go v1.16+ + # requires go v1.22+ $ make build 3. Install HyperShift in development mode which causes the operator deployment diff --git a/Makefile b/Makefile index 5d6671f83e..4fc3a01b93 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,10 @@ GO_E2E_RECIPE=CGO_ENABLED=1 $(GO) test $(GO_GCFLAGS) -tags e2e -c OUT_DIR ?= bin +# run the HO locally +HYPERSHIFT_INSTALL_AWS := ./hack/dev/aws/hypershft-install-aws.sh +RUN_OPERATOR_LOCALLY_AWS := ./hack/dev/aws/run-operator-locally-aws.sh + # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -286,3 +290,11 @@ ci-install-hypershift-private: regenerate-pki: REGENERATE_PKI=1 $(GO) test ./control-plane-pki-operator/... REGENERATE_PKI=1 $(GO) test ./test/e2e/... -run TestRegeneratePKI + +.PHONY: hypershift-install-aws-dev +hypershift-install-aws-dev: + @$(HYPERSHIFT_INSTALL_AWS) + +.PHONY: run-operator-locally-aws-dev +run-operator-locally-aws-dev: + @$(RUN_OPERATOR_LOCALLY_AWS) diff --git a/docs/content/contribute/run-hypershift-operator-locally.md b/docs/content/contribute/run-hypershift-operator-locally.md new file mode 100644 index 0000000000..3d056a816f --- /dev/null +++ b/docs/content/contribute/run-hypershift-operator-locally.md @@ -0,0 +1,51 @@ +--- +title: Run the hypershift-operator locally +--- + +## Run the HyperShift Operator locally + +To run the HyperShift Operator locally, follow these steps: + +1. Ensure that the `KUBECONFIG` environment variable is set to a management cluster where HyperShift has not been installed yet. + + ```shell linenums="1" + export KUBECONFIG="/path/to/your/kubeconfig" + ``` + +2. Build HyperShift. + +!!! note + + `requires go v1.22+ + +```shell linenums="1" + make build +``` + +3. Set the necessary environment variables + + ```shell linenums="1" + export HYPERSHIFT_REGION="your-region" + export HYPERSHIFT_BUCKET_NAME="your-bucket" + ``` + +!!! note + + `Consider setting HYPERSHIFT_REGION and HYPERSHIFT_BUCKET_NAME in your shell init script (e.g., $HOME/.bashrc). + +!!! note + + `Default values are provided for HYPERSHIFT_REGION and HYPERSHIFT_BUCKET_NAME so Step #4 will function without requiring you to export any values. + +4. Install HyperShift in development mode which causes the operator deployment to be deployment scaled to zero so that it doesn't conflict with your local operator process (see [Prerequisites](../getting-started.md#prerequisites)): + +```shell linenums="1" + make hypershift-install-aws-dev +``` + +5. Run the HyperShift operator locally. + +```shell linenums="1" + make run-operator-locally-aws-dev +``` + diff --git a/docs/content/contribute/run-locally.md b/docs/content/contribute/run-locally.md deleted file mode 100644 index 2139e66235..0000000000 --- a/docs/content/contribute/run-locally.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Run operators locally ---- - -# How to run the HyperShift Operator in a local process - -1. Ensure the `KUBECONFIG` environment variable points to a management cluster - with no HyperShift installed yet. - -2. Build HyperShift. - - make build - -3. Install HyperShift in development mode which causes the operator deployment - to be deployment scaled to zero so that it doesn't conflict with your local - operator process. - - bin/hypershift install --development - -4. Run the HyperShift operator locally. - - bin/hypershift-operator run diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 8d03de4181..81b60b546c 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -263,4 +263,5 @@ nav: - 'Onboard a Platform': contribute/onboard-a-platform.md - 'Run Tests': contribute/run-tests.md - 'Develop in Cluster': contribute/develop_in_cluster.md - - 'Conotribute to docs': contribute/contribute-docs.md + - 'Run hypershift-operator locally': contribute/run-hypershift-operator-locally.md + - 'Contribute to docs': contribute/contribute-docs.md diff --git a/hack/dev/aws/hypershift-install-aws-dev.sh b/hack/dev/aws/hypershift-install-aws-dev.sh new file mode 100755 index 0000000000..5661086820 --- /dev/null +++ b/hack/dev/aws/hypershift-install-aws-dev.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail + +REGION="${HYPERSHIFT_REGION:-us-east-1}" +BUCKET_NAME="${HYPERSHIFT_BUCKET_NAME:-hypershift-ci-oidc}" +AWSCREDS="${HYPERSHIFT_AWS_CREDS:-$HOME/.aws/credentials}" + +# Install hypershift +echo "Installing hypershift" +./bin/hypershift install \ + --oidc-storage-provider-s3-credentials "${AWSCREDS}" \ + --oidc-storage-provider-s3-region "${REGION}" \ + --oidc-storage-provider-s3-bucket-name "${BUCKET_NAME}" \ + --enable-defaulting-webhook=false \ + --enable-conversion-webhook=false \ + --enable-validating-webhook=false \ + --development=true \ No newline at end of file diff --git a/hack/dev/aws/run-operator-locally-aws-dev.sh b/hack/dev/aws/run-operator-locally-aws-dev.sh new file mode 100755 index 0000000000..d05ccd878e --- /dev/null +++ b/hack/dev/aws/run-operator-locally-aws-dev.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -euo pipefail +export METRICS_SET="Telemetry" + +export MY_NAMESPACE=hypershift +export MY_NAME=operator + +REGION="${HYPERSHIFT_REGION:-us-east-1}" +BUCKET_NAME="${HYPERSHIFT_BUCKET_NAME:-hypershift-ci-oidc}" +AWSCREDS="${HYPERSHIFT_AWS_CREDS:-$HOME/.aws/credentials}" + +# Run hypershift-operator locally. +echo "Running hypershift-operator locally..." +./bin/hypershift-operator \ + run \ + --metrics-addr=0 \ + --enable-ocp-cluster-monitoring=false \ + --enable-ci-debug-output=true \ + --private-platform=AWS \ + --enable-ci-debug-output=true \ + --oidc-storage-provider-s3-credentials "${AWSCREDS}" \ + --oidc-storage-provider-s3-region "${REGION}" \ + --oidc-storage-provider-s3-bucket-name "${BUCKET_NAME}" \ + --control-plane-operator-image=quay.io/hypershift/hypershift:latest \ No newline at end of file