- .github
- action
-
cmd
-
flux
-
testdata
- build-kustomization
- check
- cluster_info
- create_secret
- create_source_git
- create_source_helm
- diff-artifact
-
diff-kustomization
- deployment.yaml
- diff-with-deployment.golden
- diff-with-dockerconfigjson-sops-secret.golden
- diff-with-drifted-key-sops-secret.golden
- diff-with-drifted-secret.golden
- diff-with-drifted-service.golden
- diff-with-drifted-stringdata-sops-secret.golden
- diff-with-drifted-value-sops-secret.golden
- dockerconfigjson-sops-secret.yaml
- flux-kustomization-multiobj.yaml
- key-sops-secret.yaml
- kustomization.yaml
- nothing-is-deployed.golden
- secret.yaml
- service.yaml
- stringdata-sops-secret.yaml
- value-sops-secret.yaml
- envsubst
- export
- get
- helmrelease
- image
-
kustomization
- create_kustomization_from_git.golden
- create_source_git.golden
- delete_kustomization_from_git.golden
- get_kustomization_from_git.golden
- reconcile_kustomization_from_git.golden
- resume_kustomization_from_git.golden
- resume_kustomization_from_git_multiple_args.golden
- resume_kustomization_from_git_multiple_args_wait.golden
- suspend_kustomization_from_git.golden
- suspend_kustomization_from_git_multiple_args.golden
- logs
- oci
- trace
- tree
- alert.go
- alert_provider.go
- bootstrap.go
- bootstrap_bitbucket_server.go
- bootstrap_git.go
- bootstrap_gitea.go
- bootstrap_github.go
- bootstrap_gitlab.go
- build.go
- build_artifact.go
- build_artifact_test.go
- build_kustomization.go
- build_kustomization_test.go
- check.go
- check_test.go
- cluster_info.go
- cluster_info_test.go
- completion.go
- completion_bash.go
- completion_fish.go
- completion_powershell.go
- completion_zsh.go
- create.go
- create_alert.go
- create_alertprovider.go
- create_helmrelease.go
- create_image.go
- create_image_policy.go
- create_image_repository.go
- create_image_update.go
- create_kustomization.go
- create_receiver.go
- create_secret.go
- create_secret_git.go
- create_secret_git_test.go
- create_secret_helm.go
- create_secret_helm_test.go
- create_secret_oci.go
- create_secret_oci_test.go
- create_secret_tls.go
- create_secret_tls_test.go
- create_source.go
- create_source_bucket.go
- create_source_git.go
- create_source_git_test.go
- create_source_helm.go
- create_source_helm_test.go
- create_source_oci.go
- create_source_oci_test.go
- create_tenant.go
- create_test.go
- delete.go
- delete_alert.go
- delete_alertprovider.go
- delete_helmrelease.go
- delete_image.go
- delete_image_policy.go
- delete_image_repository.go
- delete_image_update.go
- delete_kustomization.go
- delete_receiver.go
- delete_source.go
- delete_source_bucket.go
- delete_source_git.go
- delete_source_helm.go
- delete_source_oci.go
- diff.go
- diff_artifact.go
- diff_artifact_test.go
- diff_kustomization.go
- diff_kustomization_test.go
- docgen.go
- envsubst.go
- envsubst_test.go
- events.go
- events_test.go
- export.go
- export_alert.go
- export_alertprovider.go
- export_helmrelease.go
- export_image.go
- export_image_policy.go
- export_image_repository.go
- export_image_update.go
- export_kustomization.go
- export_receiver.go
- export_secret.go
- export_source.go
- export_source_bucket.go
- export_source_git.go
- export_source_helm.go
- export_source_oci.go
- export_test.go
- get.go
- get_alert.go
- get_alertprovider.go
- get_all.go
- get_helmrelease.go
- get_image.go
- get_image_all.go
- get_image_policy.go
- get_image_repository.go
- get_image_update.go
- get_kustomization.go
- get_receiver.go
- get_source.go
- get_source_all.go
- get_source_bucket.go
- get_source_chart.go
- get_source_git.go
- get_source_helm.go
- get_source_oci.go
- get_test.go
- helmrelease.go
- helmrelease_test.go
- image.go
- image_test.go
- install.go
- install_test.go
- kustomization.go
- kustomization_test.go
- list.go
- list_artifact.go
- log.go
- logs.go
- logs_e2e_test.go
- logs_unit_test.go
- main.go
- main_e2e_test.go
- main_test.go
- main_unit_test.go
- manifests.embed.go
- object.go
- pull.go
- pull_artifact.go
- push.go
- push_artifact.go
- readiness.go
- readiness_test.go
- receiver.go
- reconcile.go
- reconcile_helmrelease.go
- reconcile_image.go
- reconcile_image_repository.go
- reconcile_image_updateauto.go
- reconcile_kustomization.go
- reconcile_receiver.go
- reconcile_source.go
- reconcile_source_bucket.go
- reconcile_source_chart.go
- reconcile_source_git.go
- reconcile_source_helm.go
- reconcile_source_oci.go
- reconcile_with_source.go
- resume.go
- resume_alert.go
- resume_alertprovider.go
- resume_helmrelease.go
- resume_image.go
- resume_image_repository.go
- resume_image_updateauto.go
- resume_kustomization.go
- resume_receiver.go
- resume_source.go
- resume_source_bucket.go
- resume_source_chart.go
- resume_source_git.go
- resume_source_helm.go
- resume_source_oci.go
- source.go
- source_oci_test.go
- stats.go
- status.go
- suspend.go
- suspend_alert.go
- suspend_alertprovider.go
- suspend_helmrelease.go
- suspend_image.go
- suspend_image_repository.go
- suspend_image_updateauto.go
- suspend_kustomization.go
- suspend_receiver.go
- suspend_source.go
- suspend_source_bucket.go
- suspend_source_chart.go
- suspend_source_git.go
- suspend_source_helm.go
- suspend_source_oci.go
- tag.go
- tag_artifact.go
- trace.go
- trace_test.go
- tree.go
- tree_kustomization.go
- tree_kustomization_test.go
- uninstall.go
- version.go
- version_test.go
- version_utils.go
- version_utils_test.go
-
testdata
-
flux
- docs
- install
-
internal
- build
-
flags
- crds.go
- crds_test.go
- decryption_provider.go
- decryption_provider_test.go
- ecdsa_curve.go
- ecdsa_curve_test.go
- helm_chart_source.go
- helm_chart_source_test.go
- kustomization_source.go
- kustomization_source_test.go
- log_level.go
- log_level_test.go
- public_key_algorithm.go
- public_key_algorithm_test.go
- rsa_key_bits.go
- rsa_key_bits_test.go
- safe_relative_path.go
- safe_relative_path_test.go
- source_bucket_provider.go
- source_bucket_provider_test.go
- source_oci_provider.go
- source_oci_verify_provider.go
- source_oci_verify_provider_test.go
- tree
- utils
-
manifests
- bases
- crds
- install
- integrations
- monitoring
- openshift
- policies
- rbac
- scripts
- pkg
- rfcs
- tests
- .gitignore
- .goreleaser.yml
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- DCO
- Dockerfile
- LICENSE
- MAINTAINERS
- Makefile
- README.md
- go.mod
- go.sum
- netlify.toml
Explanation
This code defines a trace
command for the Flux2 CLI tool, which allows users to trace the lifecycle of Kubernetes objects managed by Flux.
Functionality:
- Takes object names/references as arguments: Accepts either
<resource>/<name>
or<resource> <name>
format to specify the object. - Supports static and dynamic object retrieval:
- Static: If
--kind
and--api-version
flags are provided, it retrieves the object directly using its type and name. - Dynamic: If flags are omitted, it relies on the
kubectl
resource builder to infer the object type and fetch it. - Identifies Flux-managed objects: Determines if the object is managed by either Kustomize or Helm controllers by checking for specific labels or owner references.
- Generates detailed trace output: For each object, it collects and displays information such as:
- Object name and namespace
- Source repository (Git, OCI, Helm) name and details like URL, branch, tag, etc.
- Source repository revision (commit hash, tag, digest)
- Source repository reconciliation status and messages
- Kustomization or HelmRelease name and related information
- Kustomization or HelmRelease reconciliation status and messages
Code Breakdown:
- traceCmd: The main command object, defining usage, description, and example usage.
- traceFlags: A struct to store the
--kind
and--api-version
flags. - traceCmdRun: The function that handles command execution. It retrieves the object(s), determines the management type (Kustomize/Helm), and invokes appropriate trace functions.
- getObjectStatic: Retrieves the object based on the provided
kind
andapi-version
flags. - getObjectDynamic: Utilizes the
kubectl
resource builder to fetch the object based on the provided name/reference. - traceObjects: Iterates through a list of objects and calls
traceObject
for each. - traceObject: Identifies the management type (Kustomize/Helm) and calls the corresponding trace functions (
traceKustomization
ortraceHelm
). - traceKustomization: Fetches the Kustomization object, source repository (Git or OCI), and generates the trace output with relevant details.
- traceHelm: Fetches the HelmRelease object, HelmChart, and source repository (Git or Helm), and generates the trace output.
- isManagedByFlux: Checks if an object is managed by Flux by checking for specific labels.
- isOwnerManagedByFlux: Recursively traverses owner references to determine if an object is ultimately managed by Flux.
Key Concepts:
- Controller-Runtime Client: Used for interacting with Kubernetes API (e.g.,
client.Client
). - Unstructured Objects: Representation of Kubernetes objects without type information (used for flexibility).
- Kustomize and Helm Controllers: Flux controllers responsible for managing applications based on Kustomize and Helm configurations respectively.
- Source Controllers (GitRepository, OCIRepository, HelmChart, HelmRepository): Controllers responsible for fetching and managing source code, charts, etc.
This code provides a powerful tool for understanding the flow of objects through the GitOps pipeline managed by Flux. The use of templates for output generation allows for flexible and readable trace information.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph