forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revisions info reporting with multi-sourced apps support (#333)
* event-reporter: added utils methods to retrieve revisions metadata for application * event-reporter: report all revisions metadata instead single to support multisourced apps * event-reporter: added revision sha to reported value in anotations - "app.meta.revisions-metadata" * event-reporter: added change revisions sha to reported value in anotations - app.meta.revisions-metadata * event-reporter: updated changelog * event-reporter: changes to anotations repoting - app.meta.revisions-metadata, report only revision in case of helm chart * event-reporter: changes after pr review * event-reporter: fixed unit tests * event-reporter: fix lint issues * event-reporter: changes after pr reviev, fixing typo, added dedicated func a.Spec.IsHelmSource(idx), removed legacy code * event-reporter: refactoring of getApplicationLegacyRevisionDetails method * event-reporter / app_revision_test.go: added some tests to AddCommitsDetailsToAnnotations, AddCommitsDetailsToAppAnnotations, getRevisions, getOperationSyncRevisions * event-reporter / app_revision_test.go: added tests for GetRevisionsDetails method * event-reporter: updated app client to support sourceIndex param in non-grpc mode * event-reporter / app_revision.go: added sourceIndex param to applicationServiceClient.RevisionMetadata in order to properly support multisourced apps * event-reporter: lint fix * event-reporter: fix lint issues * event-reporter: fix lint issues * event-reporter: added back regacy logic with setting of commit details to labels as new runtimes should work on old on-prem versions * event-reporter: added condition to not send empty array for ChangeRevisions metadata --------- Co-authored-by: pashakostohrys <[email protected]>
- Loading branch information
1 parent
288e7d3
commit 66e1e38
Showing
11 changed files
with
763 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
### Features | ||
- fix: change revision controller should verify that revision already exists | ||
- feat: event-reporter: report change revisions metadata in app annotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package reporter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/argoproj/argo-cd/v2/event_reporter/application/mocks" | ||
"github.com/argoproj/argo-cd/v2/event_reporter/metrics" | ||
"github.com/argoproj/argo-cd/v2/event_reporter/utils" | ||
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application" | ||
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||
"github.com/argoproj/argo-cd/v2/server/cache" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestGetRevisionsDetails(t *testing.T) { | ||
t.Run("should return revisions for single source app", func(t *testing.T) { | ||
expectedRevision := "expected-revision" | ||
expectedResult := []*utils.RevisionWithMetadata{{ | ||
Revision: expectedRevision, | ||
Metadata: &v1alpha1.RevisionMetadata{ | ||
Author: "Test Author", | ||
Message: "first commit", | ||
}, | ||
}} | ||
|
||
app := v1alpha1.Application{ | ||
Spec: v1alpha1.ApplicationSpec{ | ||
Source: &v1alpha1.ApplicationSource{ | ||
RepoURL: "https://my-site.com", | ||
TargetRevision: "HEAD", | ||
Path: ".", | ||
}, | ||
}, | ||
} | ||
|
||
appServiceClient := mocks.NewApplicationClient(t) | ||
project := app.Spec.GetProject() | ||
sourceIdx1 := int32(0) | ||
|
||
appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ | ||
Name: &app.Name, | ||
AppNamespace: &app.Namespace, | ||
Revision: &expectedResult[0].Revision, | ||
Project: &project, | ||
SourceIndex: &sourceIdx1, | ||
}).Return(expectedResult[0].Metadata, nil) | ||
|
||
reporter := &applicationEventReporter{ | ||
&cache.Cache{}, | ||
&MockCodefreshClient{}, | ||
newAppLister(), | ||
appServiceClient, | ||
&metrics.MetricsServer{}, | ||
} | ||
|
||
result, _ := reporter.getRevisionsDetails(context.Background(), &app, []string{expectedRevision}) | ||
|
||
assert.Equal(t, expectedResult, result) | ||
}) | ||
|
||
t.Run("should return revisions for multi sourced apps", func(t *testing.T) { | ||
expectedRevision1 := "expected-revision-1" | ||
expectedRevision2 := "expected-revision-2" | ||
expectedResult := []*utils.RevisionWithMetadata{{ | ||
Revision: expectedRevision1, | ||
Metadata: &v1alpha1.RevisionMetadata{ | ||
Author: "Repo1 Author", | ||
Message: "first commit repo 1", | ||
}, | ||
}, { | ||
Revision: expectedRevision2, | ||
Metadata: &v1alpha1.RevisionMetadata{ | ||
Author: "Repo2 Author", | ||
Message: "first commit repo 2", | ||
}, | ||
}} | ||
|
||
app := v1alpha1.Application{ | ||
Spec: v1alpha1.ApplicationSpec{ | ||
Sources: []v1alpha1.ApplicationSource{{ | ||
RepoURL: "https://my-site.com/repo-1", | ||
TargetRevision: "branch1", | ||
Path: ".", | ||
}, { | ||
RepoURL: "https://my-site.com/repo-2", | ||
TargetRevision: "branch2", | ||
Path: ".", | ||
}}, | ||
}, | ||
} | ||
|
||
project := app.Spec.GetProject() | ||
|
||
appServiceClient := mocks.NewApplicationClient(t) | ||
sourceIdx1 := int32(0) | ||
sourceIdx2 := int32(1) | ||
appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ | ||
Name: &app.Name, | ||
AppNamespace: &app.Namespace, | ||
Revision: &expectedRevision1, | ||
Project: &project, | ||
SourceIndex: &sourceIdx1, | ||
}).Return(expectedResult[0].Metadata, nil) | ||
appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ | ||
Name: &app.Name, | ||
AppNamespace: &app.Namespace, | ||
Revision: &expectedRevision2, | ||
Project: &project, | ||
SourceIndex: &sourceIdx2, | ||
}).Return(expectedResult[1].Metadata, nil) | ||
|
||
reporter := &applicationEventReporter{ | ||
&cache.Cache{}, | ||
&MockCodefreshClient{}, | ||
newAppLister(), | ||
appServiceClient, | ||
&metrics.MetricsServer{}, | ||
} | ||
|
||
result, _ := reporter.getRevisionsDetails(context.Background(), &app, []string{expectedRevision1, expectedRevision2}) | ||
|
||
assert.Equal(t, expectedResult, result) | ||
}) | ||
|
||
t.Run("should return only revision because of helm single source app", func(t *testing.T) { | ||
expectedRevision := "expected-revision" | ||
expectedResult := []*utils.RevisionWithMetadata{{ | ||
Revision: expectedRevision, | ||
}} | ||
|
||
app := v1alpha1.Application{ | ||
Spec: v1alpha1.ApplicationSpec{ | ||
Source: &v1alpha1.ApplicationSource{ | ||
RepoURL: "https://my-site.com", | ||
TargetRevision: "HEAD", | ||
Path: ".", | ||
}, | ||
}, | ||
} | ||
|
||
appServiceClient := mocks.NewApplicationClient(t) | ||
project := app.Spec.GetProject() | ||
sourceIdx1 := int32(0) | ||
|
||
appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ | ||
Name: &app.Name, | ||
AppNamespace: &app.Namespace, | ||
Revision: &expectedResult[0].Revision, | ||
Project: &project, | ||
SourceIndex: &sourceIdx1, | ||
}).Return(expectedResult[0].Metadata, nil) | ||
|
||
reporter := &applicationEventReporter{ | ||
&cache.Cache{}, | ||
&MockCodefreshClient{}, | ||
newAppLister(), | ||
appServiceClient, | ||
&metrics.MetricsServer{}, | ||
} | ||
|
||
result, _ := reporter.getRevisionsDetails(context.Background(), &app, []string{expectedRevision}) | ||
|
||
assert.Equal(t, expectedResult, result) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.