### Start Minikube Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/minikube-without-olm.md Starts the Minikube local Kubernetes cluster. Ensure Minikube is installed and configured. ```sh minikube start ``` -------------------------------- ### ConfigMap with Mount-on-Start Annotation Source: https://github.com/devfile/devworkspace-operator/blob/main/CHANGELOG.md This ConfigMap example demonstrates the use of the `controller.devfile.io/mount-on-start: "true"` annotation. Setting this annotation prevents immediate workspace restarts when automounted resources are created or modified, deferring the mount until the next workspace start. ```yaml apiVersion: v1 kind: ConfigMap metadata: annotations: controller.devfile.io/mount-as: env controller.devfile.io/mount-on-start: "true" labels: controller.devfile.io/mount-to-devworkspace: "true" controller.devfile.io/watch-configmap: "true" name: my-config ``` -------------------------------- ### Start a DevWorkspace Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Use this command to start a DevWorkspace by setting the 'started' spec to true. ```bash kubectl patch dw --type merge -p '{"spec": {"started": true}}' ``` -------------------------------- ### Install Ginkgo for Testing Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Installs the Ginkgo testing framework, which is recommended for running the full test suite of the DevWorkspace Operator. ```bash go install github.com/onsi/ginkgo/v2/ginkgo@latest ``` -------------------------------- ### Install MetalLB Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-macos.md Apply the MetalLB manifest to install it on your cluster. Ensure MetalLB pods are ready before proceeding. ```sh kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.9/config/manifests/metallb-native.yaml ``` -------------------------------- ### Install cert-manager Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-linux.md Applies the cert-manager manifest to install the certificate management system. Ensure pods become ready. ```sh kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.15.4/cert-manager.yaml ``` ```sh kubectl wait --namespace cert-manager \ --timeout 90s \ --for=condition=ready pod \ --selector=app.kubernetes.io/instance=cert-manager ``` -------------------------------- ### Run DevWorkspace Controller Locally Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Set the NAMESPACE, install the operator, wait for deployments, scale down the on-cluster deployment, and then run the controller locally. This setup avoids conflicts with the cluster-deployed instance. ```bash export NAMESPACE="devworkspace-controller" make install # Wait for webhook server to start kubectl rollout status deployment devworkspace-controller-manager -n $NAMESPACE --timeout 90s kubectl rollout status deployment devworkspace-webhook-server -n $NAMESPACE --timeout 90s # Scale on-cluster deployment to zero to avoid conflict with locally-running instance oc patch deployment/devworkspace-controller-manager --patch "{\"spec\":{\"replicas\":0}}" -n $NAMESPACE make run ``` -------------------------------- ### Mount Resource on Workspace Start Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/additional-configuration.adoc Set the `controller.devfile.io/mount-on-start` annotation to `true` to ensure the resource is mounted automatically when a DevWorkspace starts. ```yaml metadata: annotations: controller.devfile.io/mount-on-start: "true" ``` -------------------------------- ### Install Cert-Manager Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Install cert-manager to the cluster. This step can be skipped if you are deploying on OpenShift. ```bash make install_cert_manager && \ kubectl wait --for=condition=Available -n cert-manager deployment/cert-manager ``` -------------------------------- ### Install NGINX Ingress Controller Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-macos.md Apply the manifest to install the NGINX ingress controller. This is necessary for external access to services within the cluster. ```sh kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml ``` -------------------------------- ### Install Homebrew Make and Coreutils on macOS Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md On macOS, install newer versions of make and coreutils using Homebrew to resolve potential Makefile issues. Ensure they are added to your PATH. ```bash brew install coreutils make ``` ```bash export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH" export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH" ``` -------------------------------- ### Run Webhook Server Locally for Debugging Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Starts the webhook server locally using telepresence for debugging. Telepresence redirects cluster traffic to the local instance. ```bash make debug-webhook-server ``` -------------------------------- ### Install cert-manager Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-macos.md Apply the cert-manager installation manifest. cert-manager is required for managing TLS certificates within the cluster. ```sh kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.15.4/cert-manager.yaml ``` -------------------------------- ### Install NGINX Ingress Controller Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-linux.md Applies the NGINX ingress controller manifest. Wait for the controller pods to be ready before proceeding. ```sh kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml ``` ```sh kubectl wait --namespace ingress-nginx \ --for=condition=ready pod \ --selector=app.kubernetes.io/component=controller \ --timeout=90s ``` -------------------------------- ### Get DevWorkspace IDE URL Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Retrieve the IDE URL for a started DevWorkspace by executing the `kubectl get devworkspace` command. ```bash kubectl get devworkspace -n ``` -------------------------------- ### Create DevWorkspace Operator Subscription Source: https://github.com/devfile/devworkspace-operator/blob/main/README.md Creates an OLM Subscription to install the operator from the previously configured catalog. ```bash kubectl apply -f - <` with the target namespace. ```bash kubectl apply -f ./samples/code-latest.yaml -n ``` -------------------------------- ### Single-Architecture Build Workflow Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Build and push images for a specific architecture (amd64 or arm64) for faster development cycles. ```bash make docker-build-amd64 make docker-push-amd64 ``` ```bash make docker-build-arm64 make docker-push-arm64 ``` -------------------------------- ### Run All Tests Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Executes all unit and controller tests using Ginkgo if available, otherwise falls back to 'go test'. Ensure Ginkgo is in your PATH. ```bash make test ``` -------------------------------- ### Build and deploy custom images for prerelease testing Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/release/README.md Use these commands to manually build and push container images for testing release branches before the official release job is triggered. ```bash export DWO_IMG=quay.io/yourrepo/devworkspace-controller:prerelease export PROJECT_CLONE_IMG=quay.io/yourrepo/project-clone:prerelease export PROJECT_BACKUP_IMG=quay.io/yourrepo/project-backup:prerelease # build and push project clone image podman build -t "$PROJECT_CLONE_IMG" -f ./project-clone/Dockerfile . podman push "$PROJECT_CLONE_IMG" # build and push project backup image podman build -t "$PROJECT_BACKUP_IMG" -f ./project-backup/Containerfile ./project-backup/ podman push "$PROJECT_BACKUP_IMG" # build and push DevWorkspace Operator image export DOCKER=podman # optional make docker # deploy DevWorkspace Operator using these images make install ``` -------------------------------- ### Build Custom OLM Bundle Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Builds a custom Operator Lifecycle Manager (OLM) bundle and index image, then registers the catalogsource to the cluster. Requires setting specific environment variables. ```bash make generate_olm_bundle_yaml build_bundle_and_index register_catalogsource ``` -------------------------------- ### Initialize Infrastructure Detection Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Always call infrastructure.Initialize() before using infrastructure.IsOpenShift(). This prevents panics and ensures the cluster type is correctly determined. ```go func init() { err := infrastructure.Initialize() if err != nil { setupLog.Error(err, "could not determine cluster type") os.Exit(1) } if infrastructure.IsOpenShift() { // OpenShift-specific initialization } } ``` -------------------------------- ### Create Sample DevWorkspace Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/minikube-without-olm.md Creates a sample DevWorkspace resource named 'git-clone-sample-devworkspace'. This includes defining projects from Git repositories and a command to execute within the workspace. Ensure the `CODE_HOST` environment variable is correctly set if using Che-Code. ```yaml kind: DevWorkspace apiVersion: workspace.devfile.io/v1alpha2 metadata: name: git-clone-sample-devworkspace spec: started: true template: projects: - name: web-nodejs-sample git: remotes: origin: "https://github.com/che-samples/web-nodejs-sample.git" - name: devworkspace-operator git: checkoutFrom: remote: origin revision: 0.21.x remotes: origin: "https://github.com/devfile/devworkspace-operator.git" amisevsk: "https://github.com/amisevsk/devworkspace-operator.git" commands: - id: say-hello exec: component: che-code-runtime-description commandLine: echo "Hello from $(pwd)" workingDir: ${PROJECT_SOURCE}/app contributions: - name: che-code uri: https://eclipse-che.github.io/che-plugin-registry/main/v3/plugins/che-incubator/che-code/latest/devfile.yaml components: - name: che-code-runtime-description container: env: - name: CODE_HOST value: 0.0.0.0 ``` -------------------------------- ### Detect Infrastructure Environment Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Check for OpenShift or Kubernetes environments, ensuring initialization occurs before usage to avoid panics. ```go infrastructure.IsOpenShift() ``` ```go infrastructure.Initialize() ``` ```go infrastructure.InitializeForTesting() ``` -------------------------------- ### Build and Publish DevWorkspace Controller Image Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Build the controller Go code, then build and publish the container image to your configured container registry. ```bash make docker ``` -------------------------------- ### Select Kubernetes Client Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Choose between the standard cached client and the non-caching client based on data freshness requirements. ```go NonCachingClient ``` ```go Client ``` -------------------------------- ### Add DevWorkspace Operator CatalogSource Source: https://github.com/devfile/devworkspace-operator/blob/main/README.md Applies a CatalogSource manifest to the cluster to make the operator available for installation. ```bash kubectl apply -f - < /tmp/ssh_config host * IdentityFile /etc/ssh/dwo_ssh_key StrictHostKeyChecking = no EOF ``` -------------------------------- ### Configure Workspace Storage Access Mode Source: https://github.com/devfile/devworkspace-operator/blob/main/CHANGELOG.md Example of DevWorkspaceOperatorConfig to set the storage access mode for per-user and per-workspace PVCs. Use 'ReadWriteMany' for shared access. ```yaml apiVersion: controller.devfile.io/v1alpha1 kind: DevWorkspaceOperatorConfig metadata: name: devworkspace-operator-config namespace: $OPERATOR_INSTALL_NAMESPACE config: workspace: imagePullPolicy: Always storageAccessMode: - ReadWriteMany ``` -------------------------------- ### Get Service Account Token for Local Metrics Access Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/grafana/README.md Generates a 1-hour valid token for the devworkspace-controller-serviceaccount. This token is used for authenticating local access to the metrics endpoint. ```bash TOKEN=$(kubectl create token devworkspace-controller-serviceaccount -n ${NAMESPACE} --duration=1h) ``` -------------------------------- ### Applying Container Overrides for Resource Limits Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/additional-configuration.adoc Use `container-overrides` on a container component to set resource limits, such as GPU allocation. This example configures the `nvidia.com/gpu` limit for the `web-terminal` component. ```yaml kind: DevWorkspace apiVersion: workspace.devfile.io/v1alpha2 metadata: name: example-devworkspace spec: started: true template: components: - name: web-terminal attributes: container-overrides: {"resources":{"limits":{"nvidia.com/gpu":"1"}}} ``` -------------------------------- ### Create DevWorkspaceOperatorConfig Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/kind-without-olm-macos.md Create the DevWorkspaceOperatorConfig resource, specifying the clusterHostSuffix using the obtained Load Balancer IP. Replace '' with the actual IP address. ```sh kubectl apply -f - <.nip.io" EOF ``` -------------------------------- ### Enable Minikube Ingress Addon Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/minikube-without-olm.md Enables the Ingress addon for Minikube, which is required for external access to services. ```sh minikube addons enable ingress ``` -------------------------------- ### Enable Backup CronJob with Regular OCI Registry Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/dwo-configuration.md Configure the DevWorkspaceOperatorConfig to enable the backup job, specify a regular OCI-compatible registry path, and provide an authentication secret. The schedule is set to run every 4 hours. ```yaml kind: DevWorkspaceOperatorConfig apiVersion: controller.devfile.io/v1alpha1 metadata: name: devworkspace-operator-config namespace: $OPERATOR_INSTALL_NAMESPACE config: routing: defaultRoutingClass: basic workspace: backupCronJob: enable: true registry: authSecret: my-secret path: quay.io/my-company-org schedule: '0 */4 * * *' imagePullPolicy: Always ``` -------------------------------- ### Include Workspaces for Mounting Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/additional-configuration.adoc Use the `controller.devfile.io/mount-to-devworkspace-include` annotation to specify which workspaces a resource should be mounted to. Supports comma-separated values and wildcard patterns. ```yaml metadata: annotations: controller.devfile.io/mount-to-devworkspace-include: "my-workspace, staging-*" ``` -------------------------------- ### Get DevWorkspace ID using kubectl and jq Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/workspace-capabilities.md This bash command retrieves the DevWorkspace ID from a Kubernetes DevWorkspace object using `kubectl` and `jq`. The ID is used to construct the service account name for the workspace. ```bash DEVWORKSPACE_ID=$(kubectl get devworkspaces -o json | jq -r '.status.devworkspaceId') ``` -------------------------------- ### Wait for cert-manager Pods Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/minikube-without-olm.md Waits for cert-manager pods in the 'cert-manager' namespace to become ready. This ensures cert-manager is fully operational before proceeding. ```sh kubectl wait --namespace cert-manager \ --timeout 90s \ --for=condition=ready pod \ --selector=app.kubernetes.io/instance=cert-manager ``` -------------------------------- ### Create DevWorkspaceOperatorConfig Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/minikube-without-olm.md Applies a DevWorkspaceOperatorConfig resource to configure the operator's routing. Replace with the actual Minikube IP obtained previously. The `clusterHostSuffix` is set to `.nip.io`. ```yaml apiVersion: controller.devfile.io/v1alpha1 kind: DevWorkspaceOperatorConfig metadata: name: devworkspace-operator-config namespace: devworkspace-controller config: routing: clusterHostSuffix: ".nip.io" ``` -------------------------------- ### Fail Workspace with FailureReason Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Call failWorkspace with an appropriate FailureReason when a workspace encounters a failure. This marks the workspace as failed and provides a reason for the failure. ```go return r.failWorkspace( workspace, "Error message", metrics.ReasonInfrastructureFailure, // or ReasonBadRequest, ReasonWorkspaceEngineFailure log, status, ) ``` -------------------------------- ### External Controller Test Pattern Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Standard pattern for writing controller tests using an external test package. It utilizes Ginkgo and Gomega for defining test suites and assertions, including setting up resources and verifying their state over time. ```go package controllers_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) var _ = Describe("DevWorkspace Controller", func() { It("Sets DevWorkspace ID and Starting status", func() { By("Creating a new DevWorkspace") // Create resource By("Checking DevWorkspace ID has been set") Eventually(func() (string, error) { // Get and return value }, timeout, interval).Should(Equal(expectedValue)) }) }) ``` -------------------------------- ### Combined Include and Exclude for Mounting Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/additional-configuration.adoc Combine `include` and `exclude` annotations to precisely control resource mounting. Resources are mounted only if they match the include pattern and do not match the exclude pattern. ```yaml metadata: annotations: controller.devfile.io/mount-to-devworkspace-include: "staging-*" controller.devfile.io/mount-to-devworkspace-exclude: "staging-legacy" ``` -------------------------------- ### Scale Controller to Zero Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md Scales the on-cluster controller deployment to zero replicas. This is done to avoid conflicts when running a local instance for debugging. ```bash oc patch deployment/devworkspace-controller-manager --patch "{"spec":{"replicas":0}}" ``` -------------------------------- ### Restore DevWorkspace from Backup Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/dwo-configuration.md Configure a DevWorkspace to restore its project content from a backup in an OCI registry. This is achieved by setting the `controller.devfile.io/restore-workspace` attribute to 'true'. Optionally, a custom restore source image can be specified using `controller.devfile.io/restore-source-image`. ```yaml kind: DevWorkspace spec: template: attributes: controller.devfile.io/restore-workspace: 'true' # Optional: restore from a specific image instead of the default backup registry controller.devfile.io/restore-source-image: 'registry.example.com/my-backup:latest' ``` -------------------------------- ### Configure Devfile API Fork for Local Development Source: https://github.com/devfile/devworkspace-operator/blob/main/CONTRIBUTING.md When modifying Devfile or DevWorkspace schemas, configure environment variables to point to your fork of the devfile/api repository. This ensures `go mod` uses your local fork for development. ```bash export DEVFILE_API_REPO=github.com/l0rd/api # <== your devfile/api fork export DEVFILE_API_BRANCH=my-branch-name # <== the branch of your fork export DEVWORKSPACE_API_VERSION=$(git ls-remote https://${DEVFILE_API_REPO} | grep refs/heads/${DEVFILE_API_BRANCH} | cut -f 1) go mod edit -replace github.com/devfile/api/v2=${DEVFILE_API_REPO}/v2@${DEVWORKSPACE_API_VERSION} && \ go mod download && \ go mod tidy ``` -------------------------------- ### Scale Down Controller Deployment for Local Debugging Source: https://github.com/devfile/devworkspace-operator/blob/main/AGENTS.md Before running the controller locally, scale down the cluster deployment to avoid conflicts. This command targets the `devworkspace-controller-manager` deployment. ```bash kubectl scale deploy devworkspace-controller-manager -n devworkspace-controller --replicas=0 ``` -------------------------------- ### Create DevWorkspaces Namespace Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/installation/openshift-without-olm.md Creates a namespace specifically for DevWorkspace samples. This isolates sample DevWorkspaces from the operator's namespace. ```sh oc create namespace devworkspace-samples ``` -------------------------------- ### Webhook Deployment Configuration Source: https://github.com/devfile/devworkspace-operator/blob/main/docs/dwo-configuration.md Configure webhook server deployment options like replicas, tolerations, and nodeSelector within the global DWOC's config.webhook field. ```yaml apiVersion: controller.devfile.io/v1alpha1 kind: DevWorkspaceOperatorConfig metadata: name: devworkspace-operator-config namespace: $OPERATOR_INSTALL_NAMESPACE config: webhook: nodeSelector: tolerations: <[]tolerations> replicas: ```