Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,15 @@ jobs:
flags: unit-tests

test-e2e:
name: Run end-to-end tests
name: Run end-to-end tests (${{ matrix.mapping-mode }})
if: ${{ needs.changes.outputs.code == 'true' }}
runs-on: ubuntu-22.04
needs:
- changes
strategy:
fail-fast: false
matrix:
mapping-mode: [namespaced-mapping, destination-mapping]
env:
GOPATH: /home/runner/go
steps:
Expand Down Expand Up @@ -230,6 +234,13 @@ jobs:
- name: Set up the test environment
run: |
make setup-e2e
- name: Set destination-based mapping env vars
if: ${{ matrix.mapping-mode == 'destination-mapping' }}
run: |
echo "ARGOCD_AGENT_DESTINATION_BASED_MAPPING=true" >> $GITHUB_ENV
echo "ARGOCD_PRINCIPAL_DESTINATION_BASED_MAPPING=true" >> $GITHUB_ENV
echo "ARGOCD_AGENT_CREATE_NAMESPACE=true" >> $GITHUB_ENV
echo "E2E_DESTINATION_BASED_MAPPING=true" >> $GITHUB_ENV
- name: Run the principal and agents
run: |
make all
Expand All @@ -250,31 +261,31 @@ jobs:
- name: Upload e2e-argocd-agent logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: e2e-argocd-agent.log
name: e2e-argocd-agent-${{ matrix.mapping-mode }}.log
path: /tmp/e2e-argocd-agent.log
if: ${{ failure() }}
- name: Upload test logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: test-e2e.log
name: test-e2e-${{ matrix.mapping-mode }}.log
path: /tmp/test-e2e.log
if: ${{ failure() }}
- name: Upload vcluster-agent-autonomous-controller logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: vcluster-agent-autonomous-controller.log
name: vcluster-agent-autonomous-controller-${{ matrix.mapping-mode }}.log
path: /tmp/vcluster-agent-autonomous-controller.log
if: ${{ failure() }}
- name: Upload vcluster-agent-managed-controller logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: vcluster-agent-managed-controller.log
name: vcluster-agent-managed-controller-${{ matrix.mapping-mode }}.log
path: /tmp/vcluster-agent-managed-controller.log
if: ${{ failure() }}
- name: Upload vcluster-control-plane-server logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: vcluster-control-plane-server.log
name: vcluster-control-plane-server-${{ matrix.mapping-mode }}.log
path: /tmp/vcluster-control-plane-server.log
if: ${{ failure() }}

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ start-e2e: cli install-goreman
test-e2e:
./test/run-e2e.sh

.PHONY: test-e2e-destmap
test-e2e-destmap:
E2E_DESTINATION_BASED_MAPPING=true ./test/run-e2e.sh

.PHONY: start-e2e-destmap
start-e2e-destmap: cli install-goreman
ARGOCD_AGENT_DESTINATION_BASED_MAPPING=true ARGOCD_PRINCIPAL_DESTINATION_BASED_MAPPING=true ARGOCD_AGENT_CREATE_NAMESPACE=true ENABLE_DATA_RACE_DETECTOR=$(ENABLE_DATA_RACE_DETECTOR) ./hack/dev-env/start-e2e.sh

