1
0
mirror of synced 2026-02-13 13:06:56 +00:00

fix: support reconcile recursive source tree hr => chart => repo

Signed-off-by: Raffael Sahli <raffael.sahli@doodle.com>
This commit is contained in:
Raffael Sahli
2023-04-14 10:02:03 +00:00
committed by Hidde Beydals
parent e678738ded
commit b8c24f906d
5 changed files with 75 additions and 30 deletions

View File

@@ -18,27 +18,70 @@ package main
import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
)
var reconcileSourceHelmChartCmd = &cobra.Command{
Use: "chart [name]",
Short: "Reconcile a HelmChart source",
Long: `The reconcile source command triggers a reconciliation of a HelmCHart resource and waits for it to finish.`,
Long: `The reconcile source command triggers a reconciliation of a HelmChart resource and waits for it to finish.`,
Example: ` # Trigger a reconciliation for an existing source
flux reconcile source chart podinfo`,
ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.HelmChartKind)),
RunE: reconcileCommand{
flux reconcile source chart podinfo
# Trigger a reconciliation of the HelmCharts's source and apply changes
flux reconcile helmchart podinfo --with-source`,
ValidArgsFunction: resourceNamesCompletionFunc(helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind)),
RunE: reconcileWithSourceCommand{
apiType: helmChartType,
object: helmChartAdapter{&sourcev1.HelmChart{}},
object: helmChartAdapter{&sourcev1b2.HelmChart{}},
}.run,
}
func init() {
reconcileSourceHelmChartCmd.Flags().BoolVar(&rhcArgs.syncHrWithSource, "with-source", false, "reconcile HelmChart source")
reconcileSourceCmd.AddCommand(reconcileSourceHelmChartCmd)
}
func (obj helmChartAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}
type reconcileHelmChartFlags struct {
syncHrWithSource bool
}
var rhcArgs reconcileHelmChartFlags
func (obj helmChartAdapter) reconcileSource() bool {
return rhcArgs.syncHrWithSource
}
func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName) {
var cmd reconcileCommand
switch obj.Spec.SourceRef.Kind {
case sourcev1b2.HelmRepositoryKind:
cmd = reconcileCommand{
apiType: helmRepositoryType,
object: helmRepositoryAdapter{&sourcev1b2.HelmRepository{}},
}
case sourcev1.GitRepositoryKind:
cmd = reconcileCommand{
apiType: gitRepositoryType,
object: gitRepositoryAdapter{&sourcev1.GitRepository{}},
}
case sourcev1b2.BucketKind:
cmd = reconcileCommand{
apiType: bucketType,
object: bucketAdapter{&sourcev1b2.Bucket{}},
}
}
return cmd, types.NamespacedName{
Name: obj.Spec.SourceRef.Name,
Namespace: obj.Namespace,
}
}