fix: Ensure application sets in custom namespace can be upserted (#23860)

Signed-off-by: Brian Fox <brian.fox@embark-studios.com>
Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
Brian Fox
2025-09-12 20:57:05 +02:00
committed by GitHub
parent b18ea682c4
commit bb56b9ea67
2 changed files with 53 additions and 3 deletions

View File

@@ -230,7 +230,7 @@ func (s *Server) Create(ctx context.Context, q *applicationset.ApplicationSetCre
return nil, fmt.Errorf("error creating ApplicationSet: %w", err)
}
// act idempotent if existing spec matches new spec
existing, err := s.appclientset.ArgoprojV1alpha1().ApplicationSets(s.ns).Get(ctx, appset.Name, metav1.GetOptions{
existing, err := s.appclientset.ArgoprojV1alpha1().ApplicationSets(namespace).Get(ctx, appset.Name, metav1.GetOptions{
ResourceVersion: "",
})
if err != nil {
@@ -297,7 +297,7 @@ func (s *Server) updateAppSet(ctx context.Context, appset *v1alpha1.ApplicationS
appset.Annotations = newAppset.Annotations
}
appset.Finalizers = newAppset.Finalizers
res, err := s.appclientset.ArgoprojV1alpha1().ApplicationSets(s.ns).Update(ctx, appset, metav1.UpdateOptions{})
res, err := s.appclientset.ArgoprojV1alpha1().ApplicationSets(appset.Namespace).Update(ctx, appset, metav1.UpdateOptions{})
if err == nil {
s.logAppSetEvent(ctx, appset, argo.EventReasonResourceUpdated, "updated ApplicationSets spec")
s.waitSync(res)
@@ -307,7 +307,7 @@ func (s *Server) updateAppSet(ctx context.Context, appset *v1alpha1.ApplicationS
return nil, err
}
appset, err = s.appclientset.ArgoprojV1alpha1().ApplicationSets(s.ns).Get(ctx, newAppset.Name, metav1.GetOptions{})
appset, err = s.appclientset.ArgoprojV1alpha1().ApplicationSets(appset.Namespace).Get(ctx, appset.Name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error getting ApplicationSets: %w", err)
}

View File

@@ -571,6 +571,56 @@ func TestUpdateAppSet(t *testing.T) {
})
}
func TestUpsertAppSet(t *testing.T) {
name := "test"
ns := "external-namespace"
appSet := newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Annotations = map[string]string{
"annotation-key1": "annotation-value1",
"annotation-key2": "annotation-value2",
}
appset.Labels = map[string]string{
"label-key1": "label-value1",
"label-key2": "label-value2",
}
appset.Name = name
appset.Namespace = ns
appset.Finalizers = []string{"finalizer"}
})
updatedAppSet := newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Annotations = map[string]string{
"annotation-key1": "annotation-value1-updated",
}
appset.Labels = map[string]string{
"label-key1": "label-value1-updated",
}
appset.Name = name
appset.Namespace = ns
appset.Finalizers = []string{"finalizer-updated"}
})
t.Run("Upsert", func(t *testing.T) {
appServer := newTestAppSetServer(t, appSet)
updated, err := appServer.Create(t.Context(), &applicationset.ApplicationSetCreateRequest{
Applicationset: updatedAppSet,
Upsert: true,
})
require.NoError(t, err)
assert.Equal(t, map[string]string{
"annotation-key1": "annotation-value1-updated",
"annotation-key2": "annotation-value2",
}, updated.Annotations)
assert.Equal(t, map[string]string{
"label-key1": "label-value1-updated",
"label-key2": "label-value2",
}, updated.Labels)
assert.Equal(t, []string{"finalizer-updated"}, updated.Finalizers)
})
}
func TestResourceTree(t *testing.T) {
appSet1 := newTestAppSet(func(appset *appsv1.ApplicationSet) {
appset.Name = "AppSet1"