.PHONY: test
test:
mkdir -p test/out
Expand Down
2 changes: 2 additions & 0 deletions hack/dev-env/start-agent-autonomous.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ go run ${RACE_FLAG} github.com/argoproj-labs/argocd-agent/cmd/argocd-agent agent
--server-address 127.0.0.1 \
--kubecontext vcluster-agent-autonomous \
--namespace ${ARGOCD_AUTONOMOUS_NAMESPACE} \
--destination-based-mapping=false \
--create-namespace=false \
--log-level ${ARGOCD_AGENT_LOG_LEVEL:-trace} $ARGS \
--metrics-port 8182 \
--healthz-port 8002 \
Expand Down
2 changes: 2 additions & 0 deletions hack/dev-env/start-agent-managed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ go run ${RACE_FLAG} github.com/argoproj-labs/argocd-agent/cmd/argocd-agent agent
--server-address 127.0.0.1 \
--kubecontext vcluster-agent-managed \
--namespace ${ARGOCD_MANAGED_NAMESPACE} \
--destination-based-mapping=${ARGOCD_AGENT_DESTINATION_BASED_MAPPING:-false} \
--create-namespace=${ARGOCD_AGENT_CREATE_NAMESPACE:-false} \
--log-level ${ARGOCD_AGENT_LOG_LEVEL:-trace} $ARGS \
--healthz-port 8001 \
#--enable-compression true
Expand Down
1 change: 1 addition & 0 deletions hack/dev-env/start-principal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go run ${RACE_FLAG} github.com/argoproj-labs/argocd-agent/cmd/argocd-agent princ
--kubecontext vcluster-control-plane \
--log-level ${ARGOCD_AGENT_LOG_LEVEL:-trace} \
--namespace ${ARGOCD_PRINCIPAL_NAMESPACE} \
--destination-based-mapping=${ARGOCD_PRINCIPAL_DESTINATION_BASED_MAPPING:-false}\
--auth "mtls:CN=([^,]+)" \
--resource-proxy-address "${ARGOCD_AGENT_RESOURCE_PROXY}:9090" \
$ARGS
28 changes: 8 additions & 20 deletions test/e2e/adoption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsAdoptedIfExists() {
app := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-adopt",
Namespace: fixture.ManagedAgentNamespace,
Namespace: fixture.ManagedAgentAppNamespace(),
},
Spec: argoapp.ApplicationSpec{
Project: "default",
Expand All @@ -71,10 +71,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsAdoptedIfExists() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "adoption-test",
},
Destination: fixture.ManagedDestination("adoption-test"),
SyncPolicy: &argoapp.SyncPolicy{
SyncOptions: argoapp.SyncOptions{
"CreateNamespace=true",
Expand All @@ -98,7 +95,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsAdoptedIfExists() {
app2 := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-adopt",
Namespace: fixture.AgentManagedName,
Namespace: fixture.ManagedPrincipalAppNamespace(),
},
Spec: argoapp.ApplicationSpec{
Project: "default",
Expand All @@ -107,10 +104,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsAdoptedIfExists() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Name: "agent-managed",
Namespace: "adoption-test",
},
Destination: fixture.ManagedDestination("adoption-test"),
},
}

Expand Down Expand Up @@ -149,7 +143,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsNotAdoptedIfPolicyIsNever() {
app := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-dontadopt",
Namespace: fixture.ManagedAgentNamespace,
Namespace: fixture.ManagedAgentAppNamespace(),
Annotations: map[string]string{
manager.AdoptionPolicyAnnotation: string(manager.AdoptionPolicyNever),
},
Expand All @@ -161,10 +155,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsNotAdoptedIfPolicyIsNever() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "adoption-test",
},
Destination: fixture.ManagedDestination("adoption-test"),
SyncPolicy: &argoapp.SyncPolicy{
SyncOptions: argoapp.SyncOptions{
"CreateNamespace=true",
Expand All @@ -188,7 +179,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsNotAdoptedIfPolicyIsNever() {
app2 := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-dontadopt",
Namespace: fixture.AgentManagedName,
Namespace: fixture.ManagedPrincipalAppNamespace(),
},
Spec: argoapp.ApplicationSpec{
Project: "default",
Expand All @@ -197,10 +188,7 @@ func (suite *AdoptionTestSuite) Test_ApplicationIsNotAdoptedIfPolicyIsNever() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Name: fixture.AgentManagedName,
Namespace: "adoption-test",
},
Destination: fixture.ManagedDestination("adoption-test"),
},
}

Expand Down
19 changes: 8 additions & 11 deletions test/e2e/appcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (suite *CacheTestSuite) Test_RevertManagedClusterChanges() {
// Create a managed application in the principal-cluster and ensure it is deployed into managed-cluster
app := createApp(suite.Ctx, suite.PrincipalClient, requires)
principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}
app = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient, principalKey, agentKey, requires)

