mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-26 20:24:12 +08:00
Add --show-history flag to debug kustomization
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
@ -77,7 +77,6 @@ func debugHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if debugHelmReleaseArgs.showHistory {
|
if debugHelmReleaseArgs.showHistory {
|
||||||
flagsSet++
|
flagsSet++
|
||||||
}
|
}
|
||||||
|
|
||||||
if flagsSet != 1 {
|
if flagsSet != 1 {
|
||||||
return fmt.Errorf("exactly one of --show-status, --show-values, or --show-history must be set")
|
return fmt.Errorf("exactly one of --show-status, --show-values, or --show-history must be set")
|
||||||
}
|
}
|
||||||
@ -134,9 +133,10 @@ func debugHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.Println("# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#helmrelease-status")
|
rootCmd.Println("# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#history")
|
||||||
rootCmd.Print(string(history))
|
rootCmd.Print(string(history))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
|
||||||
|
"github.com/fluxcd/pkg/apis/meta"
|
||||||
"github.com/fluxcd/pkg/kustomize"
|
"github.com/fluxcd/pkg/kustomize"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
@ -44,7 +45,10 @@ WARNING: This command will print sensitive information if Kubernetes Secrets are
|
|||||||
flux debug ks podinfo --show-status
|
flux debug ks podinfo --show-status
|
||||||
|
|
||||||
# Export the final variables used for post-build substitutions composed from referred ConfigMaps and Secrets
|
# Export the final variables used for post-build substitutions composed from referred ConfigMaps and Secrets
|
||||||
flux debug ks podinfo --show-vars > vars.env`,
|
flux debug ks podinfo --show-vars > vars.env
|
||||||
|
|
||||||
|
# Print the reconciliation history of a Flux Kustomization
|
||||||
|
flux debug ks podinfo --show-history`,
|
||||||
RunE: debugKustomizationCmdRun,
|
RunE: debugKustomizationCmdRun,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
ValidArgsFunction: resourceNamesCompletionFunc(kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind)),
|
||||||
@ -53,6 +57,7 @@ WARNING: This command will print sensitive information if Kubernetes Secrets are
|
|||||||
type debugKustomizationFlags struct {
|
type debugKustomizationFlags struct {
|
||||||
showStatus bool
|
showStatus bool
|
||||||
showVars bool
|
showVars bool
|
||||||
|
showHistory bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugKustomizationArgs debugKustomizationFlags
|
var debugKustomizationArgs debugKustomizationFlags
|
||||||
@ -60,15 +65,25 @@ var debugKustomizationArgs debugKustomizationFlags
|
|||||||
func init() {
|
func init() {
|
||||||
debugKustomizationCmd.Flags().BoolVar(&debugKustomizationArgs.showStatus, "show-status", false, "print the status of the Flux Kustomization")
|
debugKustomizationCmd.Flags().BoolVar(&debugKustomizationArgs.showStatus, "show-status", false, "print the status of the Flux Kustomization")
|
||||||
debugKustomizationCmd.Flags().BoolVar(&debugKustomizationArgs.showVars, "show-vars", false, "print the final vars of the Flux Kustomization in dot env format")
|
debugKustomizationCmd.Flags().BoolVar(&debugKustomizationArgs.showVars, "show-vars", false, "print the final vars of the Flux Kustomization in dot env format")
|
||||||
|
debugKustomizationCmd.Flags().BoolVar(&debugKustomizationArgs.showHistory, "show-history", false, "print the reconciliation history of the Flux Kustomization")
|
||||||
debugCmd.AddCommand(debugKustomizationCmd)
|
debugCmd.AddCommand(debugKustomizationCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func debugKustomizationCmdRun(cmd *cobra.Command, args []string) error {
|
func debugKustomizationCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
if (!debugKustomizationArgs.showStatus && !debugKustomizationArgs.showVars) ||
|
flagsSet := 0
|
||||||
(debugKustomizationArgs.showStatus && debugKustomizationArgs.showVars) {
|
if debugKustomizationArgs.showStatus {
|
||||||
return fmt.Errorf("either --show-status or --show-vars must be set")
|
flagsSet++
|
||||||
|
}
|
||||||
|
if debugKustomizationArgs.showVars {
|
||||||
|
flagsSet++
|
||||||
|
}
|
||||||
|
if debugKustomizationArgs.showHistory {
|
||||||
|
flagsSet++
|
||||||
|
}
|
||||||
|
if flagsSet != 1 {
|
||||||
|
return fmt.Errorf("exactly one of --show-status, --show-vars, or --show-history must be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
@ -130,5 +145,20 @@ func debugKustomizationCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debugKustomizationArgs.showHistory {
|
||||||
|
if len(ks.Status.History) == 0 {
|
||||||
|
ks.Status.History = meta.History{}
|
||||||
|
}
|
||||||
|
|
||||||
|
history, err := yaml.Marshal(ks.Status.History)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd.Println("# History documentation: https://fluxcd.io/flux/components/kustomize/kustomizations/#history")
|
||||||
|
rootCmd.Print(string(history))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,17 @@ func TestDebugKustomization(t *testing.T) {
|
|||||||
"debug ks test-from --show-vars --show-status=false",
|
"debug ks test-from --show-vars --show-status=false",
|
||||||
"testdata/debug_kustomization/vars-from.golden.env",
|
"testdata/debug_kustomization/vars-from.golden.env",
|
||||||
tmpl,
|
tmpl,
|
||||||
|
}, {
|
||||||
|
"debug history",
|
||||||
|
"debug ks test-with-history --show-history --show-status=false",
|
||||||
|
"testdata/debug_kustomization/history.golden.yaml",
|
||||||
|
tmpl,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"debug history empty",
|
||||||
|
"debug ks test --show-history --show-status=false",
|
||||||
|
"testdata/debug_kustomization/history-empty.golden.yaml",
|
||||||
|
tmpl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#helmrelease-status
|
# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#history
|
||||||
[]
|
[]
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#helmrelease-status
|
# History documentation: https://fluxcd.io/flux/components/helm/helmreleases/#history
|
||||||
- appVersion: 6.0.0
|
- appVersion: 6.0.0
|
||||||
chartName: podinfo
|
chartName: podinfo
|
||||||
chartVersion: 6.0.0
|
chartVersion: 6.0.0
|
||||||
|
|||||||
2
cmd/flux/testdata/debug_kustomization/history-empty.golden.yaml
vendored
Normal file
2
cmd/flux/testdata/debug_kustomization/history-empty.golden.yaml
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# History documentation: https://fluxcd.io/flux/components/kustomize/kustomizations/#history
|
||||||
|
[]
|
||||||
17
cmd/flux/testdata/debug_kustomization/history.golden.yaml
vendored
Normal file
17
cmd/flux/testdata/debug_kustomization/history.golden.yaml
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# History documentation: https://fluxcd.io/flux/components/kustomize/kustomizations/#history
|
||||||
|
- digest: sha256:def456
|
||||||
|
firstReconciled: "2024-01-01T09:00:00Z"
|
||||||
|
lastReconciled: "2024-01-01T10:00:00Z"
|
||||||
|
lastReconciledDuration: 300ms
|
||||||
|
lastReconciledStatus: success
|
||||||
|
metadata:
|
||||||
|
originRevision: abc123
|
||||||
|
totalReconciliations: 1
|
||||||
|
- digest: sha256:ghi012
|
||||||
|
firstReconciled: "2024-02-01T09:00:00Z"
|
||||||
|
lastReconciled: "2024-02-01T10:00:00Z"
|
||||||
|
lastReconciledDuration: 500ms
|
||||||
|
lastReconciledStatus: failure
|
||||||
|
metadata:
|
||||||
|
originRevision: xyz789
|
||||||
|
totalReconciliations: 10
|
||||||
@ -44,6 +44,47 @@ spec:
|
|||||||
- kind: Secret
|
- kind: Secret
|
||||||
name: test
|
name: test
|
||||||
---
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: test-with-history
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: test
|
||||||
|
interval: 1m
|
||||||
|
path: "./"
|
||||||
|
prune: true
|
||||||
|
postBuild:
|
||||||
|
substitute:
|
||||||
|
TEST_OVERRIDE: "in-line"
|
||||||
|
TEST_INLINE: "in-line"
|
||||||
|
substituteFrom:
|
||||||
|
- kind: ConfigMap
|
||||||
|
name: test
|
||||||
|
- kind: Secret
|
||||||
|
name: test
|
||||||
|
status:
|
||||||
|
observedGeneration: 1
|
||||||
|
history:
|
||||||
|
- digest: sha256:def456
|
||||||
|
firstReconciled: "2024-01-01T09:00:00Z"
|
||||||
|
lastReconciled: "2024-01-01T10:00:00Z"
|
||||||
|
lastReconciledDuration: 300ms
|
||||||
|
lastReconciledStatus: success
|
||||||
|
metadata:
|
||||||
|
originRevision: abc123
|
||||||
|
totalReconciliations: 1
|
||||||
|
- digest: sha256:ghi012
|
||||||
|
firstReconciled: "2024-02-01T09:00:00Z"
|
||||||
|
lastReconciled: "2024-02-01T10:00:00Z"
|
||||||
|
lastReconciledDuration: 500ms
|
||||||
|
lastReconciledStatus: failure
|
||||||
|
metadata:
|
||||||
|
originRevision: xyz789
|
||||||
|
totalReconciliations: 10
|
||||||
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
Reference in New Issue
Block a user