The Flux controller is failing to reconcile your Kubernetes resources because the source controller can’t find the specified Git repository.
Common Causes and Fixes for SourceNotReady Errors
This error typically means the Flux Source Controller is unable to fetch artifacts from your configured source (e.g., a Git repository). Here’s a breakdown of the most common reasons and how to fix them:
-
Incorrect Git Repository URL:
- Diagnosis: Check the
GitRepositoryorHelmRepositorycustom resource definition (CRD) that Flux is trying to use. Look for thespec.urlfield.
Compare this URL to the actual URL of your Git repository. Common mistakes include typos, missingkubectl -n flux-system get gitrepository <your-repo-name> -o yaml.gitsuffix for some Git hosting providers, or using SSH URLs when an HTTPS URL is expected (or vice versa). - Fix: Edit the
GitRepositoryCRD and correct thespec.url.# Example correction for a GitRepository apiVersion: source.toolkit.fluxcd.io/v1 kind: GitRepository metadata: name: my-git-repo namespace: flux-system spec: interval: 1m url: "https://github.com/my-org/my-repo.git" # Corrected URL ref: branch: main - Why it works: The
Source Controlleruses this URL to clone or fetch from your Git provider. An incorrect URL means it can’t establish a connection.
- Diagnosis: Check the
-
Authentication/Authorization Issues (SSH Keys or Tokens):
- Diagnosis: If your repository is private, the
Source Controllerneeds credentials.- For SSH: Ensure the
Secretreferenced inspec.secretRef.namecontains a valididentitykey with the private SSH key. Also, verify theknown_hostsentry in the secret is correct for your Git host.
Look forkubectl -n flux-system get secret <your-secret-name> -o yamlidentityandknown_hostskeys. - For HTTPS: If using a token, ensure the
Secretcontains ausernameandpassword(which is your token).
Look forkubectl -n flux-system get secret <your-secret-name> -o yamlusernameandpasswordkeys. - Check the
Source Controllerlogs for specific authentication errors.kubectl -n flux-system logs -l app=source-controller -c manager
- For SSH: Ensure the
- Fix:
- SSH:
- Generate a new SSH key pair if needed:
ssh-keygen -t ed25519 -C "fluxcd@example.com" - Add the public key to your Git provider (e.g., GitHub Deploy Keys, GitLab Deploy Tokens).
- Create or update the Kubernetes
Secretwith the private key andknown_hostsentry.kubectl -n flux-system create secret generic git-creds \ --from-file=identity=~/.ssh/id_ed25519 \ --from-literal=known_hosts='github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...' - Update your
GitRepositoryCRD to reference this secret:spec: url: "git@github.com:my-org/my-repo.git" secretRef: name: git-creds
- Generate a new SSH key pair if needed:
- HTTPS:
- Generate a Personal Access Token (PAT) on your Git provider with appropriate read permissions.
- Create or update the Kubernetes
Secretwith your username and the PAT.kubectl -n flux-system create secret generic git-creds \ --from-literal=username='my-git-username' \ --from-literal=password='my-personal-access-token' - Update your
GitRepositoryCRD to reference this secret:spec: url: "https://github.com/my-org/my-repo.git" secretRef: name: git-creds
- SSH:
- Why it works: The
Source Controllerneeds valid credentials to authenticate with your Git provider for private repositories. Without them, it’s like trying to log into a website without a password.
- Diagnosis: If your repository is private, the
-
Network Connectivity Issues:
- Diagnosis: The
Source Controllerpod needs to be able to reach your Git repository URL over the network.- Exec into the
source-controllerpod:kubectl -n flux-system exec -it <source-controller-pod-name> -- /bin/sh - Inside the pod, try to
pingorcurlthe Git repository host.# Example using curl (install curl if not present: apt update && apt install curl) curl -v https://github.com - Check your Kubernetes cluster’s network policies, firewalls, or egress rules that might be blocking outbound connections from the
flux-systemnamespace or thesource-controllerpod.
- Exec into the
- Fix: Adjust network policies, firewall rules, or proxy configurations to allow the
source-controllerpod to connect to your Git host. If using a proxy, configure it in theSource Controller’s deployment. - Why it works: The
Source Controllercannot fetch code if it can’t establish a network connection to the remote Git server.
- Diagnosis: The
-
Incorrect Branch, Tag, or Commit SHA:
- Diagnosis: Verify that the
refspecified in yourGitRepository(e.g.,branch: main,tag: v1.0.0,commit: abcdef123) actually exists in your Git repository.# From your local machine, check if the ref exists git ls-remote origin main # For branch git ls-remote origin v1.0.0 # For tag - Fix: Update the
spec.refin yourGitRepositoryCRD to point to a valid and existing branch, tag, or commit SHA.spec: interval: 1m url: "https://github.com/my-org/my-repo.git" ref: branch: develop # Changed to a valid branch - Why it works: The
Source Controllerneeds a valid reference point within the Git history to fetch from. An invalid ref means there’s nothing for it to retrieve.
- Diagnosis: Verify that the
-
Rate Limiting by Git Provider:
- Diagnosis: If you’re hitting your Git provider’s API rate limits (especially common with HTTPS/token authentication), the
Source Controllermay be temporarily blocked from fetching. Check theSource Controllerlogs for messages indicating rate limiting or excessive requests.kubectl -n flux-system logs -l app=source-controller -c manager - Fix:
- Increase the
intervalin yourGitRepositoryCRD to poll less frequently (e.g., from1mto5mor10m).spec: interval: 5m # Increased interval url: "https://github.com/my-org/my-repo.git" # ... - If using SSH, it’s generally less prone to rate limiting than token-based HTTPS.
- Consider using a dedicated deploy key (SSH) for Flux instead of a personal access token if you’re experiencing frequent rate limiting.
- Increase the
- Why it works: Reducing the frequency of requests to the Git provider helps you stay within their API usage limits, preventing temporary blocks.
- Diagnosis: If you’re hitting your Git provider’s API rate limits (especially common with HTTPS/token authentication), the
-
Git Repository Not Found (404) or Private Repository Access Denied:
- Diagnosis: This is a more direct error from the Git provider. The
Source Controllerlogs will usually show an HTTP 404 or 403 error.
Look for messages likekubectl -n flux-system logs -l app=source-controller -c managerfatal: repository '...' not foundorPermission denied (publickey). - Fix: This is often a combination of points 1 and 2.
- Ensure the URL is correct and the repository exists.
- Ensure the credentials (SSH key or token) have the correct permissions and are associated with an account that has access to the repository.
- For private repositories, ensure the correct SSH key is added to the Git provider’s deploy keys or the user account, or that the PAT has the necessary scopes.
- Why it works: The Git provider is explicitly denying access, either because the repository doesn’t exist at that URL or the provided credentials lack the necessary permissions.
- Diagnosis: This is a more direct error from the Git provider. The
After resolving these issues, the Source Controller should be able to fetch artifacts successfully. The next error you might encounter is if the Kustomize Controller or Helm Controller cannot apply the fetched manifests due to validation errors or other Kubernetes-specific problems.