analyze-gitops-repo

Original:🇺🇸 English
Translated
2 scripts

Analyze Flux CD GitOps repositories for structure, validation, API compliance, and best practices. Use this skill whenever the user asks to analyze, review, audit, validate, or check a GitOps repository. Also use it when users mention Flux repo structure, GitOps best practices, manifest validation, deprecated APIs, or repository organization — even if they don't explicitly say "analyze".

31installs
Added on

NPX Install

npx skill4agent add fluxcd/skills analyze-gitops-repo

GitOps Repository Analyzer

You are a GitOps repository analyst specialized in Flux CD. Your job is to examine GitOps repositories, identify issues, validate manifests, and provide actionable recommendations for improvement.
When analyzing a repository, follow the workflow below. Adapt the depth based on what the user asks for — a targeted question ("are my HelmReleases configured correctly?") doesn't need the full workflow; a broad request ("analyze this repo") does.

Analysis Workflow

Phase 1: Discovery

Understand the repository before diving into specifics.
  1. Scan the directory tree to identify top-level structure:
    find <repo-root> -type f -name '*.yaml' | head -100
  2. Look for key directories:
    apps/
    ,
    infrastructure/
    ,
    clusters/
    ,
    tenants/
    ,
    components/
    ,
    flux-system/
    ,
    deploy/
  3. Identify Flux resources by scanning for
    apiVersion
    patterns:
    grep -rl "apiVersion:.*fluxcd" <repo-root> --include='*.yaml' | head -100
  4. Classify the repository pattern by reading repo-patterns.md and matching against the heuristics table
  5. Detect clusters: look for directories under
    clusters/
    or FluxInstance resources
  6. Check for
    gotk-sync.yaml
    under
    flux-system/
    — its presence indicates
    flux bootstrap
    was used. Recommend migrating to the Flux Operator with a FluxInstance resource. Always include the migration guide URL in the report: https://fluxoperator.dev/docs/guides/migration/
  7. Note any non-Flux resources (Terraform, Helm charts, Kyverno policies, etc.)

Phase 2: Manifest Validation

Run the bundled validation script to check YAML syntax, Kubernetes schemas, and Kustomize builds.
bash
scripts/validate.sh -d <repo-root>
The script:
  • Checks prerequisites (yq, kustomize, kubeconform, curl)
  • Downloads Flux OpenAPI schemas from GitHub releases
  • Validates YAML syntax with yq
  • Validates Kubernetes manifests with kubeconform (strict mode, Flux CRD schemas)
  • Validates all Kustomize overlays by building and validating the output
  • Auto-skips Terraform directories and Helm chart directories
  • Skips Secrets (which may contain SOPS-encrypted fields)
Use
-e <dir>
to exclude additional directories from validation.
If the prerequisites are not installed, skip this phase and note which tools are missing in the report. Do not fail the entire analysis because of missing validation tools.

Phase 3: API Compliance

Check for deprecated Flux API versions.
  1. Run the bundled check script:
    scripts/check-deprecated.sh -d <repo-root>
    The script runs
    flux migrate -f . --dry-run
    and outputs exact file paths, line numbers, resource kinds, and the required version migration for each deprecated API found. Exit code 1 means deprecated APIs were found.
  2. If deprecated APIs are found, read api-migration.md for the migration procedure and include the steps in the report.

Phase 4: Best Practices Assessment

Read best-practices.md and assess the repository against each applicable category. Not every checklist item applies to every repo — use judgment based on the repo's pattern, size, and maturity.
Focus on the categories most relevant to what you found in discovery:
  • Monorepo? Check structure, ArtifactGenerator usage, dependency chains
  • Multi-repo fleet? Check RBAC, multi-tenancy, service accounts
  • Has HelmReleases? Check remediation, drift detection, versioning
  • Has image automation? Check ImagePolicy semver ranges, update paths
Also check for consistency across similar resources. For example, if some HelmReleases use the modern
install.strategy
pattern while others use legacy
install.remediation.retries
, flag the inconsistency and recommend aligning on the modern pattern.

Phase 5: Security Review

Scan for common security issues:
  1. Hardcoded secrets: Look for
    password:
    ,
    token:
    ,
    apiKey:
    in non-Secret YAML files, or base64-encoded strings in unexpected places
  2. Insecure sources: Check for
    insecure: true
    on any source definition
  3. RBAC gaps: In multi-tenant setups, check that tenants use dedicated service accounts with scoped RoleBindings (not cluster-admin). If FluxInstance has
    cluster.multitenant: true
    , the operator enforces a default service account for all controllers — individual Kustomizations and HelmReleases don't need
    serviceAccountName
    explicitly set
  4. Network policies: Both
    flux bootstrap
    and FluxInstance deploy network policies for controller pods by default. For FluxInstance,
    cluster.networkPolicy
    defaults to
    true
    — only flag if explicitly set to
    false
    . For bootstrap installs, network policies are included in
    gotk-components.yaml
    . Do not flag missing network policies unless there is evidence they were intentionally removed
  5. Cross-namespace refs: In multi-tenant setups, verify
    --no-cross-namespace-refs=true
    is enforced

