mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
Fix panic on reconcile with source of ExternalArtifact kind
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
parent
e95da82f5a
commit
69feb7214a
4 changed files with 47 additions and 33 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
|
|
||||||
helmv2 "github.com/fluxcd/helm-controller/api/v2"
|
helmv2 "github.com/fluxcd/helm-controller/api/v2"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
||||||
|
|
@ -67,7 +66,7 @@ func (obj helmReleaseAdapter) reconcileSource() bool {
|
||||||
return rhrArgs.syncHrWithSource
|
return rhrArgs.syncHrWithSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName) {
|
func (obj helmReleaseAdapter) getSource() (reconcileSource, sourceReference) {
|
||||||
var (
|
var (
|
||||||
name string
|
name string
|
||||||
ns string
|
ns string
|
||||||
|
|
@ -78,21 +77,26 @@ func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName
|
||||||
if ns == "" {
|
if ns == "" {
|
||||||
ns = obj.Namespace
|
ns = obj.Namespace
|
||||||
}
|
}
|
||||||
namespacedName := types.NamespacedName{
|
srcRef := sourceReference{
|
||||||
Name: name,
|
kind: obj.Spec.ChartRef.Kind,
|
||||||
Namespace: ns,
|
name: name,
|
||||||
|
namespace: ns,
|
||||||
}
|
}
|
||||||
if obj.Spec.ChartRef.Kind == sourcev1.HelmChartKind {
|
switch obj.Spec.ChartRef.Kind {
|
||||||
|
case sourcev1.HelmChartKind:
|
||||||
return reconcileWithSourceCommand{
|
return reconcileWithSourceCommand{
|
||||||
apiType: helmChartType,
|
apiType: helmChartType,
|
||||||
object: helmChartAdapter{&sourcev1.HelmChart{}},
|
object: helmChartAdapter{&sourcev1.HelmChart{}},
|
||||||
force: true,
|
force: true,
|
||||||
}, namespacedName
|
}, srcRef
|
||||||
|
case sourcev1.OCIRepositoryKind:
|
||||||
|
return reconcileCommand{
|
||||||
|
apiType: ociRepositoryType,
|
||||||
|
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
||||||
|
}, srcRef
|
||||||
|
default:
|
||||||
|
return nil, srcRef
|
||||||
}
|
}
|
||||||
return reconcileCommand{
|
|
||||||
apiType: ociRepositoryType,
|
|
||||||
object: ociRepositoryAdapter{&sourcev1.OCIRepository{}},
|
|
||||||
}, namespacedName
|
|
||||||
default:
|
default:
|
||||||
// default case assumes the HelmRelease is using a HelmChartTemplate
|
// default case assumes the HelmRelease is using a HelmChartTemplate
|
||||||
ns = obj.Spec.Chart.Spec.SourceRef.Namespace
|
ns = obj.Spec.Chart.Spec.SourceRef.Namespace
|
||||||
|
|
@ -104,9 +108,10 @@ func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName
|
||||||
apiType: helmChartType,
|
apiType: helmChartType,
|
||||||
object: helmChartAdapter{&sourcev1.HelmChart{}},
|
object: helmChartAdapter{&sourcev1.HelmChart{}},
|
||||||
force: true,
|
force: true,
|
||||||
}, types.NamespacedName{
|
}, sourceReference{
|
||||||
Name: name,
|
kind: sourcev1.HelmChartKind,
|
||||||
Namespace: ns,
|
name: name,
|
||||||
|
namespace: ns,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
||||||
|
|
@ -62,8 +61,8 @@ func (obj kustomizationAdapter) reconcileSource() bool {
|
||||||
return rksArgs.syncKsWithSource
|
return rksArgs.syncKsWithSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj kustomizationAdapter) getSource() (reconcileSource, types.NamespacedName) {
|
func (obj kustomizationAdapter) getSource() (reconcileSource, sourceReference) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileSource
|
||||||
switch obj.Spec.SourceRef.Kind {
|
switch obj.Spec.SourceRef.Kind {
|
||||||
case sourcev1.OCIRepositoryKind:
|
case sourcev1.OCIRepositoryKind:
|
||||||
cmd = reconcileCommand{
|
cmd = reconcileCommand{
|
||||||
|
|
@ -82,9 +81,10 @@ func (obj kustomizationAdapter) getSource() (reconcileSource, types.NamespacedNa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd, types.NamespacedName{
|
return cmd, sourceReference{
|
||||||
Name: obj.Spec.SourceRef.Name,
|
kind: obj.Spec.SourceRef.Kind,
|
||||||
Namespace: obj.Spec.SourceRef.Namespace,
|
name: obj.Spec.SourceRef.Name,
|
||||||
|
namespace: obj.Spec.SourceRef.Namespace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
||||||
)
|
)
|
||||||
|
|
@ -58,8 +57,8 @@ func (obj helmChartAdapter) reconcileSource() bool {
|
||||||
return rhcArgs.syncHrWithSource
|
return rhcArgs.syncHrWithSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName) {
|
func (obj helmChartAdapter) getSource() (reconcileSource, sourceReference) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileSource
|
||||||
switch obj.Spec.SourceRef.Kind {
|
switch obj.Spec.SourceRef.Kind {
|
||||||
case sourcev1.HelmRepositoryKind:
|
case sourcev1.HelmRepositoryKind:
|
||||||
cmd = reconcileCommand{
|
cmd = reconcileCommand{
|
||||||
|
|
@ -78,9 +77,10 @@ func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd, types.NamespacedName{
|
return cmd, sourceReference{
|
||||||
Name: obj.Spec.SourceRef.Name,
|
kind: obj.Spec.SourceRef.Kind,
|
||||||
Namespace: obj.Namespace,
|
name: obj.Spec.SourceRef.Name,
|
||||||
|
namespace: obj.Namespace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,17 @@ import (
|
||||||
"github.com/fluxcd/flux2/v2/internal/utils"
|
"github.com/fluxcd/flux2/v2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type sourceReference struct {
|
||||||
|
kind string
|
||||||
|
name string
|
||||||
|
namespace string
|
||||||
|
}
|
||||||
|
|
||||||
type reconcileWithSource interface {
|
type reconcileWithSource interface {
|
||||||
adapter
|
adapter
|
||||||
reconcilable
|
reconcilable
|
||||||
reconcileSource() bool
|
reconcileSource() bool
|
||||||
getSource() (reconcileSource, types.NamespacedName)
|
getSource() (reconcileSource, sourceReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
type reconcileSource interface {
|
type reconcileSource interface {
|
||||||
|
|
@ -61,14 +67,17 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
if reconcile.object.reconcileSource() || reconcile.force {
|
if reconcile.object.reconcileSource() || reconcile.force {
|
||||||
reconcileCmd, nsName := reconcile.object.getSource()
|
reconcileCmd, srcRef := reconcile.object.getSource()
|
||||||
nsCopy := *kubeconfigArgs.Namespace
|
if reconcileCmd == nil {
|
||||||
if nsName.Namespace != "" {
|
return fmt.Errorf("cannot reconcile source of kind %s", srcRef.kind)
|
||||||
*kubeconfigArgs.Namespace = nsName.Namespace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := reconcileCmd.run(nil, []string{nsName.Name})
|
nsCopy := *kubeconfigArgs.Namespace
|
||||||
if err != nil {
|
if srcRef.namespace != "" {
|
||||||
|
*kubeconfigArgs.Namespace = srcRef.namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := reconcileCmd.run(nil, []string{srcRef.name}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*kubeconfigArgs.Namespace = nsCopy
|
*kubeconfigArgs.Namespace = nsCopy
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue