Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,94 @@ deploy-olm: undeploy-olm ## Build current branch operator image, bundle image, p
chmod -R 777 $(DEPLOY_TMP) && rm -rf $(DEPLOY_TMP)
$(OPERATOR_SDK) run bundle --security-context-config restricted $(THIS_BUNDLE_IMAGE) --namespace $(OADP_TEST_NAMESPACE)

##@ Velero PR Testing

# Configuration for Velero PR builds
VELERO_REPO_PATH ?= $(HOME)/git/velero
# Use github.user if set, otherwise try to extract from git remote, fallback to "unknown"
GHCR_USER ?= $(shell git config github.user 2>/dev/null || (git config remote.origin.url 2>/dev/null | sed -n 's/.*github\.com[:/]\([^/]*\)\/.*/\1/p') || echo "unknown")
VELERO_IMAGE_TAG ?= pr$(VELERO_PR_NUMBER)
VELERO_IMAGE ?= ghcr.io/$(GHCR_USER)/velero:$(VELERO_IMAGE_TAG)

.PHONY: build-velero-pr
build-velero-pr: ## Build Velero image from a PR. Usage: make build-velero-pr VELERO_PR_NUMBER=9407
ifndef VELERO_PR_NUMBER
$(error VELERO_PR_NUMBER is required. Usage: make build-velero-pr VELERO_PR_NUMBER=9407)
endif
@echo "Building Velero from PR #$(VELERO_PR_NUMBER)..."
@echo "Velero repo path: $(VELERO_REPO_PATH)"
@echo "Target image: $(VELERO_IMAGE)"
@if [ ! -d "$(VELERO_REPO_PATH)" ]; then \
echo "Error: Velero repository not found at $(VELERO_REPO_PATH)"; \
echo "Please clone it first: git clone https://github.com/openshift/velero $(VELERO_REPO_PATH)"; \
exit 1; \
fi
@echo "Checking out oadp-dev branch..."
cd $(VELERO_REPO_PATH) && git checkout oadp-dev
@echo "Pulling latest oadp-dev..."
cd $(VELERO_REPO_PATH) && git pull openshift oadp-dev
@echo "Fetching PR #$(VELERO_PR_NUMBER) from upstream..."
cd $(VELERO_REPO_PATH) && git fetch upstream pull/$(VELERO_PR_NUMBER)/head:pr-$(VELERO_PR_NUMBER)
@echo "Cherry-picking PR commits..."
@echo "Note: If cherry-pick has conflicts, you may need to resolve them manually in $(VELERO_REPO_PATH)"
cd $(VELERO_REPO_PATH) && \
(git cherry-pick upstream/main..pr-$(VELERO_PR_NUMBER) || \
(if git status | grep -q "nothing to commit"; then \
echo "Cherry-pick resulted in empty commit (changes already present), skipping..."; \
git cherry-pick --skip; \
else \
echo "Cherry-pick failed with conflicts. Please resolve conflicts in $(VELERO_REPO_PATH)"; \
exit 1; \
fi))
@echo "Building Velero image using Dockerfile.ubi..."
cd $(VELERO_REPO_PATH) && $(CONTAINER_TOOL) build -f Dockerfile.ubi -t "$(VELERO_IMAGE)" .
@echo "Build complete: $(VELERO_IMAGE)"

.PHONY: push-velero-pr
push-velero-pr: ## Push Velero PR image to GHCR. Usage: make push-velero-pr VELERO_PR_NUMBER=9407
ifndef VELERO_PR_NUMBER
$(error VELERO_PR_NUMBER is required. Usage: make push-velero-pr VELERO_PR_NUMBER=9407)
endif
@echo "Pushing $(VELERO_IMAGE) to GitHub Container Registry..."
@echo "Note: Make sure you're authenticated to ghcr.io (docker login ghcr.io)"
$(CONTAINER_TOOL) push "$(VELERO_IMAGE)"
@echo "Push complete: $(VELERO_IMAGE)"