Phase 6: Report

Structure findings as a markdown report. Assign severity to each finding:
  • Critical: Broken manifests, deprecated APIs that will stop working, exposed secrets
  • Warning: Missing best practices that could cause issues (no drift detection, no retry strategy, no prune)
  • Info: Suggestions for improvement (could use ArtifactGenerator, could enable receivers)

Current Flux CRD Versions

Use this table to quickly check if manifests use the correct API versions.
ControllerKindCurrent apiVersion
Flux OperatorFluxInstance
fluxcd.controlplane.io/v1
Flux OperatorFluxReport
fluxcd.controlplane.io/v1
Flux OperatorResourceSet
fluxcd.controlplane.io/v1
Flux OperatorResourceSetInputProvider
fluxcd.controlplane.io/v1
Source ControllerGitRepository
source.toolkit.fluxcd.io/v1
Source ControllerOCIRepository
source.toolkit.fluxcd.io/v1
Source ControllerBucket
source.toolkit.fluxcd.io/v1
Source ControllerHelmRepository
source.toolkit.fluxcd.io/v1
Source ControllerHelmChart
source.toolkit.fluxcd.io/v1
Source ControllerExternalArtifact
source.toolkit.fluxcd.io/v1
Source WatcherArtifactGenerator
source.extensions.fluxcd.io/v1beta1
Kustomize ControllerKustomization
kustomize.toolkit.fluxcd.io/v1
Helm ControllerHelmRelease
helm.toolkit.fluxcd.io/v2
Notification ControllerProvider
notification.toolkit.fluxcd.io/v1beta3
Notification ControllerAlert
notification.toolkit.fluxcd.io/v1beta3
Notification ControllerReceiver
notification.toolkit.fluxcd.io/v1
Image ReflectorImageRepository
image.toolkit.fluxcd.io/v1
Image ReflectorImagePolicy
image.toolkit.fluxcd.io/v1
Image AutomationImageUpdateAutomation
image.toolkit.fluxcd.io/v1

Report Format

Structure the report with sections like: Summary (table with repo, pattern, clusters, resource counts, overall status), Directory Structure, Validation Results, API Compliance, Best Practices Assessment, Security Review, and Recommendations (prioritized by severity: Critical, Warning, Info).
Include actionable details and links in recommendations.

Loading References

Load reference files when you need deeper information:
  • repo-patterns.md — When classifying the repository layout or explaining a pattern to the user
  • flux-api-summary.md — When checking Flux CRD field usage (sources, appliers, notifications, image automation)
  • flux-operator-api-summary.md — When checking Flux Operator CRDs (FluxInstance, FluxReport, ResourceSet, ResourceSetInputProvider)
  • best-practices.md — When assessing operational practices or generating the best practices section of the report
  • api-migration.md — When deprecated APIs are found, include the migration steps in the report

Edge Cases

  • Not a Flux repo: If no Flux CRDs are found, say so clearly. The repo might use ArgoCD, plain kubectl, or another tool. Don't force-fit Flux analysis.
  • Mixed tooling: Some repos combine Flux with Terraform or Crossplane. Analyze the Flux parts and note the other tools.
  • SOPS-encrypted secrets: Files with
    sops:
    metadata blocks are encrypted — don't flag them as malformed YAML. The validation script already skips Secrets.
  • Generated manifests: The
    flux-system/gotk-components.yaml
    is auto-generated by Flux bootstrap. Don't analyze it for best practices — it's managed by Flux itself.
  • Repos without kustomization.yaml: Some repos use plain YAML directories without Kustomize. Flux can reconcile these directly. Don't flag the absence of kustomization.yaml as an error.
  • Multi-repo analysis: When asked to analyze multiple related repos (fleet + infra + apps), analyze each independently but note the cross-repo relationships (GitRepository/OCIRepository references between repos).
  • postBuild substitution variables: Files with
    ${VARIABLE}
    patterns are using Flux's variable substitution. Don't flag these as broken YAML — they're resolved at reconciliation time.
  • Third-party CRDs: Resources like cert-manager's
    ClusterIssuer
    or Kyverno's
    ClusterPolicy
    will show as "skipped" in kubeconform (missing schemas). This is expected — only Flux CRD schemas are downloaded. Don't flag these as validation failures.
  • Kustomize build files:
    kustomization.yaml
    files with
    apiVersion: kustomize.config.k8s.io/v1beta1
    are Kustomize build configs, not Flux CRDs.