Skip to content

Commit b96401b

Browse files
authored
fix(project): Do not block project update when a cluster referenced in an App doesn't exist (#23659)
Signed-off-by: OpenGuidou <[email protected]>
1 parent f953976 commit b96401b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

server/project/project.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ func (s *Server) Update(ctx context.Context, q *project.ProjectUpdateRequest) (*
420420
destCluster, err := argo.GetDestinationCluster(ctx, a.Spec.Destination, s.db)
421421
if err != nil {
422422
if err.Error() != argo.ErrDestinationMissing {
423-
return nil, err
423+
// If cluster is not found, we should discard this app, as it's most likely already in error
424+
continue
424425
}
425426
invalidDstCount++
426427
}

server/project/project_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,35 @@ p, role:admin, projects, update, *, allow`)
743743
_, err := projectServer.GetSyncWindowsState(ctx, &project.SyncWindowsQuery{Name: projectWithSyncWindows.Name})
744744
assert.EqualError(t, err, "rpc error: code = PermissionDenied desc = permission denied: projects, get, test")
745745
})
746+
747+
t.Run("TestAddSyncWindowWhenAnAppReferencesAClusterThatDoesNotExist", func(t *testing.T) {
748+
_ = enforcer.SetBuiltinPolicy(`p, role:admin, projects, get, *, allow
749+
p, role:admin, projects, update, *, allow`)
750+
sessionMgr := session.NewSessionManager(settingsMgr, test.NewFakeProjLister(), "", nil, session.NewUserStateStorage(nil))
751+
projectWithAppWithInvalidCluster := existingProj.DeepCopy()
752+
753+
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
754+
invalidApp := v1alpha1.Application{
755+
ObjectMeta: metav1.ObjectMeta{Name: "test-invalid", Namespace: "default"},
756+
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test", Destination: v1alpha1.ApplicationDestination{Namespace: "ns3", Server: "https://server4"}},
757+
}
758+
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projectWithAppWithInvalidCluster, &invalidApp), enforcer, sync.NewKeyLock(), sessionMgr, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
759+
760+
// Add sync window
761+
syncWindow := v1alpha1.SyncWindow{
762+
Kind: "deny",
763+
Schedule: "* * * * *",
764+
Duration: "1h",
765+
Applications: []string{"*"},
766+
Clusters: []string{"*"},
767+
}
768+
projectWithAppWithInvalidCluster.Spec.SyncWindows = append(projectWithAppWithInvalidCluster.Spec.SyncWindows, &syncWindow)
769+
res, err := projectServer.Update(ctx, &project.ProjectUpdateRequest{
770+
Project: projectWithAppWithInvalidCluster,
771+
})
772+
require.NoError(t, err)
773+
assert.Len(t, res.Spec.SyncWindows, 1)
774+
})
746775
}
747776

748777
func newEnforcer(kubeclientset *fake.Clientset) *rbac.Enforcer {

0 commit comments

Comments
 (0)