.PHONY: deploy-olm-velero-pr
deploy-olm-velero-pr: THIS_OPERATOR_IMAGE?=ttl.sh/oadp-operator-velero-pr$(VELERO_PR_NUMBER)-$(GIT_REV):$(TTL_DURATION)
deploy-olm-velero-pr: THIS_BUNDLE_IMAGE?=ttl.sh/oadp-operator-velero-pr$(VELERO_PR_NUMBER)-bundle-$(GIT_REV):$(TTL_DURATION)
deploy-olm-velero-pr: DEPLOY_TMP:=$(shell mktemp -d)/
deploy-olm-velero-pr: build-velero-pr push-velero-pr undeploy-olm ## Build Velero from PR, build OADP operator with custom Velero image, and deploy via OLM. Usage: make deploy-olm-velero-pr VELERO_PR_NUMBER=9407
ifndef VELERO_PR_NUMBER
$(error VELERO_PR_NUMBER is required. Usage: make deploy-olm-velero-pr VELERO_PR_NUMBER=9407)
endif
@make versions
@echo "DEPLOY_TMP: $(DEPLOY_TMP)"
@echo "Using custom Velero image: $(VELERO_IMAGE)"
# Copy project to temp directory and modify manager.yaml to use custom Velero image
cp -r . $(DEPLOY_TMP) && cd $(DEPLOY_TMP) && \
$(SED) -i 's|value: quay.io/konveyor/velero:latest|value: $(VELERO_IMAGE)|g' config/manager/manager.yaml && \
IMG=$(THIS_OPERATOR_IMAGE) BUNDLE_IMG=$(THIS_BUNDLE_IMAGE) \
make docker-build docker-push bundle bundle-build bundle-push; \
chmod -R 777 $(DEPLOY_TMP) && rm -rf $(DEPLOY_TMP)
$(OPERATOR_SDK) run bundle --security-context-config restricted $(THIS_BUNDLE_IMAGE) --namespace $(OADP_TEST_NAMESPACE)
@echo ""
@echo "=========================================================================="
@echo "OADP operator deployed with custom Velero image from PR #$(VELERO_PR_NUMBER)"
@echo "Velero image: $(VELERO_IMAGE)"
@echo "=========================================================================="

.PHONY: undeploy-olm-velero-pr
undeploy-olm-velero-pr: undeploy-olm ## Cleanup OADP deployment and reset Velero repo to oadp-dev branch
@echo "Cleaning up Velero repository..."
@if [ -d "$(VELERO_REPO_PATH)" ]; then \
echo "Resetting $(VELERO_REPO_PATH) to oadp-dev branch..."; \
cd $(VELERO_REPO_PATH) && git checkout oadp-dev && git reset --hard openshift/oadp-dev; \
echo "Deleting PR branch if it exists..."; \
cd $(VELERO_REPO_PATH) && git branch -D pr-$(VELERO_PR_NUMBER) 2>/dev/null || true; \
fi
@echo "Cleanup complete"

.PHONY: undeploy-olm
undeploy-olm: login-required operator-sdk ## Uninstall current branch operator via OLM
$(OC_CLI) whoami # Check if logged in
Expand Down
284 changes: 284 additions & 0 deletions docs/developer/testing_with_velero_prs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
# Testing OADP with Custom Velero PRs

This guide explains how to test OADP operator with a custom Velero build from an upstream PR. This is useful when you need to verify OADP compatibility with upcoming Velero changes or test bug fixes before they're merged.

## Overview

The `make deploy-olm-velero-pr` target automates the process of:
1. Fetching a PR from vmware-tanzu/velero
2. Cherry-picking it onto openshift/velero's oadp-dev branch
3. Building a custom Velero image
4. Deploying OADP operator with that custom Velero image

## Prerequisites

### 1. Velero Repository

Clone the OpenShift Velero fork and configure remotes:

```bash
# Clone the repository
git clone https://github.com/openshift/velero ~/git/velero
cd ~/git/velero

# Add upstream remote
git remote add upstream https://github.com/vmware-tanzu/velero
git fetch --all
```

If you want to use a different location, set `VELERO_REPO_PATH`:
```bash
export VELERO_REPO_PATH=/path/to/your/velero
```

### 2. Container Registry Authentication

Authenticate to GitHub Container Registry:

```bash
# Create a GitHub Personal Access Token with 'write:packages' scope
# Then login:
docker login ghcr.io -u YOUR_GITHUB_USERNAME
# Or with podman:
podman login ghcr.io -u YOUR_GITHUB_USERNAME
```

### 3. OpenShift Cluster Access

Ensure you're logged into an OpenShift cluster:

```bash
oc login <your-cluster-url>
```

## Usage

### Quick Start - Full Workflow

Deploy OADP with a custom Velero build from PR #9407:

```bash
make deploy-olm-velero-pr VELERO_PR_NUMBER=9407
```

This single command will:
1. Build the Velero image from the PR
2. Push it to `ghcr.io/<your-username>/velero:pr9407`
3. Build OADP operator with the custom image reference
4. Deploy via OLM to your cluster

### Custom Parameters

Override default settings:

```bash
make deploy-olm-velero-pr \
VELERO_PR_NUMBER=9407 \
GHCR_USER=myusername \
VELERO_REPO_PATH=/custom/path/to/velero \
VELERO_IMAGE_TAG=custom-tag
```

**Available parameters:**
- `VELERO_PR_NUMBER` (required): PR number from vmware-tanzu/velero
- `VELERO_REPO_PATH` (optional): Path to velero repository (default: `~/git/velero`)
- `GHCR_USER` (optional): GitHub username for GHCR (default: from `git config user.name`)
- `VELERO_IMAGE_TAG` (optional): Custom image tag (default: `pr<number>`)
- `VELERO_IMAGE` (optional): Full image override

