# Testing Guide for ftrack Helm Chart

This guide provides instructions for setting up a local Kubernetes testing environment using Kind (Kubernetes in Docker) to test the ftrack Helm chart.

## System Requirements

### Required Dependencies

The following tools must be installed on your system:

#### 1. Docker
- **macOS**: [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/)
- **Linux**: Docker Engine (see installation instructions below)

#### 2. kubectl
Command-line tool for interacting with Kubernetes clusters.

#### 3. Helm
Package manager for Kubernetes (version 3.x or higher).

#### 4. Kind
Kubernetes in Docker - runs local Kubernetes clusters using Docker containers.

#### 5. Make (Optional but Recommended)
Build automation tool, typically pre-installed on macOS and Linux.

---

## Installation Instructions

### macOS Installation

Using [Homebrew](https://brew.sh/) (recommended):

```bash
# Install Docker Desktop from https://docs.docker.com/desktop/install/mac-install/
# Or use Homebrew Cask:
brew install --cask docker

# Install kubectl
brew install kubectl

# Install Helm
brew install helm

# Install Kind
brew install kind

# Verify Make is installed (usually pre-installed)
make --version
```

### Linux Installation

#### Ubuntu/Debian

```bash
# Install Docker
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

# Add your user to the docker group (logout/login required after this)
sudo usermod -aG docker $USER

# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

# Install Kind
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

# Verify Make is installed (usually pre-installed)
make --version
```

#### Fedora/RHEL/CentOS

```bash
# Install Docker
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER

# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

# Install Kind
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

# Verify Make is installed
make --version
```

---

## Database Setup

Before installing the chart, you need a MariaDB/MySQL database.

### Database Running on Host (Docker)

If you're running a database in Docker on your host machine, Kind pods cannot connect to `127.0.0.1`. You need to use your host's IP address:

```bash
# Get the host IP accessible from Kind cluster
make get-host-ip
```

Then update `values-test.yaml` with this IP:
```yaml
database:
  host: 172.18.0.1  # Replace with the IP from get-host-ip
  port: 3306
  user: your_db_user
  password: your_db_password
  name: ftrack
```

**Important:** Ensure your database allows connections from the Kind network (usually `172.18.0.0/16`).


## Quick Start

Once all dependencies are installed and the database is configured, you can use the provided Makefile to manage the test environment:



### 1. Create Kind Cluster
```bash
make create-cluster
```

### 2. Configure
See the Database Setup section above and update `values-test.yaml`

Set ftrack image registry password in .env file or export as environment variable:
```bash
export IMAGE_REGISTRY_PASSWORD="your_dockerhub_password"
```

### 3. Install ftrack Helm Chart
```bash
make install
```

For verbose output to debug issues:
```bash
make install-debug
```

### 4. Access ftrack
```bash
# Get the NodePort for accessing ftrack
kubectl get svc -n ftrack

# Forward port to access locally (run in a separate terminal)
make port-forward
```

Then open your browser to: http://localhost:8080




---

## Manual Setup (Without Make)

If you prefer to run commands manually:

### Create Kind Cluster
```bash
kind create cluster --name ftrack-test --config kind-config.yaml
```

### Verify Cluster
```bash
kubectl cluster-info --context kind-ftrack-test
kubectl get nodes
```

### Create Namespace
```bash
kubectl create namespace ftrack
```

### Install Helm Chart
```bash
helm install ftrack . \
  -n ftrack \
  -f values-test.yaml \
  --set imageRegistry.password="$IMAGE_REGISTRY_PASSWORD" \
  --wait \
  --timeout 10m
```

### Check Deployment
```bash
kubectl get pods -n ftrack
kubectl get svc -n ftrack
```

### Port Forward to Access ftrack
```bash
kubectl port-forward -n ftrack svc/nginx 8080:80
```

### Uninstall
```bash
helm uninstall ftrack -n ftrack
```

### Delete Cluster
```bash
kind delete cluster --name ftrack-test
```

---
## Additional Resources

- [Kind Documentation](https://kind.sigs.k8s.io/)
- [Helm Documentation](https://helm.sh/docs/)
- [Kubernetes Documentation](https://kubernetes.io/docs/)
- [Docker Documentation](https://docs.docker.com/)