// Case 1: Modify the application directly in the managed-cluster,
Expand Down Expand Up @@ -103,7 +103,7 @@ func (suite *CacheTestSuite) Test_RevertDisconnectedManagedClusterChanges() {
// Create a managed application in the principal-cluster and ensure it is deployed into managed-cluster
app := createApp(suite.Ctx, suite.PrincipalClient, requires)
principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}
app = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient, principalKey, agentKey, requires)

// Case 1: Agent is disconnected with principal, now modify the application directly in the managed-cluster,
Expand Down Expand Up @@ -133,7 +133,7 @@ func (suite *CacheTestSuite) Test_CacheRecreatedOnRestart() {
// Create a managed application in the principal-cluster and ensure it is deployed into managed-cluster
app := createApp(suite.Ctx, suite.PrincipalClient, requires)
principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}
app = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient, principalKey, agentKey, requires)

// Case 1: Agent is restarted, now make direct changes in the managed-cluster,
Expand All @@ -158,7 +158,7 @@ func (suite *CacheTestSuite) Test_RevertManagedClusterOfflineChanges() {
// Create a managed application in the principal-cluster and ensure it is deployed into managed-cluster
app := createApp(suite.Ctx, suite.PrincipalClient, requires)
principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}
app = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient, principalKey, agentKey, requires)

// Agent in not running, but still make changes in the managed-cluster application manifest.
Expand Down Expand Up @@ -268,14 +268,14 @@ func (suite *CacheTestSuite) Test_RevertManagedAppDeletion() {
// Create a managed application in the principal-cluster and ensure it is deployed into managed-cluster
app := createApp(suite.Ctx, suite.PrincipalClient, requires)
principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}
app = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient, principalKey, agentKey, requires)

t.Log("Delete application directly from managed agent")
requires.NoError(suite.ManagedAgentClient.Delete(suite.Ctx, &argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: app.Name,
Namespace: fixture.ManagedAgentNamespace,
Namespace: fixture.ManagedAgentAppNamespace(),
},
}, metav1.DeleteOptions{}))

