Skip to content

Commit

Permalink
fix: AppProject informer should be single namespace (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannfis authored Nov 5, 2024
1 parent 237faa7 commit 97e0bdd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
17 changes: 4 additions & 13 deletions internal/informer/appproject/projectinformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package appproject

import (
"context"
"strings"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
Expand All @@ -33,7 +32,7 @@ import (

type AppProjectInformer struct {
filterFunc func(proj *v1alpha1.AppProject) bool
namespaces []string
namespace string
logger *logrus.Entry

projectInformer *informer.GenericInformer
Expand Down Expand Up @@ -93,14 +92,6 @@ func WithLogger(l *logrus.Entry) AppProjectInformerOption {
}
}

// WithNamespaces sets additional namespaces to be watched by the AppProjectInformer
func WithNamespaces(namespaces ...string) AppProjectInformerOption {
return func(o *AppProjectInformer) error {
o.namespaces = namespaces
return nil
}
}

// WithMetrics sets the AppProject watcher metrics to be used with this
// informer.
func WithMetrics(m *metrics.AppProjectWatcherMetrics) AppProjectInformerOption {
Expand All @@ -115,7 +106,7 @@ func WithMetrics(m *metrics.AppProjectWatcherMetrics) AppProjectInformerOption {
// given appclientset.
func NewAppProjectInformer(ctx context.Context, client appclientset.Interface, namespace string, options ...AppProjectInformerOption) (*AppProjectInformer, error) {
pi := &AppProjectInformer{
namespaces: make([]string, 0),
namespace: namespace,
}
for _, o := range options {
err := o(pi)
Expand Down Expand Up @@ -148,7 +139,7 @@ func NewAppProjectInformer(ctx context.Context, client appclientset.Interface, n
}
return projects, err
}),
informer.WithNamespaces(pi.namespaces...),
informer.WithNamespaces(pi.namespace),
informer.WithWatchCallback(func(options v1.ListOptions, namespace string) (watch.Interface, error) {
log().Info("Watching AppProjects")
return client.ArgoprojV1alpha1().AppProjects(namespace).Watch(ctx, options)
Expand Down Expand Up @@ -208,7 +199,7 @@ func NewAppProjectInformer(ctx context.Context, client appclientset.Interface, n
}

func (i *AppProjectInformer) Start(ctx context.Context) {
log().Infof("Starting app project informer (namespaces: %s)", strings.Join(i.namespaces, ","))
log().Infof("Starting app project informer (namespace: %s)", i.namespace)
err := i.projectInformer.Start(ctx)
if err != nil {
log().Errorf("Failed to start app project informer: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions internal/informer/appproject/projectinformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func Test_AppProjectInformer(t *testing.T) {
WithDeleteFunc(func(proj *v1alpha1.AppProject) {
numDeleted.Add(1)
}),
WithNamespaces("argocd"),
)
require.NoError(t, err)
require.NotNil(t, pi)
Expand Down Expand Up @@ -105,7 +104,7 @@ func Test_FilterFunc(t *testing.T) {
updateCh := make(chan bool)
deleteCh := make(chan bool)
ac := fakeappclient.NewSimpleClientset()
pi, err := NewAppProjectInformer(context.TODO(), ac, "test",
pi, err := NewAppProjectInformer(context.TODO(), ac, "argocd",
WithAddFunc(func(proj *v1alpha1.AppProject) {
numAdded.Add(1)
if numAdded.Load() > 1 {
Expand Down Expand Up @@ -179,7 +178,6 @@ func Test_NamespaceNotAllowed(t *testing.T) {
addCh := make(chan bool)
ac := fakeappclient.NewSimpleClientset()
pi, err := NewAppProjectInformer(context.TODO(), ac, "argocd",
WithNamespaces("argocd"),
WithAddFunc(func(proj *v1alpha1.AppProject) {
numAdded.Add(1)
require.Equal(t, "argocd", proj.Namespace)
Expand Down

0 comments on commit 97e0bdd

Please sign in to comment.