mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-29 23:37:47 +08:00
Fix reconcile with source in a different namespace
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
@ -18,6 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||||
@ -60,7 +61,7 @@ func (obj helmReleaseAdapter) reconcileSource() bool {
|
|||||||
return rhrArgs.syncHrWithSource
|
return rhrArgs.syncHrWithSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj helmReleaseAdapter) getSource() (reconcileCommand, string) {
|
func (obj helmReleaseAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileCommand
|
||||||
switch obj.Spec.Chart.Spec.SourceRef.Kind {
|
switch obj.Spec.Chart.Spec.SourceRef.Kind {
|
||||||
case sourcev1.HelmRepositoryKind:
|
case sourcev1.HelmRepositoryKind:
|
||||||
@ -80,5 +81,8 @@ func (obj helmReleaseAdapter) getSource() (reconcileCommand, string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd, obj.Spec.Chart.Spec.SourceRef.Name
|
return cmd, types.NamespacedName{
|
||||||
|
Name: obj.Spec.Chart.Spec.SourceRef.Name,
|
||||||
|
Namespace: obj.Spec.Chart.Spec.SourceRef.Namespace,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||||
@ -60,7 +61,7 @@ func (obj kustomizationAdapter) reconcileSource() bool {
|
|||||||
return rksArgs.syncKsWithSource
|
return rksArgs.syncKsWithSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj kustomizationAdapter) getSource() (reconcileCommand, string) {
|
func (obj kustomizationAdapter) getSource() (reconcileCommand, types.NamespacedName) {
|
||||||
var cmd reconcileCommand
|
var cmd reconcileCommand
|
||||||
switch obj.Spec.SourceRef.Kind {
|
switch obj.Spec.SourceRef.Kind {
|
||||||
case sourcev1.GitRepositoryKind:
|
case sourcev1.GitRepositoryKind:
|
||||||
@ -75,5 +76,8 @@ func (obj kustomizationAdapter) getSource() (reconcileCommand, string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd, obj.Spec.SourceRef.Name
|
return cmd, types.NamespacedName{
|
||||||
|
Name: obj.Spec.SourceRef.Name,
|
||||||
|
Namespace: obj.Spec.SourceRef.Namespace,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ type reconcileWithSource interface {
|
|||||||
adapter
|
adapter
|
||||||
reconcilable
|
reconcilable
|
||||||
reconcileSource() bool
|
reconcileSource() bool
|
||||||
getSource() (reconcileCommand, string)
|
getSource() (reconcileCommand, types.NamespacedName)
|
||||||
}
|
}
|
||||||
|
|
||||||
type reconcileWithSourceCommand struct {
|
type reconcileWithSourceCommand struct {
|
||||||
@ -55,14 +55,13 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if reconcile.object.reconcileSource() {
|
if reconcile.object.reconcileSource() {
|
||||||
|
reconcileCmd, nsName := reconcile.object.getSource()
|
||||||
nsCopy := rootArgs.namespace
|
nsCopy := rootArgs.namespace
|
||||||
objectNs := reconcile.object.asClientObject().GetNamespace()
|
if nsName.Namespace != "" {
|
||||||
if objectNs != "" {
|
rootArgs.namespace = nsName.Namespace
|
||||||
rootArgs.namespace = reconcile.object.asClientObject().GetNamespace()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reconcileCmd, sourceName := reconcile.object.getSource()
|
err := reconcileCmd.run(nil, []string{nsName.Name})
|
||||||
err := reconcileCmd.run(nil, []string{sourceName})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user