### Step-by-Step Workflow

If you need more control over the process:

#### 1. Build Velero Image

```bash
make build-velero-pr VELERO_PR_NUMBER=9407
```

This will:
- Checkout `oadp-dev` branch
- Fetch PR from upstream
- Cherry-pick commits
- Build using `Dockerfile.ubi`

#### 2. Push to Registry

```bash
make push-velero-pr VELERO_PR_NUMBER=9407
```

#### 3. Deploy OADP (skip Velero build/push)

If you've already built and pushed the image separately:

```bash
make deploy-olm RELATED_IMAGE_VELERO=ghcr.io/myuser/velero:pr9407
```

### Cleanup

Remove the deployment and reset the Velero repository:

```bash
make undeploy-olm-velero-pr VELERO_PR_NUMBER=9407
```

This will:
- Undeploy OADP operator via OLM
- Reset Velero repository to clean `oadp-dev` branch
- Delete the PR branch

## Troubleshooting

### Cherry-pick Conflicts

If the PR has conflicts with `oadp-dev`:

```bash
cd ~/git/velero
# Resolve conflicts manually
git status
# Edit conflicting files
git add <resolved-files>
git cherry-pick --continue
```

Then continue with the build:

```bash
make build-velero-pr VELERO_PR_NUMBER=9407
```

### Build Failures

Check the Velero Dockerfile.ubi requirements:
```bash
cd ~/git/velero
cat Dockerfile.ubi
```

Ensure all build dependencies are available.

### Image Push Issues

Verify GHCR authentication:
```bash
docker login ghcr.io
# Test with a simple push
docker pull alpine:latest
docker tag alpine:latest ghcr.io/$USER/test:latest
docker push ghcr.io/$USER/test:latest
```

### Verify Deployment

Check that the custom Velero image is being used:

```bash
oc get deployment velero -n openshift-adp -o jsonpath='{.spec.template.spec.containers[0].image}'
```

Expected output: `ghcr.io/<your-user>/velero:pr9407`

## Example Workflow

Complete example testing Velero PR #9407:

```bash
# 1. Ensure prerequisites
oc login https://api.my-cluster.com:6443
docker login ghcr.io

# 2. Deploy OADP with custom Velero
make deploy-olm-velero-pr VELERO_PR_NUMBER=9407

# 3. Verify deployment
oc get pods -n openshift-adp
oc get deployment velero -n openshift-adp -o yaml | grep image:

# 4. Test your scenario
# ... run your tests ...

# 5. Cleanup
make undeploy-olm-velero-pr VELERO_PR_NUMBER=9407
```

## How It Works

### Image Reference Replacement

The target modifies `config/manager/manager.yaml` to replace:
```yaml
- name: RELATED_IMAGE_VELERO
value: quay.io/konveyor/velero:latest
```

With:
```yaml
- name: RELATED_IMAGE_VELERO
value: ghcr.io/<user>/velero:pr<number>
```

This environment variable is read by the OADP operator to determine which Velero image to deploy.

### Temporary Build Directory

Similar to `deploy-olm`, the target uses a temporary directory for the build to avoid modifying your working tree. All changes to `config/manager/manager.yaml` are isolated to the build.

### Bundle Image Naming

The bundle image includes the PR number for easy identification:
```
ttl.sh/oadp-operator-velero-pr9407-<git-rev>:1h
```

## Advanced Usage

### Testing Multiple PRs

To test multiple Velero PRs in sequence:

```bash
for pr in 9407 9408 9409; do
echo "Testing PR #$pr"
make deploy-olm-velero-pr VELERO_PR_NUMBER=$pr
# Run your tests
./run-tests.sh
make undeploy-olm-velero-pr VELERO_PR_NUMBER=$pr
done
```

### Using Local Velero Changes

If you have local changes in the Velero repository:

```bash
cd ~/git/velero
# Make your changes
git add .
git commit -m "Local changes"

# Build and deploy without cherry-picking
cd ~/oadp-operator
make build-velero-pr VELERO_PR_NUMBER=local
make push-velero-pr VELERO_PR_NUMBER=local
```

### Persistent Image Tag

Use a custom tag that doesn't include the PR number:

```bash
make deploy-olm-velero-pr \
VELERO_PR_NUMBER=9407 \
VELERO_IMAGE_TAG=my-test-build
```

Image will be: `ghcr.io/<user>/velero:my-test-build`

## Related Documentation

- [Install from Source](install_from_source.md) - General development deployment guide
- [Testing Guide](testing/TESTING.md) - E2E testing documentation
- [OLM Hacking](olm_hacking.md) - Working with OLM bundles
Loading