mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 23:21:48 +00:00
feat: reconcile referencing helmchart if helmrelease is reconciled with source
Signed-off-by: Raffael Sahli <raffael.sahli@doodle.com>
This commit is contained in:
parent
c88a2f4137
commit
1e2845ed95
1 changed files with 42 additions and 4 deletions
|
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
||||
|
|
@ -36,10 +38,7 @@ The reconcile kustomization command triggers a reconciliation of a HelmRelease r
|
|||
# Trigger a reconciliation of the HelmRelease's source and apply changes
|
||||
flux reconcile hr podinfo --with-source`,
|
||||
ValidArgsFunction: resourceNamesCompletionFunc(helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind)),
|
||||
RunE: reconcileWithSourceCommand{
|
||||
apiType: helmReleaseType,
|
||||
object: helmReleaseAdapter{&helmv2.HelmRelease{}},
|
||||
}.run,
|
||||
RunE: reconcileSourceAndChart,
|
||||
}
|
||||
|
||||
type reconcileHelmReleaseFlags struct {
|
||||
|
|
@ -87,3 +86,42 @@ func (obj helmReleaseAdapter) getSource() (reconcileCommand, types.NamespacedNam
|
|||
Namespace: obj.Spec.Chart.Spec.SourceRef.Namespace,
|
||||
}
|
||||
}
|
||||
|
||||
func (obj helmChartAdapter) lastHandledReconcileRequest() string {
|
||||
return obj.Status.GetLastHandledReconcileRequest()
|
||||
}
|
||||
|
||||
func reconcileSourceAndChart(cmd *cobra.Command, args []string) error {
|
||||
hr := helmv2.HelmRelease{}
|
||||
reconcile := reconcileWithSourceCommand{
|
||||
apiType: helmReleaseType,
|
||||
object: helmReleaseAdapter{&hr},
|
||||
}
|
||||
|
||||
if err := reconcile.run(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if reconcile.object.reconcileSource() {
|
||||
nsName := strings.Split(hr.Status.HelmChart, "/")
|
||||
if len(nsName) != 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
nsCopy := *kubeconfigArgs.Namespace
|
||||
reconcileChart := reconcileCommand{
|
||||
apiType: helmChartType,
|
||||
object: helmChartAdapter{&sourcev1.HelmChart{}},
|
||||
}
|
||||
|
||||
if nsName[0] != "" {
|
||||
*kubeconfigArgs.Namespace = nsName[0]
|
||||
}
|
||||
|
||||
err := reconcileChart.run(nil, []string{nsName[1]})
|
||||
*kubeconfigArgs.Namespace = nsCopy
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue