argo-cd/controller/sync_test.go

1656 lines
55 KiB
Go
Raw Normal View History

package controller
import (
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
"strconv"
"testing"
"github.com/argoproj/argo-cd/gitops-engine/pkg/sync"
synccommon "github.com/argoproj/argo-cd/gitops-engine/pkg/sync/common"
"github.com/argoproj/argo-cd/gitops-engine/pkg/utils/kube"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/argoproj/argo-cd/v3/common"
"github.com/argoproj/argo-cd/v3/controller/testdata"
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v3/reposerver/apiclient"
"github.com/argoproj/argo-cd/v3/test"
"github.com/argoproj/argo-cd/v3/util/argo/diff"
"github.com/argoproj/argo-cd/v3/util/argo/normalizers"
)
func TestPersistRevisionHistory(t *testing.T) {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
defaultProject := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
}
data := fakeData{
apps: []runtime.Object{app, defaultProject},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{},
}}
ctrl.appStateManager.SyncAppState(app, defaultProject, opState)
// Ensure we record spec.source into sync result
feat: Multiple sources for applications (#2789) (#10432) * feat: support multiple sources for application Signed-off-by: ishitasequeira <ishiseq29@gmail.com> remove debug logging and unwanted code Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix lint and unit test errors Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix lint and unit test errors Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix bug introduced after rebase Signed-off-by: ishitasequeira <ishiseq29@gmail.com> executed make codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> remove unwanted logging Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix ci failures Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix index out of bounds error Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * ui fixes Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <michael@crenshaw.dev> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add revisions to SyncOperation for rollback Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * change Source to *ApplicationSource in ApplicationSpec Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix env variable read logic for ValueFiles Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update multiple sources doc Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add repository lock and checkout target revision Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * checkout all sources before generating manifest Signed-off-by: ishitasequeira <ishiseq29@gmail.com> generate mock reposerverclient Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update logic for returning ManifestResponse to avoid nil pointer issues Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix nil reference and key mismatch bugs; add more logs (#6) * fix nil reference and key mismatch bugs; add more logs * remove temporary comment * addressed the lint failure and added chart to RefTargeRevisionMapping * normalize git repo (#7) * do not leak lock releases * prevent deadlock * allow spec update * move settings fetch outside loop * cache busing * return err instead of logging it * no caching in test * fix cache key marshaling Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update grpc field numbers Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * path resolution tests (#12) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> do things in better ways Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> consolidate Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add regex check for value of source.ref Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add webhook tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> change Source to *ApplicationSource in ApplicationSpec Signed-off-by: ishitasequeira <ishiseq29@gmail.com> address PR comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Retrigger CI pipeline Signed-off-by: ishitasequeira <ishiseq29@gmail.com> rebased with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix env variable read logic for ValueFiles Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Address PR comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add repository lock and checkout target revision Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * checkout all sources before generating manifest Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * generate mock reposerverclient Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * address comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update logic for returning ManifestResponse to avoid nil pointer issues Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix nil reference and key mismatch bugs; add more logs (#6) * fix nil reference and key mismatch bugs; add more logs * remove temporary comment * addressed the lint failure and added chart to RefTargeRevisionMapping * normalize git repo (#7) * do not leak lock releases * prevent deadlock * allow spec update * move settings fetch outside loop * cache busing * return err instead of logging it * no caching in test * fix cache key marshaling Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update grpc field numbers Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add regex check for value of source.ref Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * Added unit tests (#15) * add unit tests 1 * fix lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix application parameters tab, rebased UI changes, tests Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * More tests (#16) * more tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix lint error Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Test get ref sources (#17) * test GetRefSources Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: ishitasequeira <ishiseq29@gmail.com> GenerateManifests test (#18) * GenerateManifests test Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Fix broken tests (#19) * fix broken tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Symlink test (#20) * check referenced sources for out-of-bounds symlinks Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * unlock the values file repo before doing a symlink check (#22) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * multi source docs (#21) * multi source docs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix warning title Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * clarify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * clarify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * add e2e tests for multiple sources and fix UI lint (#23) * add e2e tests for multiple sources and fix UI lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add auto-sync and hard refresh to e2e tests Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * change refresh type to RefreshTypeNormal for e2e Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update e2e testcase with helm data Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add TestMultiSourceAppWithSourceOverride Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add missing yaml file Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <michael@crenshaw.dev> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
2022-12-16 20:47:08 +00:00
assert.Equal(t, app.Spec.GetSource(), opState.SyncResult.Source)
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(t.Context(), app.Name, metav1.GetOptions{})
require.NoError(t, err)
feat: source hydrator (#20345) * feat(hydrator): add sourceHydrator types Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix(codegen): use kube_codegen.sh deepcopy and client gen correctly Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> deepcopy gen Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): add commit-server component Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> go mod tidy Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> one test file for both implementations Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix test for linux Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix git client mock Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix git client mock Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> address comments Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> unit tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix image, fix health checks, fix merge issue Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix lint issues Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> remove code that doesn't work for GHE Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> changes from comments Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> allow opt-in Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> separation between app controller and hydrator Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify diff Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> todos Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add dry sha to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add app name to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> more logging, no caching Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix cluster install Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't interrupt an ongoing hydrate operation Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> revert hydrate loop fix Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> handle project-scoped repo creds Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> codegen Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> improve docs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fixes from comments Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * set hydrator enabled key when using hydrator manifests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix manifests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> improve docs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> allow opt-in Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> separation between app controller and hydrator Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify diff Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> todos Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add dry sha to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add app name to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> more logging, no caching Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix cluster install Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't interrupt an ongoing hydrate operation Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> revert hydrate loop fix Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> handle project-scoped repo creds Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> codegen Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> improve docs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fixes from comments Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): add sourceHydrator types Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix(codegen): use kube_codegen.sh deepcopy and client gen correctly Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> deepcopy gen Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> allow opt-in Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> separation between app controller and hydrator Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify diff Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> todos Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add dry sha to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add app name to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> more logging, no caching Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix cluster install Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't interrupt an ongoing hydrate operation Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> revert hydrate loop fix Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> handle project-scoped repo creds Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> codegen Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * feat(hydrator): write credentials handling + UI Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> feat(hydrator): enable controller Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Omer Azmon <omer_azmon@intuit.com> Co-authored-by: daengdaengLee <gunho1020@gmail.com> Co-authored-by: Juwon Hwang (Kevin) <juwon8891@gmail.com> Co-authored-by: thisishwan2 <feel000617@gmail.com> Co-authored-by: mirageoasis <kimhw0820@naver.com> Co-authored-by: Robin Lieb <robin.j.lieb@gmail.com> Co-authored-by: miiiinju1 <gms07073@ynu.ac.kr> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> allow opt-in Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> separation between app controller and hydrator Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify diff Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> todos Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> simplify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add dry sha to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> add app name to logs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> more logging, no caching Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix cluster install Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't interrupt an ongoing hydrate operation Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> revert hydrate loop fix Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> feat(hydrator): write credentials handling + UI Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> WIP: add new APIs for write creds Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> write api and template api Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix time function Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix lint issues Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't enrich with read creds Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> revert tls change Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't disable buttons in UI Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> ask repo server for specific revision Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fixes Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> lint ui Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> remove unnecessary change Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix test and lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> enable hydrator for e2e tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * free disk space for e2e tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> don't free disk space Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * free disk space for e2e tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * remove comment that breaks auth Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * try removing extra function Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * cleanup from comments Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix test Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
2024-12-16 21:59:09 +00:00
require.Len(t, updatedApp.Status.History, 1)
feat: Multiple sources for applications (#2789) (#10432) * feat: support multiple sources for application Signed-off-by: ishitasequeira <ishiseq29@gmail.com> remove debug logging and unwanted code Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix lint and unit test errors Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix lint and unit test errors Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix bug introduced after rebase Signed-off-by: ishitasequeira <ishiseq29@gmail.com> executed make codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> remove unwanted logging Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix ci failures Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix index out of bounds error Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * ui fixes Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <michael@crenshaw.dev> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add revisions to SyncOperation for rollback Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * change Source to *ApplicationSource in ApplicationSpec Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix env variable read logic for ValueFiles Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update multiple sources doc Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add repository lock and checkout target revision Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * checkout all sources before generating manifest Signed-off-by: ishitasequeira <ishiseq29@gmail.com> generate mock reposerverclient Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update logic for returning ManifestResponse to avoid nil pointer issues Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix nil reference and key mismatch bugs; add more logs (#6) * fix nil reference and key mismatch bugs; add more logs * remove temporary comment * addressed the lint failure and added chart to RefTargeRevisionMapping * normalize git repo (#7) * do not leak lock releases * prevent deadlock * allow spec update * move settings fetch outside loop * cache busing * return err instead of logging it * no caching in test * fix cache key marshaling Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update grpc field numbers Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * path resolution tests (#12) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> do things in better ways Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> consolidate Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add regex check for value of source.ref Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add webhook tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> change Source to *ApplicationSource in ApplicationSpec Signed-off-by: ishitasequeira <ishiseq29@gmail.com> address PR comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Retrigger CI pipeline Signed-off-by: ishitasequeira <ishiseq29@gmail.com> rebased with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix env variable read logic for ValueFiles Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Address PR comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add repository lock and checkout target revision Signed-off-by: ishitasequeira <ishiseq29@gmail.com> fix codegen Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * checkout all sources before generating manifest Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * generate mock reposerverclient Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * address comments Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update logic for returning ManifestResponse to avoid nil pointer issues Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix nil reference and key mismatch bugs; add more logs (#6) * fix nil reference and key mismatch bugs; add more logs * remove temporary comment * addressed the lint failure and added chart to RefTargeRevisionMapping * normalize git repo (#7) * do not leak lock releases * prevent deadlock * allow spec update * move settings fetch outside loop * cache busing * return err instead of logging it * no caching in test * fix cache key marshaling Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update grpc field numbers Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add regex check for value of source.ref Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * Rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * Added unit tests (#15) * add unit tests 1 * fix lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix application parameters tab, rebased UI changes, tests Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * More tests (#16) * more tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> fix lint error Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Test get ref sources (#17) * test GetRefSources Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix lint Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: ishitasequeira <ishiseq29@gmail.com> GenerateManifests test (#18) * GenerateManifests test Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Fix broken tests (#19) * fix broken tests Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Symlink test (#20) * check referenced sources for out-of-bounds symlinks Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * unlock the values file repo before doing a symlink check (#22) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * multi source docs (#21) * multi source docs Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * fix warning title Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * clarify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * clarify Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * add e2e tests for multiple sources and fix UI lint (#23) * add e2e tests for multiple sources and fix UI lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add auto-sync and hard refresh to e2e tests Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * change refresh type to RefreshTypeNormal for e2e Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * update e2e testcase with helm data Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add TestMultiSourceAppWithSourceOverride Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * add missing yaml file Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * rebase with master Signed-off-by: ishitasequeira <ishiseq29@gmail.com> * fix lint Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: ishitasequeira <ishiseq29@gmail.com> Signed-off-by: Michael Crenshaw <michael@crenshaw.dev> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
2022-12-16 20:47:08 +00:00
assert.Equal(t, app.Spec.GetSource(), updatedApp.Status.History[0].Source)
assert.Equal(t, "abc123", updatedApp.Status.History[0].Revision)
}
fix: update managed namespace metadata (#13074) * fix: update managed namespace metadata This commit fixes an issue where a namespace does not get updated unless a sync is performed. Since the `managedNamespaceMetadata` is not a part of the Application Git state, we need a way to force a sync once the metadata has changed. In order to do that, we need to add state to compare with. Once a sync is performed, the `ManagedNamespaceMetadata` gets copied to `SyncResult`, which will then be compared with on subsequent syncs. If there's a mismatch between `app.Spec.SyncPolicy.ManagedNamespaceMetadata` and `app.Status.OperationState.SyncResult.ManagedNamespaceMetadata` we mark the Application as `OutOfSync`. Fixes #12661. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: nil check Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: allow empty apps to be updated If an app is empty but still differs in terms of `managedNamespaceMetadata`, it should still be kept up to date. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * test: add unit tests in appcontroller Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: rebase Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * refactor: extract method Consolidate checks to `app.HasChangedManagedNamespaceMetadata()` Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * chore: make codegen Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> --------- Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
2023-05-19 13:55:08 +00:00
func TestPersistManagedNamespaceMetadataState(t *testing.T) {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
app.Spec.SyncPolicy.ManagedNamespaceMetadata = &v1alpha1.ManagedNamespaceMetadata{
Labels: map[string]string{
"foo": "bar",
},
Annotations: map[string]string{
"foo": "bar",
},
}
defaultProject := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
fix: update managed namespace metadata (#13074) * fix: update managed namespace metadata This commit fixes an issue where a namespace does not get updated unless a sync is performed. Since the `managedNamespaceMetadata` is not a part of the Application Git state, we need a way to force a sync once the metadata has changed. In order to do that, we need to add state to compare with. Once a sync is performed, the `ManagedNamespaceMetadata` gets copied to `SyncResult`, which will then be compared with on subsequent syncs. If there's a mismatch between `app.Spec.SyncPolicy.ManagedNamespaceMetadata` and `app.Status.OperationState.SyncResult.ManagedNamespaceMetadata` we mark the Application as `OutOfSync`. Fixes #12661. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: nil check Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: allow empty apps to be updated If an app is empty but still differs in terms of `managedNamespaceMetadata`, it should still be kept up to date. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * test: add unit tests in appcontroller Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: rebase Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * refactor: extract method Consolidate checks to `app.HasChangedManagedNamespaceMetadata()` Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * chore: make codegen Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> --------- Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
2023-05-19 13:55:08 +00:00
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
}
data := fakeData{
apps: []runtime.Object{app, defaultProject},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
fix: update managed namespace metadata (#13074) * fix: update managed namespace metadata This commit fixes an issue where a namespace does not get updated unless a sync is performed. Since the `managedNamespaceMetadata` is not a part of the Application Git state, we need a way to force a sync once the metadata has changed. In order to do that, we need to add state to compare with. Once a sync is performed, the `ManagedNamespaceMetadata` gets copied to `SyncResult`, which will then be compared with on subsequent syncs. If there's a mismatch between `app.Spec.SyncPolicy.ManagedNamespaceMetadata` and `app.Status.OperationState.SyncResult.ManagedNamespaceMetadata` we mark the Application as `OutOfSync`. Fixes #12661. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: nil check Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: allow empty apps to be updated If an app is empty but still differs in terms of `managedNamespaceMetadata`, it should still be kept up to date. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * test: add unit tests in appcontroller Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: rebase Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * refactor: extract method Consolidate checks to `app.HasChangedManagedNamespaceMetadata()` Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * chore: make codegen Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> --------- Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
2023-05-19 13:55:08 +00:00
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{},
}}
ctrl.appStateManager.SyncAppState(app, defaultProject, opState)
fix: update managed namespace metadata (#13074) * fix: update managed namespace metadata This commit fixes an issue where a namespace does not get updated unless a sync is performed. Since the `managedNamespaceMetadata` is not a part of the Application Git state, we need a way to force a sync once the metadata has changed. In order to do that, we need to add state to compare with. Once a sync is performed, the `ManagedNamespaceMetadata` gets copied to `SyncResult`, which will then be compared with on subsequent syncs. If there's a mismatch between `app.Spec.SyncPolicy.ManagedNamespaceMetadata` and `app.Status.OperationState.SyncResult.ManagedNamespaceMetadata` we mark the Application as `OutOfSync`. Fixes #12661. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: nil check Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: allow empty apps to be updated If an app is empty but still differs in terms of `managedNamespaceMetadata`, it should still be kept up to date. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * test: add unit tests in appcontroller Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: rebase Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * refactor: extract method Consolidate checks to `app.HasChangedManagedNamespaceMetadata()` Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * chore: make codegen Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> --------- Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
2023-05-19 13:55:08 +00:00
// Ensure we record spec.syncPolicy.managedNamespaceMetadata into sync result
assert.Equal(t, app.Spec.SyncPolicy.ManagedNamespaceMetadata, opState.SyncResult.ManagedNamespaceMetadata)
}
func TestPersistRevisionHistoryRollback(t *testing.T) {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
defaultProject := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
}
data := fakeData{
apps: []runtime.Object{app, defaultProject},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source specified
source := v1alpha1.ApplicationSource{
Helm: &v1alpha1.ApplicationSourceHelm{
Parameters: []v1alpha1.HelmParameter{
{
Name: "test",
Value: "123",
},
},
},
}
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &source,
},
}}
ctrl.appStateManager.SyncAppState(app, defaultProject, opState)
// Ensure we record opState's source into sync result
assert.Equal(t, source, opState.SyncResult.Source)
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(t.Context(), app.Name, metav1.GetOptions{})
require.NoError(t, err)
assert.Len(t, updatedApp.Status.History, 1)
assert.Equal(t, source, updatedApp.Status.History[0].Source)
assert.Equal(t, "abc123", updatedApp.Status.History[0].Revision)
}
func TestSyncComparisonError(t *testing.T) {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
defaultProject := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
Spec: v1alpha1.AppProjectSpec{
SignatureKeys: []v1alpha1.SignatureKey{{KeyID: "test"}},
},
}
data := fakeData{
apps: []runtime.Object{app, defaultProject},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
VerifyResult: "something went wrong",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{},
}}
t.Setenv("ARGOCD_GPG_ENABLED", "true")
ctrl.appStateManager.SyncAppState(app, defaultProject, opState)
conditions := app.Status.GetConditions(map[v1alpha1.ApplicationConditionType]bool{v1alpha1.ApplicationConditionComparisonError: true})
assert.NotEmpty(t, conditions)
assert.Equal(t, "abc123", opState.SyncResult.Revision)
}
func TestAppStateManager_SyncAppState(t *testing.T) {
t.Parallel()
type fixture struct {
application *v1alpha1.Application
project *v1alpha1.AppProject
controller *ApplicationController
}
setup := func(liveObjects map[kube.ResourceKey]*unstructured.Unstructured) *fixture {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
if liveObjects == nil {
liveObjects = make(map[kube.ResourceKey]*unstructured.Unstructured)
}
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
Spec: v1alpha1.AppProjectSpec{
SignatureKeys: []v1alpha1.SignatureKey{{KeyID: "test"}},
Destinations: []v1alpha1.ApplicationDestination{
{
Namespace: "*",
Server: "*",
},
},
},
}
data := fakeData{
apps: []runtime.Object{app, project},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: liveObjects,
}
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
project: project,
controller: ctrl,
}
}
t.Run("will fail the sync if finds shared resources", func(t *testing.T) {
// given
t.Parallel()
sharedObject := kube.MustToUnstructured(&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "configmap1",
Namespace: "default",
Annotations: map[string]string{
common.AnnotationKeyAppInstance: "guestbook:/ConfigMap:default/configmap1",
},
},
})
liveObjects := make(map[kube.ResourceKey]*unstructured.Unstructured)
liveObjects[kube.GetResourceKey(sharedObject)] = sharedObject
f := setup(liveObjects)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
SyncOptions: []string{"FailOnSharedResource=true"},
},
}}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then
assert.Equal(t, synccommon.OperationFailed, opState.Phase)
assert.Contains(t, opState.Message, "ConfigMap/configmap1 is part of applications fake-argocd-ns/my-app and guestbook")
})
}
func TestSyncWindowDeniesSync(t *testing.T) {
t.Parallel()
type fixture struct {
application *v1alpha1.Application
project *v1alpha1.AppProject
controller *ApplicationController
}
setup := func() *fixture {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
Spec: v1alpha1.AppProjectSpec{
SyncWindows: v1alpha1.SyncWindows{{
Kind: "deny",
Schedule: "0 0 * * *",
Duration: "24h",
Clusters: []string{"*"},
Namespaces: []string{"*"},
Applications: []string{"*"},
}},
},
}
data := fakeData{
apps: []runtime.Object{app, project},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
project: project,
controller: ctrl,
}
}
t.Run("will keep the sync progressing if a sync window prevents the sync", func(t *testing.T) {
// given a project with an active deny sync window and an operation in progress
t.Parallel()
f := setup()
opMessage := "Sync operation blocked by sync window"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then
assert.Equal(t, synccommon.OperationRunning, opState.Phase)
assert.Contains(t, opState.Message, opMessage)
})
}
func TestNormalizeTargetResources(t *testing.T) {
type fixture struct {
comparisonResult *comparisonResult
}
setup := func(t *testing.T, ignores []v1alpha1.ResourceIgnoreDifferences) *fixture {
t.Helper()
dc, err := diff.NewDiffConfigBuilder().
WithDiffSettings(ignores, nil, true, normalizers.IgnoreNormalizerOpts{}).
WithNoCache().
Build()
require.NoError(t, err)
live := test.YamlToUnstructured(testdata.LiveDeploymentYaml)
target := test.YamlToUnstructured(testdata.TargetDeploymentYaml)
return &fixture{
&comparisonResult{
reconciliationResult: sync.ReconciliationResult{
Live: []*unstructured.Unstructured{live},
Target: []*unstructured.Unstructured{target},
},
diffConfig: dc,
},
}
}
t.Run("will modify target resource adding live state in fields it should ignore", func(t *testing.T) {
// given
ignore := v1alpha1.ResourceIgnoreDifferences{
Group: "*",
Kind: "*",
ManagedFieldsManagers: []string{"janitor"},
}
ignores := []v1alpha1.ResourceIgnoreDifferences{ignore}
f := setup(t, ignores)
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
iksmVersion := targets[0].GetAnnotations()["iksm-version"]
assert.Equal(t, "2.0", iksmVersion)
})
t.Run("will not modify target resource if ignore difference is not configured", func(t *testing.T) {
// given
f := setup(t, []v1alpha1.ResourceIgnoreDifferences{})
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
iksmVersion := targets[0].GetAnnotations()["iksm-version"]
assert.Equal(t, "1.0", iksmVersion)
})
t.Run("will remove fields from target if not present in live", func(t *testing.T) {
ignore := v1alpha1.ResourceIgnoreDifferences{
Group: "apps",
Kind: "Deployment",
JSONPointers: []string{"/metadata/annotations/iksm-version"},
}
ignores := []v1alpha1.ResourceIgnoreDifferences{ignore}
f := setup(t, ignores)
live := f.comparisonResult.reconciliationResult.Live[0]
unstructured.RemoveNestedField(live.Object, "metadata", "annotations", "iksm-version")
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
_, ok := targets[0].GetAnnotations()["iksm-version"]
assert.False(t, ok)
})
t.Run("will correctly normalize with multiple ignore configurations", func(t *testing.T) {
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "apps",
Kind: "Deployment",
JSONPointers: []string{"/spec/replicas"},
},
{
Group: "*",
Kind: "*",
ManagedFieldsManagers: []string{"janitor"},
},
}
f := setup(t, ignores)
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
normalized := targets[0]
iksmVersion, ok := normalized.GetAnnotations()["iksm-version"]
require.True(t, ok)
assert.Equal(t, "2.0", iksmVersion)
replicas, ok, err := unstructured.NestedInt64(normalized.Object, "spec", "replicas")
require.NoError(t, err)
require.True(t, ok)
assert.Equal(t, int64(4), replicas)
})
t.Run("will keep new array entries not found in live state if not ignored", func(t *testing.T) {
t.Skip("limitation in the current implementation")
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "apps",
Kind: "Deployment",
JQPathExpressions: []string{".spec.template.spec.containers[] | select(.name == \"guestbook-ui\")"},
},
}
f := setup(t, ignores)
target := test.YamlToUnstructured(testdata.TargetDeploymentNewEntries)
f.comparisonResult.reconciliationResult.Target = []*unstructured.Unstructured{target}
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
containers, ok, err := unstructured.NestedSlice(targets[0].Object, "spec", "template", "spec", "containers")
require.NoError(t, err)
require.True(t, ok)
assert.Len(t, containers, 2)
})
}
func TestNormalizeTargetResourcesWithList(t *testing.T) {
type fixture struct {
comparisonResult *comparisonResult
}
setupHTTPProxy := func(t *testing.T, ignores []v1alpha1.ResourceIgnoreDifferences) *fixture {
t.Helper()
dc, err := diff.NewDiffConfigBuilder().
WithDiffSettings(ignores, nil, true, normalizers.IgnoreNormalizerOpts{}).
WithNoCache().
Build()
require.NoError(t, err)
live := test.YamlToUnstructured(testdata.LiveHTTPProxy)
target := test.YamlToUnstructured(testdata.TargetHTTPProxy)
return &fixture{
&comparisonResult{
reconciliationResult: sync.ReconciliationResult{
Live: []*unstructured.Unstructured{live},
Target: []*unstructured.Unstructured{target},
},
diffConfig: dc,
},
}
}
t.Run("will properly ignore nested fields within arrays", func(t *testing.T) {
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "projectcontour.io",
Kind: "HTTPProxy",
JQPathExpressions: []string{".spec.routes[]"},
// JSONPointers: []string{"/spec/routes"},
},
}
f := setupHTTPProxy(t, ignores)
target := test.YamlToUnstructured(testdata.TargetHTTPProxy)
f.comparisonResult.reconciliationResult.Target = []*unstructured.Unstructured{target}
// when
patchedTargets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, f.comparisonResult.reconciliationResult.Live, 1)
require.Len(t, f.comparisonResult.reconciliationResult.Target, 1)
require.Len(t, patchedTargets, 1)
// live should have 1 entry
require.Len(t, dig(f.comparisonResult.reconciliationResult.Live[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors"), 1)
// assert some arbitrary field to show `entries[0]` is not an empty object
require.Equal(t, "sample-header", dig(f.comparisonResult.reconciliationResult.Live[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors", 0, "entries", 0, "requestHeader", "headerName"))
// target has 2 entries
require.Len(t, dig(f.comparisonResult.reconciliationResult.Target[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors", 0, "entries"), 2)
// assert some arbitrary field to show `entries[0]` is not an empty object
require.Equal(t, "sample-header", dig(f.comparisonResult.reconciliationResult.Target[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors", 0, "entries", 0, "requestHeaderValueMatch", "headers", 0, "name"))
// It should be *1* entries in the array
require.Len(t, dig(patchedTargets[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors"), 1)
// and it should NOT equal an empty object
require.Len(t, dig(patchedTargets[0].Object, "spec", "routes", 0, "rateLimitPolicy", "global", "descriptors", 0, "entries", 0), 1)
})
t.Run("will correctly set array entries if new entries have been added", func(t *testing.T) {
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "apps",
Kind: "Deployment",
JQPathExpressions: []string{".spec.template.spec.containers[].env[] | select(.name == \"SOME_ENV_VAR\")"},
},
}
f := setupHTTPProxy(t, ignores)
live := test.YamlToUnstructured(testdata.LiveDeploymentEnvVarsYaml)
target := test.YamlToUnstructured(testdata.TargetDeploymentEnvVarsYaml)
f.comparisonResult.reconciliationResult.Live = []*unstructured.Unstructured{live}
f.comparisonResult.reconciliationResult.Target = []*unstructured.Unstructured{target}
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
containers, ok, err := unstructured.NestedSlice(targets[0].Object, "spec", "template", "spec", "containers")
require.NoError(t, err)
require.True(t, ok)
assert.Len(t, containers, 1)
ports := containers[0].(map[string]any)["ports"].([]any)
assert.Len(t, ports, 1)
env := containers[0].(map[string]any)["env"].([]any)
assert.Len(t, env, 3)
first := env[0]
second := env[1]
third := env[2]
// Currently the defined order at this time is the insertion order of the target manifest.
assert.Equal(t, "SOME_ENV_VAR", first.(map[string]any)["name"])
assert.Equal(t, "some_value", first.(map[string]any)["value"])
assert.Equal(t, "SOME_OTHER_ENV_VAR", second.(map[string]any)["name"])
assert.Equal(t, "some_other_value", second.(map[string]any)["value"])
assert.Equal(t, "YET_ANOTHER_ENV_VAR", third.(map[string]any)["name"])
assert.Equal(t, "yet_another_value", third.(map[string]any)["value"])
})
t.Run("ignore-deployment-image-replicas-changes-additive", func(t *testing.T) {
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "apps",
Kind: "Deployment",
JSONPointers: []string{"/spec/replicas"},
}, {
Group: "apps",
Kind: "Deployment",
JQPathExpressions: []string{".spec.template.spec.containers[].image"},
},
}
f := setupHTTPProxy(t, ignores)
live := test.YamlToUnstructured(testdata.MinimalImageReplicaDeploymentYaml)
target := test.YamlToUnstructured(testdata.AdditionalImageReplicaDeploymentYaml)
f.comparisonResult.reconciliationResult.Live = []*unstructured.Unstructured{live}
f.comparisonResult.reconciliationResult.Target = []*unstructured.Unstructured{target}
// when
targets, err := normalizeTargetResources(f.comparisonResult)
// then
require.NoError(t, err)
require.Len(t, targets, 1)
metadata, ok, err := unstructured.NestedMap(targets[0].Object, "metadata")
require.NoError(t, err)
require.True(t, ok)
labels, ok := metadata["labels"].(map[string]any)
require.True(t, ok)
assert.Len(t, labels, 2)
assert.Equal(t, "web", labels["appProcess"])
spec, ok, err := unstructured.NestedMap(targets[0].Object, "spec")
require.NoError(t, err)
require.True(t, ok)
assert.Equal(t, int64(1), spec["replicas"])
template, ok := spec["template"].(map[string]any)
require.True(t, ok)
tMetadata, ok := template["metadata"].(map[string]any)
require.True(t, ok)
tLabels, ok := tMetadata["labels"].(map[string]any)
require.True(t, ok)
assert.Len(t, tLabels, 2)
assert.Equal(t, "web", tLabels["appProcess"])
tSpec, ok := template["spec"].(map[string]any)
require.True(t, ok)
containers, ok, err := unstructured.NestedSlice(tSpec, "containers")
require.NoError(t, err)
require.True(t, ok)
assert.Len(t, containers, 1)
first := containers[0].(map[string]any)
assert.Equal(t, "alpine:3", first["image"])
resources, ok := first["resources"].(map[string]any)
require.True(t, ok)
requests, ok := resources["requests"].(map[string]any)
require.True(t, ok)
assert.Equal(t, "400m", requests["cpu"])
env, ok, err := unstructured.NestedSlice(first, "env")
require.NoError(t, err)
require.True(t, ok)
assert.Len(t, env, 1)
env0 := env[0].(map[string]any)
assert.Equal(t, "EV", env0["name"])
assert.Equal(t, "here", env0["value"])
})
}
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
func TestDeriveServiceAccountMatchingNamespaces(t *testing.T) {
t.Parallel()
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
type fixture struct {
project *v1alpha1.AppProject
application *v1alpha1.Application
cluster *v1alpha1.Cluster
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
setup := func(destinationServiceAccounts []v1alpha1.ApplicationDestinationServiceAccount, destinationNamespace, destinationServerURL, applicationNamespace string) *fixture {
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Namespace: "argocd-ns",
Name: "testProj",
},
Spec: v1alpha1.AppProjectSpec{
DestinationServiceAccounts: destinationServiceAccounts,
},
}
app := &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Namespace: applicationNamespace,
Name: "testApp",
},
Spec: v1alpha1.ApplicationSpec{
Project: "testProj",
Destination: v1alpha1.ApplicationDestination{
Server: destinationServerURL,
Namespace: destinationNamespace,
},
},
}
cluster := &v1alpha1.Cluster{
Server: "https://kubernetes.svc.local",
Name: "test-cluster",
}
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
return &fixture{
project: project,
application: app,
cluster: cluster,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
}
t.Run("empty destination service accounts", func(t *testing.T) {
// given an application referring a project with no destination service accounts
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := ""
expectedErrMsg := "no matching service account found for destination server https://kubernetes.svc.local and namespace testns"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Equal(t, expectedSA, sa)
// then, there should be an error saying no valid match was found
assert.EqualError(t, err, expectedErrMsg)
})
t.Run("exact match of destination namespace", func(t *testing.T) {
// given an application referring a project with exactly one destination service account that matches the application destination,
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should be no error and should use the right service account for impersonation
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("exact one match with multiple destination service accounts", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts having one exact match for application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "guestbook-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "guestbook-test",
DefaultServiceAccount: "guestbook-test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should be no error and should use the right service account for impersonation
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("first match to be used when multiple matches are available", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts having multiple match for application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-3",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "guestbook-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should be no error and it should use the first matching service account for impersonation
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("first match to be used when glob pattern is used", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with glob patterns matching the application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "test*",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and should use the first matching glob pattern service account for impersonation
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("no match among a valid list", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with no matches for application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "test1",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "test2",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := ""
expectedErrMsg := "no matching service account found for destination server https://kubernetes.svc.local and namespace testns"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should be an error saying no match was found
require.EqualError(t, err, expectedErrMsg)
assert.Equal(t, expectedSA, sa)
})
t.Run("app destination namespace is empty", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with empty application destination namespace
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "*",
DefaultServiceAccount: "test-sa-2",
},
}
destinationNamespace := ""
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:argocd-ns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and the service account configured for with empty namespace should be used.
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("match done via catch all glob pattern", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts having a catch all glob pattern
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns1",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and the catch all service account should be returned
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("match done via invalid glob pattern", func(t *testing.T) {
// given an application referring a project with a destination service account having an invalid glob pattern for namespace
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "e[[a*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := ""
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there must be an error as the glob pattern is invalid.
require.ErrorContains(t, err, "invalid glob pattern for destination namespace")
assert.Equal(t, expectedSA, sa)
})
t.Run("sa specified with a namespace", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts having a matching service account specified with its namespace
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "myns:test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:myns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
assert.Equal(t, expectedSA, sa)
// then, there should not be any error and the service account with its namespace should be returned.
require.NoError(t, err)
})
t.Run("app destination name instead of server URL", func(t *testing.T) {
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// Use destination name instead of server URL
f.application.Spec.Destination.Server = ""
f.application.Spec.Destination.Name = f.cluster.Name
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Equal(t, expectedSA, sa)
// then, there should not be any error and the service account with its namespace should be returned.
require.NoError(t, err)
})
}
func TestDeriveServiceAccountMatchingServers(t *testing.T) {
t.Parallel()
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
type fixture struct {
project *v1alpha1.AppProject
application *v1alpha1.Application
cluster *v1alpha1.Cluster
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
setup := func(destinationServiceAccounts []v1alpha1.ApplicationDestinationServiceAccount, destinationNamespace, destinationServerURL, applicationNamespace string) *fixture {
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Namespace: "argocd-ns",
Name: "testProj",
},
Spec: v1alpha1.AppProjectSpec{
DestinationServiceAccounts: destinationServiceAccounts,
},
}
app := &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Namespace: applicationNamespace,
Name: "testApp",
},
Spec: v1alpha1.ApplicationSpec{
Project: "testProj",
Destination: v1alpha1.ApplicationDestination{
Server: destinationServerURL,
Namespace: destinationNamespace,
},
},
}
cluster := &v1alpha1.Cluster{
Server: "https://kubernetes.svc.local",
Name: "test-cluster",
}
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
return &fixture{
project: project,
application: app,
cluster: cluster,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
}
t.Run("exact one match with multiple destination service accounts", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts and one exact match for application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "guestbook-sa",
},
{
Server: "https://abc.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "guestbook-test-sa",
},
{
Server: "https://cde.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "default-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and the right service account must be returned.
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("first match to be used when multiple matches are available", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts and multiple matches for application destination
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "guestbook",
DefaultServiceAccount: "guestbook-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and first matching service account should be used
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("first match to be used when glob pattern is used", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with a matching glob pattern and exact match
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "test*",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Equal(t, expectedSA, sa)
// then, there should not be any error and the service account of the glob pattern, being the first match should be returned.
require.NoError(t, err)
})
t.Run("no match among a valid list", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with no match
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa",
},
{
Server: "https://abc.svc.local",
Namespace: "testns",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://cde.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://xyz.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := ""
expectedErr := "no matching service account found for destination server https://xyz.svc.local and namespace testns"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, &v1alpha1.Cluster{Server: destinationServerURL})
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there an error with appropriate message must be returned
require.EqualError(t, err, expectedErr)
assert.Equal(t, expectedSA, sa)
})
t.Run("match done via catch all glob pattern", func(t *testing.T) {
// given an application referring a project with multiple destination service accounts with matching catch all glob pattern
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "testns1",
DefaultServiceAccount: "test-sa-2",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "*",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://localhost:6443"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and the service account of the glob pattern match must be returned.
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("match done via invalid glob pattern", func(t *testing.T) {
// given an application referring a project with a destination service account having an invalid glob pattern for server
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "e[[a*",
Namespace: "test-ns",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := ""
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there must be an error as the glob pattern is invalid.
require.ErrorContains(t, err, "invalid glob pattern for destination server")
assert.Equal(t, expectedSA, sa)
})
t.Run("sa specified with a namespace", func(t *testing.T) {
// given app sync impersonation feature is enabled and matching service account is prefixed with a namespace
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://abc.svc.local",
Namespace: "testns",
DefaultServiceAccount: "myns:test-sa",
},
{
Server: "https://kubernetes.svc.local",
Namespace: "default",
DefaultServiceAccount: "default-sa",
},
{
Server: "*",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://abc.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:myns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, &v1alpha1.Cluster{Server: destinationServerURL})
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, there should not be any error and the service account with the given namespace prefix must be returned.
require.NoError(t, err)
assert.Equal(t, expectedSA, sa)
})
t.Run("app destination name instead of server URL", func(t *testing.T) {
t.Parallel()
destinationServiceAccounts := []v1alpha1.ApplicationDestinationServiceAccount{
{
Server: "https://kubernetes.svc.local",
Namespace: "*",
DefaultServiceAccount: "test-sa",
},
}
destinationNamespace := "testns"
destinationServerURL := "https://kubernetes.svc.local"
applicationNamespace := "argocd-ns"
expectedSA := "system:serviceaccount:testns:test-sa"
f := setup(destinationServiceAccounts, destinationNamespace, destinationServerURL, applicationNamespace)
// Use destination name instead of server URL
f.application.Spec.Destination.Server = ""
f.application.Spec.Destination.Name = f.cluster.Name
// when
sa, err := deriveServiceAccountToImpersonate(f.project, f.application, f.cluster)
assert.Equal(t, expectedSA, sa)
// then, there should not be any error and the service account with its namespace should be returned.
require.NoError(t, err)
})
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
func TestSyncWithImpersonate(t *testing.T) {
type fixture struct {
application *v1alpha1.Application
project *v1alpha1.AppProject
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
controller *ApplicationController
}
setup := func(impersonationEnabled bool, destinationNamespace, serviceAccountName string) *fixture {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
Spec: v1alpha1.AppProjectSpec{
DestinationServiceAccounts: []v1alpha1.ApplicationDestinationServiceAccount{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
{
Server: "https://localhost:6443",
Namespace: destinationNamespace,
DefaultServiceAccount: serviceAccountName,
},
},
},
}
additionalObjs := []runtime.Object{}
if serviceAccountName != "" {
syncServiceAccount := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
Name: serviceAccountName,
Namespace: test.FakeDestNamespace,
},
}
additionalObjs = append(additionalObjs, syncServiceAccount)
}
data := fakeData{
apps: []runtime.Object{app, project},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: "https://localhost:6443",
Revision: "abc123",
},
managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{},
configMapData: map[string]string{
"application.sync.impersonation.enabled": strconv.FormatBool(impersonationEnabled),
},
additionalObjs: additionalObjs,
}
ctrl := newFakeController(t.Context(), &data, nil)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
return &fixture{
application: app,
project: project,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
controller: ctrl,
}
}
t.Run("sync with impersonation and no matching service account", func(t *testing.T) {
// given app sync impersonation feature is enabled with an application referring a project no matching service account
f := setup(true, test.FakeArgoCDNamespace, "")
opMessage := "failed to find a matching service account to impersonate: no matching service account found for destination server https://localhost:6443 and namespace fake-dest-ns"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then, app sync should fail with expected error message in operation state
assert.Equal(t, synccommon.OperationError, opState.Phase)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Contains(t, opState.Message, opMessage)
})
t.Run("sync with impersonation and empty service account match", func(t *testing.T) {
// given app sync impersonation feature is enabled with an application referring a project matching service account that is an empty string
f := setup(true, test.FakeDestNamespace, "")
opMessage := "failed to find a matching service account to impersonate: default service account contains invalid chars ''"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then app sync should fail with expected error message in operation state
assert.Equal(t, synccommon.OperationError, opState.Phase)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Contains(t, opState.Message, opMessage)
})
t.Run("sync with impersonation and matching sa", func(t *testing.T) {
// given app sync impersonation feature is enabled with an application referring a project matching service account
f := setup(true, test.FakeDestNamespace, "test-sa")
opMessage := "successfully synced (no more tasks)"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then app sync should not fail
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Contains(t, opState.Message, opMessage)
})
t.Run("sync without impersonation", func(t *testing.T) {
// given app sync impersonation feature is disabled with an application referring a project matching service account
f := setup(false, test.FakeDestNamespace, "")
opMessage := "successfully synced (no more tasks)"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
}
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
// then application sync should pass using the control plane service account
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
assert.Contains(t, opState.Message, opMessage)
})
t.Run("app destination name instead of server URL", func(t *testing.T) {
// given app sync impersonation feature is enabled with an application referring a project matching service account
f := setup(true, test.FakeDestNamespace, "test-sa")
opMessage := "successfully synced (no more tasks)"
opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
},
Phase: synccommon.OperationRunning,
}
f.application.Spec.Destination.Server = ""
f.application.Spec.Destination.Name = "minikube"
// when
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then app sync should not fail
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
assert.Contains(t, opState.Message, opMessage)
chore: Added unit tests and fix e2e tests for application sync decoupling feature (#19966) * fixed doc comments and added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added comments for the newly added unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Refactored method name to deriveServiceAccountToImpersonate Signed-off-by: anandf <anjoseph@redhat.com> * Using const name in return value Signed-off-by: anandf <anjoseph@redhat.com> * Added unit tests for argocd proj add-destination-service-accounts Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing e2e tests Signed-off-by: anandf <anjoseph@redhat.com> * Fix linting errors Signed-off-by: anandf <anjoseph@redhat.com> * Using require package instead of assert and fixed code generation Signed-off-by: anandf <anjoseph@redhat.com> * Removed parallel execution of tests for sync with impersonate Signed-off-by: anandf <anjoseph@redhat.com> * Added err checks for glob validations Signed-off-by: anandf <anjoseph@redhat.com> * Fixed e2e tests for sync impersonation Signed-off-by: anandf <anjoseph@redhat.com> * Using consistently based expects in E2E tests Signed-off-by: anandf <anjoseph@redhat.com> * Added more unit tests and fixed go generate Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failed lint errors, unit and e2e test failures Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports linter issue Signed-off-by: anandf <anjoseph@redhat.com> * Added code comments and added few missing unit tests Signed-off-by: anandf <anjoseph@redhat.com> * Added missing unit test for GetDestinationServiceAccounts method Signed-off-by: anandf <anjoseph@redhat.com> * Fixed goimports formatting with local for project_test.go Signed-off-by: anandf <anjoseph@redhat.com> * Corrected typo in a field name additionalObjs Signed-off-by: anandf <anjoseph@redhat.com> * Fixed failing unit tests Signed-off-by: anandf <anjoseph@redhat.com> --------- Signed-off-by: anandf <anjoseph@redhat.com>
2024-10-03 14:37:50 +00:00
})
}
func TestClientSideApplyMigration(t *testing.T) {
t.Parallel()
type fixture struct {
application *v1alpha1.Application
project *v1alpha1.AppProject
controller *ApplicationController
}
setup := func(disableMigration bool, customManager string) *fixture {
app := newFakeApp()
app.Status.OperationState = nil
app.Status.History = nil
// Add sync options
if disableMigration {
app.Spec.SyncPolicy.SyncOptions = append(app.Spec.SyncPolicy.SyncOptions, "DisableClientSideApplyMigration=true")
}
// Add custom manager annotation if specified
if customManager != "" {
app.Annotations = map[string]string{
"argocd.argoproj.io/client-side-apply-migration-manager": customManager,
}
}
project := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.FakeArgoCDNamespace,
Name: "default",
},
}
data := fakeData{
apps: []runtime.Object{app, project},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
project: project,
controller: ctrl,
}
}
t.Run("client-side apply migration enabled by default", func(t *testing.T) {
// given
t.Parallel()
f := setup(false, "")
// when
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
}}
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
assert.Contains(t, opState.Message, "successfully synced")
})
t.Run("client-side apply migration disabled", func(t *testing.T) {
// given
t.Parallel()
f := setup(true, "")
// when
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
}}
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
assert.Contains(t, opState.Message, "successfully synced")
})
t.Run("client-side apply migration with custom manager", func(t *testing.T) {
// given
t.Parallel()
f := setup(false, "my-custom-manager")
// when
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{
Source: &v1alpha1.ApplicationSource{},
},
}}
f.controller.appStateManager.SyncAppState(f.application, f.project, opState)
// then
assert.Equal(t, synccommon.OperationSucceeded, opState.Phase)
assert.Contains(t, opState.Message, "successfully synced")
})
}
func dig(obj any, path ...any) any {
i := obj
for _, segment := range path {
switch segment := segment.(type) {
case int:
i = i.([]any)[segment]
case string:
i = i.(map[string]any)[segment]
default:
panic("invalid path for object")
}
}
return i
}