Expand Down Expand Up @@ -468,7 +468,7 @@ func createApp(ctx context.Context, client fixture.KubeClient, requires *require
app := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: fixture.AgentManagedName,
Namespace: fixture.ManagedPrincipalAppNamespace(),
},
Spec: argoapp.ApplicationSpec{
Project: "default",
Expand All @@ -477,10 +477,7 @@ func createApp(ctx context.Context, client fixture.KubeClient, requires *require
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Server: fixture.AgentClusterServerURL,
Namespace: namespace,
},
Destination: fixture.ManagedDestination(namespace),
SyncPolicy: &argoapp.SyncPolicy{
SyncOptions: argoapp.SyncOptions{
"CreateNamespace=true",
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/appproject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func (suite *AppProjectTestSuite) Test_AppProject_Managed() {
requires.Equal("in-cluster", mappProject.Spec.Destinations[0].Name)
requires.Equal("https://kubernetes.default.svc", mappProject.Spec.Destinations[0].Server)

requires.Nil(mappProject.Spec.SourceNamespaces)
if fixture.IsDestinationBased() {
requires.Equal(appProject.Spec.SourceNamespaces, mappProject.Spec.SourceNamespaces)
} else {
requires.Nil(mappProject.Spec.SourceNamespaces)
}

// Modify the appProject on the principal and ensure the change is propagated
// to the managed-agent
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (suite *BasicTestSuite) Test_AgentManaged() {
app := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook",
Namespace: "agent-managed",
Namespace: fixture.ManagedPrincipalAppNamespace(),
},
Spec: argoapp.ApplicationSpec{
Project: "default",
Expand All @@ -46,10 +46,7 @@ func (suite *BasicTestSuite) Test_AgentManaged() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: argoapp.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "guestbook",
},
Destination: fixture.ManagedDestination("guestbook"),
SyncPolicy: &argoapp.SyncPolicy{
SyncOptions: argoapp.SyncOptions{
"CreateNamespace=true",
Expand All @@ -61,7 +58,7 @@ func (suite *BasicTestSuite) Test_AgentManaged() {
requires.NoError(err)

principalKey := fixture.ToNamespacedName(&app)
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentNamespace}
agentKey := types.NamespacedName{Name: app.Name, Namespace: fixture.ManagedAgentAppNamespace()}

// Ensure the app has been pushed to the managed-agent
requires.Eventually(func() bool {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/clusterinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
// Create the first application in the principal cluster and validate deployment to managed cluster
appFirst := createApp(suite.Ctx, suite.PrincipalClient, requires)
appFirst = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient,
fixture.ToNamespacedName(&appFirst), types.NamespacedName{Name: appFirst.Name, Namespace: fixture.ManagedAgentNamespace}, requires)
fixture.ToNamespacedName(&appFirst), types.NamespacedName{Name: appFirst.Name, Namespace: fixture.ManagedAgentAppNamespace()}, requires)

// Step 2:
// Verify that cluster cache info has been updated for first application in agent cluster by Argo CD
Expand All @@ -186,7 +186,7 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
// Create the second application having different name and namespace, also validate deployment to managed cluster
appSecond := createApp(suite.Ctx, suite.PrincipalClient, requires, struct{ Name, Namespace string }{Name: "guestbook1", Namespace: "guestbook1"})
appSecond = validateManagedAppCreated(suite.Ctx, suite.ManagedAgentClient, suite.PrincipalClient,
fixture.ToNamespacedName(&appSecond), types.NamespacedName{Name: appSecond.Name, Namespace: fixture.ManagedAgentNamespace}, requires)
fixture.ToNamespacedName(&appSecond), types.NamespacedName{Name: appSecond.Name, Namespace: fixture.ManagedAgentAppNamespace()}, requires)

// Step 4:
// Verify that cluster cache info has been updated by Argo CD for second application in agent cluster
Expand All @@ -206,7 +206,7 @@ func (suite *ClusterInfoTestSuite) Test_ClusterCacheInfo() {
requires.Eventually(func() bool {
app := argoapp.Application{}
return errors.IsNotFound(suite.ManagedAgentClient.Get(suite.Ctx,
types.NamespacedName{Name: appFirst.Name, Namespace: fixture.ManagedAgentNamespace}, &app, metav1.GetOptions{}))
types.NamespacedName{Name: appFirst.Name, Namespace: fixture.ManagedAgentAppNamespace()}, &app, metav1.GetOptions{}))
}, 60*time.Second, 2*time.Second)

// Step 6:
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (suite *DeleteTestSuite) Test_CascadeDeleteOnManagedAgent() {
appOnPrincipal := v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app",
Namespace: "agent-managed",
Namespace: fixture.ManagedPrincipalAppNamespace(),
},
Spec: v1alpha1.ApplicationSpec{
Project: "default",
Expand All @@ -50,10 +50,7 @@ func (suite *DeleteTestSuite) Test_CascadeDeleteOnManagedAgent() {
TargetRevision: "HEAD",
Path: "kustomize-guestbook",
},
Destination: v1alpha1.ApplicationDestination{
Name: "agent-managed",
Namespace: "guestbook",
},
Destination: fixture.ManagedDestination("guestbook"),
SyncPolicy: &v1alpha1.SyncPolicy{
Automated: &v1alpha1.SyncPolicyAutomated{},
SyncOptions: v1alpha1.SyncOptions{
Expand Down Expand Up @@ -109,7 +106,7 @@ func (suite *DeleteTestSuite) Test_CascadeDeleteOnManagedAgent() {
app := argoapp.Application{
ObjectMeta: metav1.ObjectMeta{
Name: appOnPrincipal.Name,
Namespace: fixture.ManagedAgentNamespace,
Namespace: fixture.ManagedAgentAppNamespace(),
},
}
err := suite.ManagedAgentClient.Get(suite.Ctx, fixture.ToNamespacedName(&app), &app, metav1.GetOptions{})
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/dest_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type DestinationMappingTestSuite struct {

// SetupSuite runs before the tests in the suite are run.
func (suite *DestinationMappingTestSuite) SetupSuite() {
if fixture.IsDestinationBased() {
suite.T().Skip("DestinationMappingTestSuite is redundant when all suites already run in destination-based mode")
}
suite.BaseSuite.SetupSuite()
var err error

Expand Down
Loading
Loading