- Development Environment Setup
- Makefile
- Dependencies
- Linting
- Testing
- Building
- Build using boilerplate container
- Running Locally
- Running Remotely
- Monitoring ongoing upgrade
- Maintenance
Everything you need to develop this operator locally.
A recent Go distribution (>=1.23) with enabled Go modules.
go version
go version go1.23.9 linux/amd64The Operator is being developed based on the Operators SDK.
Ensure this is installed and available in your $PATH.
v1.21.0 is being used for managed-upgrade-operator development.
operator-sdk version
operator-sdk version: "v1.21.0", commit: "89d21a133750aee994476736fa9523656c793588", kubernetes version: "1.23", go version: "go1.17.10", GOOS: "linux", GOARCH: "amd64"All available standardized commands for the Makefile are available via:
make
Usage: make <OPTIONS> ... <TARGETS>
Available targets are:
go-build Build binary
go-check Golang linting and other static analysis
go-test runs go test across operator
boilerplate-update Make boilerplate update itself
help Show this help screen.
run Run operator locally against the configured Kubernetes cluster in ~/.kube/config
tools Install local go tools for MUOThe tool dependencies that are required locally to be present are all part of tools.go file. This file will refer the version of the required module from go.mod file.
In order to install the tool dependencies locally, run make tools at the root of the cloned repository, which will fetch the tools for you and install the binaries at location $GOPATH/bin by default:
make toolsThis will make sure that the installed binaries are always as per the required version mentioned in go.mod file. If the version of the module is changed, need to run the command again locally to have new version of tools.
NOTE
If any of the dependencies are failing to install due to checksum mismatch, try setting GOPROXY env variable using export GOPROXY="https://proxy.golang.org" and run make tools again
To run lint locally, call make lint
make lintTo run unit tests locally, call make go-test
make go-testTo run go build locally, call make go-build
make go-buildTo run lint, test and build in app-sre/boilerplate container, call boilerplate/_lib/container-make. This will call make inside the app-sre/boilerplate container.
boilerplate/_lib/container-makeWhen building on macOS, the boilerplate container-based build approach make container-build is not supported due to limitations with running Podman-in-Podman in a cross-platform environment. Instead, macOS users should use make go-mac-build
to build arm64 image podman build --platform=linux/amd64 -t quay.io/[$PERSONAL_REPO]/managed-upgrade-operator:[$IMAGE_VERSION] -f build/Dockerfile .
- Make sure you have the operator-sdk in your
$PATH. - Install an OSD cluster using staging or integration environment. Make sure to use CCS option.
- Once the cluster installs, create a user with
cluster-adminrole and log in usingocclient. - Scale down existing MUO deployment and delete the leader lease:
oc scale deployment managed-upgrade-operator -n openshift-managed-upgrade-operator --replicas=0
oc delete lease managed-upgrade-operator-lock -n openshift-managed-upgrade-operator- Apply the LOCAL mode ConfigMap. This prevents OCM from deleting manually-created UpgradeConfigs and ignores the
UpgradeConfigSyncFailureOver4HrSREalert that fires when the deployed MUO is scaled down:
oc apply -f test/deploy/managed-upgrade-operator-config.yaml -n openshift-managed-upgrade-operator- Switch to the MUO service account. The operator must run as this account to bypass webhooks that block UpgradeConfig modifications:
oc login $(oc get infrastructures cluster -o json | jq -r '.status.apiServerURL') \
--token=$(oc create token managed-upgrade-operator -n openshift-managed-upgrade-operator)- Apply an UpgradeConfig CR. Edit
test/deploy/upgrade.managed.openshift.io_v1alpha1_upgradeconfig_cr.yamlwith your desired version and channel, then apply it:
oc apply -f test/deploy/upgrade.managed.openshift.io_v1alpha1_upgradeconfig_cr.yaml- Run the operator.
ROUTES=truetells MUO to use OpenShift Routes to reach Prometheus and Alertmanager, which is the simplest option for local development:
ROUTES=true OSDK_FORCE_RUN_MODE=local make runNote: If you prefer using internal cluster services instead of routes, see the
development/port-forwardsscript. This approach requires/etc/hostsentries and port-forwards but replicates the production network path.
- Build the image. In this example, we will use Quay as the container registry for our image:
make docker-build IMG=quay.io/<QUAY_USERNAME>/managed-upgrade-operator:latest- Setup quay registry and push the image:
podman push quay.io/<QUAY_USERNAME>/managed-upgrade-operator:latest-
Login to
ocas admin -
Ensure no other instances of managed-upgrade-operator are actively running on your cluster, as they may conflict. If MUO is already deployed on the cluster scale the deployment down to 0:
oc scale deployment managed-upgrade-operator -n <EXISTING_MUO_NAMESPACE> --replicas=0- Create a project for the operator to run inside of:
oc new-project test-managed-upgrade-operator- Deploy the service account, clusterrole, clusterrolebinding and ConfigMap on your target cluster:
oc create -f deploy/cluster_role.yaml
oc create -f test/deploy/managed_upgrade_role.yaml
oc create -f deploy/prometheus_role.yaml
oc create -f test/deploy/cluster_role_binding.yaml
oc create -f test/deploy/managed_upgrade_rolebinding.yaml
oc create -f test/deploy/prometheus_rolebinding.yaml
oc create -f test/deploy/monitoring_reader_role.yaml
oc create -f test/deploy/pullsecret_reader_role.yaml
oc create -f test/deploy/monitoring_reader_rolebinding.yaml
oc create -f test/deploy/pullsecret_reader_rolebinding.yaml
oc create -f test/deploy/service_account.yaml
oc create -f test/deploy/managed-upgrade-operator-config.yaml- Set
test/deploy/operator.yamlto usequay.io/<QUAY_USERNAME>/managed-upgrade-operator:latestcontainer image and create deployment configuration by updating theimagefield:
containers:
- name: managed-upgrade-operator
# Update the line below
image: quay.io/<QUAY_USERNAME>/managed-upgrade-operator:latest- Then create the
Deploymentresource:
oc create -f test/deploy/operator.yaml- Trigger a reconcile loop by applying an upgradeconfig CR with your desired specs:
oc create -f - <<EOF
apiVersion: upgrade.managed.openshift.io/v1alpha1
kind: UpgradeConfig
metadata:
name: managed-upgrade-config
spec:
type: "OSD"
upgradeAt: "2020-01-01T00:00:00Z"
PDBForceDrainTimeout: 60
desired:
channel: "fast-4.7"
version: "4.7.18"
EOFNOTE
Refer to fast-4.7 for currently available versions in fast-4.7 channel.
- After applying an
upgradeConfig, you should see your upgrade progressing
oc get upgrade -n test-managed-upgrade-operator- Inspect
upgradeConfig:
oc describe upgrade -n test-managed-upgrade-operator managed-upgrade-config - It can be useful to monitor the events in
test-managed-upgrade-operatornamespace during the upgrade:
oc get event -n test-managed-upgrade-operator -w- To see messages from MUO, inspect
MUO containerlogs intest-managed-upgrade-operatornamespace:
oc logs <MUO POD> -n test-managed-upgrade-operator -f- To follow upgrade status, get
clusterversion:
oc get clusterversion -w- To follow upgrade messages, inspect
cluster-version-operatorpod logs inopenshift-cluster-version namespace:
oc logs cluster-version-operator-<POD-ID> -n openshift-cluster-version -fWe can leverage the script for maintenance:
python hack/maintenance-update.pyOverall the script does the following:
- By default, update the common dependencies like
github.com/openshift-online/ocm-sdk-go,github.com/openshift/osde2e-common - If specified then update dependencies as per required OpenShift version (Eg. release-4.19)
- Run go mod tidy on the changes
- Validate the changes with boilerplate validations
- Review and add/commit the changes if all seems good so far
- Update boilerplate
- Perform validations again
- Review and add/commit the changes if all seems good so far
For the periodic maintenance, can leverage the script as follows:
# To update existing deps to latest version
python hack/maintenance-update.py
# To update deps to a specific Openshift release
python hack/maintenance-update.py --release release-4.19