forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: reporter uses sources-server #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fe72abd
reporter - sources-server
andrii-codefresh 0789fa1
whitespaces
andrii-codefresh 0c01daa
remove marker
andrii-codefresh 612d43c
don't use sources-server as a package
andrii-codefresh d944d2b
go.sum
andrii-codefresh 4d922ea
fix tests
andrii-codefresh 1358037
fix linter
andrii-codefresh fed1b91
fix linter
andrii-codefresh 7e0de8d
fix linter
andrii-codefresh 3f2161f
fix linter
andrii-codefresh 139c1e1
Merge remote-tracking branch 'origin/release-2.12' into CR-26144-sour…
andrii-codefresh 4620576
revisions
andrii-codefresh c06ce89
use the first
andrii-codefresh fc0addc
fix PR comments
andrii-codefresh 0a0f837
Merge remote-tracking branch 'origin/release-2.12' into CR-26144-sour…
andrii-codefresh 8e0541f
merge branch
andrii-codefresh a5359e4
Revert "merge branch"
andrii-codefresh 6bbadea
fix linter
andrii-codefresh 280a4f4
add logs
andrii-codefresh 4bc9ba6
Merge remote-tracking branch 'origin/release-2.12' into CR-26144-sour…
andrii-codefresh cd32a7d
CHANGELOG.md
andrii-codefresh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||
| - feat(event-reporter): multisourced apps support improvements: reporting syncOperationRevisions, detecting correct resource sourceIdx, reporting correct git commit info | ||
| - feat(event-reporter): using sources-server for getting application version |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,108 @@ | ||
| package sources_server_client | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| netUrl "net/url" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||
| ) | ||
|
|
||
| type VersionPayload struct { | ||
| App v1alpha1.Application `json:"app"` | ||
| Revision string `json:"revision"` | ||
| } | ||
|
|
||
| type DependenciesMap struct { | ||
| Lock string `json:"helm/Chart.lock"` | ||
| Deps string `json:"helm/dependencies"` | ||
| Requirements string `json:"helm/requirements.yaml"` | ||
| } | ||
|
|
||
| type AppVersionResult struct { | ||
| AppVersion string `json:"appVersion"` | ||
| Dependencies DependenciesMap `json:"dependencies"` | ||
| } | ||
|
|
||
| type SourcesServerConfig struct { | ||
| BaseURL string | ||
| } | ||
|
|
||
| type sourceServerClient struct { | ||
| clientConfig *SourcesServerConfig | ||
| } | ||
|
|
||
| type SourceServerClientInteface interface { | ||
| GetAppVersion(app *v1alpha1.Application, revision *string) *AppVersionResult | ||
| } | ||
|
|
||
| func (c *sourceServerClient) sendRequest(method, url string, payload interface{}) ([]byte, error) { | ||
oleksandr-codefresh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var requestBody []byte | ||
| var err error | ||
| if payload != nil { | ||
| requestBody, err = json.Marshal(payload) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error marshalling payload: %w", err) | ||
| } | ||
| } | ||
|
|
||
| fullURL, err := netUrl.JoinPath(c.clientConfig.BaseURL, url) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error joining path: %w", err) | ||
| } | ||
|
|
||
| req, err := http.NewRequest(method, fullURL, bytes.NewBuffer(requestBody)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating request: %w", err) | ||
| } | ||
|
|
||
| req.Header.Set("Content-Type", "application/json") | ||
|
|
||
| client := &http.Client{} | ||
| resp, err := client.Do(req) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error making request: %w", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode < 200 || resp.StatusCode >= 300 { | ||
| body, _ := io.ReadAll(resp.Body) | ||
| return nil, fmt.Errorf("server responded with status %d: %s", resp.StatusCode, string(body)) | ||
| } | ||
|
|
||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error reading response body: %w", err) | ||
| } | ||
|
|
||
| return body, nil | ||
| } | ||
|
|
||
| func (c *sourceServerClient) GetAppVersion(app *v1alpha1.Application, revision *string) *AppVersionResult { | ||
| log.Infof("cfGetAppVersion. Sending request to sources-server for %s", app.Name) | ||
| appVersionResult, err := c.sendRequest("POST", "/getAppVersion", VersionPayload{App: *app, Revision: *revision}) | ||
| if err != nil { | ||
| log.Errorf("error getting app version: %v", err) | ||
| return nil | ||
| } | ||
|
|
||
| var versionStruct AppVersionResult | ||
| err = json.Unmarshal(appVersionResult, &versionStruct) | ||
| if err != nil { | ||
| log.Errorf("error unmarshaling app version: %v", err) | ||
| return nil | ||
| } | ||
|
|
||
| return &versionStruct | ||
| } | ||
|
|
||
| func NewSourceServerClient(clientConfig *SourcesServerConfig) SourceServerClientInteface { | ||
| return &sourceServerClient{ | ||
| clientConfig: clientConfig, | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.