Git Integration
Nyl provides built-in Git repository management for fetching Helm charts and scanning application manifests from Git repositories. This enables declarative infrastructure management without requiring manual repository cloning.
Features
Section titled “Features”- Bare repositories: Minimal disk usage with shared object store
- Worktrees: Isolated checkouts for different refs (branches, tags, commits)
- Lazy fetching: Refs fetched first, objects downloaded on-demand
- Automatic caching: Repositories cached locally for fast subsequent access
- Concurrent access: Multiple refs from the same repository can be checked out simultaneously
Cache Directory
Section titled “Cache Directory”Nyl stores Git repositories in a cache directory to avoid redundant clones and improve performance.
Configuration
Section titled “Configuration”The cache directory is determined by:
NYL_CACHE_DIRenvironment variable (preferred).nyl/cache/in the current directory (fallback)
Example:
export NYL_CACHE_DIR=/var/cache/nylnyl render app.yamlCache Structure
Section titled “Cache Structure”$NYL_CACHE_DIR/git/├── bare/│ ├── {url_hash}-{repo_name}/ # Bare repository│ │ ├── objects/│ │ ├── refs/│ │ └── ...│ └── {url_hash2}-{repo_name2}/└── worktrees/ ├── {url_hash}-{ref_hash}/ # Worktree checkout ├── {url_hash}-{ref_hash2}/ # Another ref from same repo └── {url_hash2}-{ref_hash}/ # Different repoKey points:
- One bare repository per Git URL (shared object store)
- One worktree per unique URL + ref combination
- Worktrees share objects from bare repo (disk-efficient)
- URL and ref hashes ensure uniqueness and avoid conflicts
Using Git with HelmChart
Section titled “Using Git with HelmChart”HelmChart resources can reference Helm charts stored in Git repositories.
Basic Example
Section titled “Basic Example”apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: nginx namespace: defaultspec: chart: repository: git+https://github.com/bitnami/charts.git version: main name: bitnami/nginxParameters
Section titled “Parameters”repository: Git repository URL withgit+prefix (required)version: Branch, tag, or commit (optional, defaults to HEAD)name: Subdirectory within repository (optional)
Helm Dependencies
Section titled “Helm Dependencies”Nyl automatically detects and builds Helm chart dependencies for charts from Git repositories. When a chart contains a Chart.yaml with dependencies or a Chart.lock file, Nyl will:
- Detect the presence of dependencies
- Automatically run
helm dependency buildto fetch and build them - Continue with normal chart rendering
This means you can use charts with dependencies from Git repositories without any additional configuration:
# Chart.yaml in Git repositoryapiVersion: v2name: my-appversion: 1.0.0dependencies: - name: common version: "^1.0" repository: "oci://registry-1.docker.io/bitnamicharts" - name: postgresql version: "~12.0" repository: "https://charts.bitnami.com/bitnami"The dependencies will be automatically resolved when you reference this chart:
apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: my-appspec: chart: repository: git+https://github.com/example/charts.git version: main name: charts/my-app # Chart with dependencies release: name: my-app namespace: defaultSupported Ref Types
Section titled “Supported Ref Types”You can reference different types of Git refs:
Branch:
spec: chart: repository: git+https://github.com/example/charts.git version: mainTag:
spec: chart: repository: git+https://github.com/example/charts.git version: v2.1.0Commit SHA:
spec: chart: repository: git+https://github.com/example/charts.git version: abc123def456HEAD (default):
spec: chart: repository: git+https://github.com/example/charts.git # version defaults to HEADUsing Git with ApplicationGenerator
Section titled “Using Git with ApplicationGenerator”ApplicationGenerator resources scan Git repositories for Nyl manifests and automatically generate ArgoCD Applications.
Example
Section titled “Example”apiVersion: argocd.nyl.niklasrosenstein.github.com/v1kind: ApplicationGeneratormetadata: name: cluster-apps namespace: argocdspec: destination: server: https://kubernetes.default.svc namespace: argocd source: repoURL: https://github.com/example/gitops-demo.git targetRevision: main path: apps include: - "*.yaml" - "*.yml" exclude: - ".*" - "_*" project: defaultWhen rendered, Nyl will:
- Resolve repository source location (override, local checkout reuse, ArgoCD checkout reuse, or cached Git worktree)
- Use the
mainrevision - Navigate to the
apps/directory - Scan for YAML files matching the include/exclude patterns
- Generate ArgoCD Application manifests for each NylRelease found
ApplicationGenerator Resolution Order
Section titled “ApplicationGenerator Resolution Order”For ApplicationGenerator, Nyl resolves the source repository in this order:
NYL_APPGEN_REPO_PATH_OVERRIDE, if set- The current local Git checkout, if the current
PWDis inside a repository whose remote matchesspec.source.repoURL, andspec.source.targetRevisionisHEADor the current branch name - ArgoCD’s local checkout via
ARGOCD_APP_SOURCE_* - The normal Git cache/worktree flow
If one step does not match, Nyl falls through to the next step automatically.
Current Local Checkout Reuse
Section titled “Current Local Checkout Reuse”When you run Nyl from inside the same repository referenced by an ApplicationGenerator, Nyl can skip clone/worktree operations and reuse the current local checkout.
Reuse is enabled only when all of these conditions match:
- The current
PWDis inside a Git repository - At least one local remote matches
spec.source.repoURLafter normalization spec.source.targetRevisionisHEAD, or exactly matches the current checked-out branch name
Notes:
- Detached
HEADonly matchestargetRevision: HEAD - If the remote or revision does not match, Nyl falls back to ArgoCD checkout reuse or the normal Git cache/worktree flow
ArgoCD Local Checkout Reuse
Section titled “ArgoCD Local Checkout Reuse”When running in ArgoCD plugin context, Nyl can also reuse the local checkout that ArgoCD already prepared.
Reuse is enabled only when all of these conditions match exactly:
spec.source.repoURLequalsARGOCD_APP_SOURCE_REPO_URL(normalized URL comparison)spec.source.targetRevisionequalsARGOCD_APP_SOURCE_TARGET_REVISION(exact string match)ARGOCD_APP_SOURCE_PATHcan be resolved relative to the current working directory
If any condition does not match, Nyl falls back to the normal Git cache/worktree resolution.
Local Worktree Override (Testing)
Section titled “Local Worktree Override (Testing)”For local testing, you can bypass Git clone/worktree resolution and force all ApplicationGenerator resources to read from a local repository root:
export NYL_APPGEN_REPO_PATH_OVERRIDE=/path/to/local/reponyl render apps.yamlexport NYL_APPGEN_REPO_PATH_OVERRIDE=@gitnyl render apps.yamlBehavior:
- If
NYL_APPGEN_REPO_PATH_OVERRIDEis set to a local path, Nyl resolvesspec.source.path/spec.source.pathsselectors under that path. - If
NYL_APPGEN_REPO_PATH_OVERRIDE=@git, Nyl discovers the Git repository root from the currentPWDand resolves selectors under that root. - If unset, Nyl tries current local checkout reuse first, then ArgoCD checkout reuse, then normal Git clone/cache/worktree resolution from
spec.source.repoURLandspec.source.targetRevision. - If the override path is invalid, or
@gitis used outside a Git repository, rendering fails immediately.
Selector behavior:
source.pathscans the selected directory non-recursively by default.- Use glob selectors (for example
**/*.yaml) orsource.pathsfor multi-selector/recursive workflows. - Include/exclude patterns are matched against paths relative to the repository root.
Performance Characteristics
Section titled “Performance Characteristics”Initial Clone
Section titled “Initial Clone”- Lazy fetching: Only refs are fetched initially (~KB), not objects (~MB/GB)
- On-demand objects: Commit objects fetched only when needed
- Bandwidth efficient: Minimal initial download
Subsequent Access
Section titled “Subsequent Access”- Cache hit: Near-instant if ref already checked out
- Ref update: Only fetch new refs if branch updated
- Object reuse: Worktrees share objects from bare repo
Disk Usage
Section titled “Disk Usage”- Bare repo: One copy of objects for all refs
- Worktrees: Only working directory files (no .git directory)
- Efficient: Much smaller than full clones for each ref
Example disk usage for a 100MB repository with 3 refs:
- Traditional approach: 3 × 100MB = 300MB
- Nyl approach: 100MB (bare) + 3 × ~10MB (worktrees) = ~130MB
Authentication
Section titled “Authentication”Nyl supports both public and private Git repositories through multiple authentication methods.
Automatic Credential Discovery
Section titled “Automatic Credential Discovery”When running inside a Kubernetes cluster with access to ArgoCD secrets, Nyl automatically discovers repository credentials from ArgoCD repository secrets. No additional configuration required!
Example: Using a private Helm chart
apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: private-app namespace: defaultspec: chart: repository: git+git@github.com:myorg/private-charts.git version: main name: charts/appIf an ArgoCD repository secret exists for github.com, Nyl will automatically use those credentials.
Authentication Methods
Section titled “Authentication Methods”-
ArgoCD Repository Secrets (Recommended)
- Credentials automatically discovered from
argocdnamespace - Supports both SSH keys and HTTPS tokens
- Zero configuration required
- See Repository Secrets for details
- Credentials automatically discovered from
-
SSH Agent
- Fallback for SSH URLs when no secret found
- Works with local development workflows
- Requires SSH agent running with key loaded
-
Public Repositories
- No authentication needed
- Works out of the box
Supported Credential Types
Section titled “Supported Credential Types”SSH Key Authentication:
- Private key stored in ArgoCD secret
- Recommended for production use
- Better security than HTTPS tokens
HTTPS Token Authentication:
- Personal access tokens or passwords
- Useful for HTTPS-only repositories
- Stored in ArgoCD secret
Example: Creating Repository Secret
Section titled “Example: Creating Repository Secret”# SSH authenticationkubectl create secret generic github-private \ -n argocd \ --from-literal=url=git@github.com:myorg/charts.git \ --from-file=sshPrivateKey=$HOME/.ssh/id_rsa
kubectl label secret github-private \ -n argocd \ argocd.argoproj.io/secret-type=repository
# HTTPS authenticationkubectl create secret generic github-https \ -n argocd \ --from-literal=url=https://github.com/myorg/charts.git \ --from-literal=username=myuser \ --from-literal=password=ghp_token123
kubectl label secret github-https \ -n argocd \ argocd.argoproj.io/secret-type=repositoryFor complete documentation on authentication, see Repository Secrets.
Limitations
Section titled “Limitations”-
Shallow clones not supported: libgit2 (the underlying library) doesn’t support shallow clones. Full repository history is fetched.
-
Force checkout: When reusing worktrees, local changes are discarded. Worktrees are treated as read-only checkouts.
Troubleshooting
Section titled “Troubleshooting”Cache directory permissions
Section titled “Cache directory permissions”Problem: Permission denied when creating cache directory
Solution: Set NYL_CACHE_DIR to a writable location:
export NYL_CACHE_DIR=$HOME/.cache/nylLarge repository performance
Section titled “Large repository performance”Problem: Initial clone is slow for large repositories
Explanation: Nyl fetches the full repository (no shallow clone support)
Workaround: Use a specific tag/commit to avoid fetching all branches:
spec: chart: repository: git+https://github.com/large/repo.git version: v1.2.3 # Specific tag, not a branchStale cache
Section titled “Stale cache”Problem: Git repository not updating with latest changes
Solution: Clear the cache directory:
rm -rf $NYL_CACHE_DIR/git/Or for a specific repository:
# Find the cached repols $NYL_CACHE_DIR/git/bare/# Remove itrm -rf $NYL_CACHE_DIR/git/bare/{hash}-{repo-name}rm -rf $NYL_CACHE_DIR/git/worktrees/{hash}-*Authentication failures
Section titled “Authentication failures”Problem: Cannot access private repository
Solution: See Repository Secrets for authentication setup
Examples
Section titled “Examples”Multi-environment Chart from Git
Section titled “Multi-environment Chart from Git”apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: myapp namespace: productionspec: chart: repository: git+https://github.com/company/charts.git version: stable name: applications/myapp values: environment: production replicas: 5Development Branch
Section titled “Development Branch”apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: myapp namespace: developmentspec: chart: repository: git+https://github.com/company/charts.git version: develop name: applications/myapp values: environment: development replicas: 1Specific Version
Section titled “Specific Version”apiVersion: nyl.niklasrosenstein.github.com/v1kind: HelmChartmetadata: name: myapp namespace: stagingspec: chart: repository: git+https://github.com/company/charts.git version: v2.1.0 name: applications/myappApplicationGenerator with Filtering
Section titled “ApplicationGenerator with Filtering”apiVersion: argocd.nyl.niklasrosenstein.github.com/v1kind: ApplicationGeneratormetadata: name: monitoring-apps namespace: argocdspec: destination: server: https://kubernetes.default.svc namespace: argocd source: repoURL: https://github.com/company/infrastructure.git targetRevision: main path: monitoring include: - "*.yaml" - "*.yml" exclude: - ".*" # Hidden files - "_*" # Files starting with underscore - "test_*" # Test files project: monitoring labels: team: platform category: monitoringBest Practices
Section titled “Best Practices”-
Pin versions in production: Use tags or commit SHAs for production deployments:
version: v1.2.3 # Tag# orversion: abc123 # Commit SHA -
Use branches for development: Use branch refs for development environments:
version: develop # Branch name -
Set cache directory: Configure
NYL_CACHE_DIRin CI/CD environments:Terminal window export NYL_CACHE_DIR=/cache/nyl -
Monitor cache size: Periodically clean up old worktrees if disk space is limited:
Terminal window find $NYL_CACHE_DIR/git/worktrees -mtime +30 -delete -
Use subpaths: Keep charts in subdirectories for better organization:
spec:chart:repository: git+https://github.com/company/charts.gitname: charts/applications/myapp