Skip to content

Commit 389d443

Browse files
ppapapetrou76oleksandr-codefreshreggie-knitishfyandrii-korotkov-verkada
authored
chore: sync our fork to 3.1.5 sync branch (#428)
* chore: sync all codefresh code changes into v3.0.2 (#397) * chore: sync all codefresh code changes into v3.0.2 without event-reporter related changes Signed-off-by: oleksandr-codefresh <[email protected]> * removed cf script Signed-off-by: oleksandr-codefresh <[email protected]> * upgraded git-lfs to 3.6.1 in Dockerfile (#386) Signed-off-by: reggie-k <[email protected]> Signed-off-by: oleksandr-codefresh <[email protected]> * fixed webstorm go.mod issue Signed-off-by: oleksandr-codefresh <[email protected]> * e2e: improved error logs Signed-off-by: oleksandr-codefresh <[email protected]> * fixed changes on generated files Signed-off-by: oleksandr-codefresh <[email protected]> * chore: replace heptio-images with argocd-e2e-container (argoproj#23040) Signed-off-by: nitishfy <[email protected]> Signed-off-by: Nitish Kumar <[email protected]> (cherry picked from commit 309acd1) Signed-off-by: oleksandr-codefresh <[email protected]> * feat: upgraded github.com/expr-lang/expr from 0.16.9 to 0.17.0 Signed-off-by: oleksandr-codefresh <[email protected]> * e2e [TestTrackAppStateAndSyncApp / TestNewStyleResourceActionMixedOk / TestNewStyleResourceActionPermitted / TestNamespacedPermissions]: added wait for sync operation Signed-off-by: oleksandr-codefresh <[email protected]> --------- Signed-off-by: oleksandr-codefresh <[email protected]> Signed-off-by: reggie-k <[email protected]> Co-authored-by: Regina Voloshin <[email protected]> Co-authored-by: Nitish Kumar <[email protected]> # Conflicts: # .github/workflows/ci-build.yaml # cmd/argocd/commands/app_test.go # go.mod # go.sum # manifests/base/kustomization.yaml # manifests/core-install-with-hydrator.yaml # manifests/core-install.yaml # manifests/core-install/kustomization.yaml # manifests/ha/base/kustomization.yaml # manifests/ha/install-with-hydrator.yaml # manifests/ha/install.yaml # manifests/ha/namespace-install-with-hydrator.yaml # manifests/ha/namespace-install.yaml # manifests/install-with-hydrator.yaml # manifests/install.yaml # manifests/namespace-install-with-hydrator.yaml # manifests/namespace-install.yaml # pkg/apiclient/application/application.pb.go # pkg/apiclient/application/application.pb.gw.go # pkg/apis/application/v1alpha1/generated.pb.go # reposerver/apiclient/mocks/RepoServerServiceClient.go # reposerver/apiclient/repository.pb.go # server/application/application.proto # util/git/mocks/Client.go * fix(validateDestination query): as we moved to argo.GetDestinationCluster, we can simply rely on error returned from this request (#405) Signed-off-by: oleksandr-codefresh <[email protected]> * removed curl from image (#406) Signed-off-by: reggie-k <[email protected]> * feat: Add GitHub API metrics (#404) * added github api metrics Signed-off-by: reggie-k <[email protected]> * fix(docs): fix applicationsetcontroller.enable.github.api.metrics to false in docs cm (argoproj#23516) Signed-off-by: reggie-k <[email protected]> * fix: Account for batch event processing in e2e tests (argoproj#22356) Signed-off-by: Andrii Korotkov <[email protected]> --------- Signed-off-by: reggie-k <[email protected]> Signed-off-by: Andrii Korotkov <[email protected]> Co-authored-by: Andrii Korotkov <[email protected]> * cherry-pick 1b48f36 Upgrade ubuntu base image to latest 25.04 digest (#407) Signed-off-by: reggie-k <[email protected]> Co-authored-by: dudinea <[email protected]> * feat: CR-29912 manual cherry pick app set pr generator return 0 results if the repo does not exist (#409) * manually added the changes Signed-off-by: reggie-k <[email protected]> * pull request functionality Signed-off-by: reggie-k <[email protected]> * pull request functionality Signed-off-by: reggie-k <[email protected]> --------- Signed-off-by: reggie-k <[email protected]> * feat: move pkg/exec in-tree and add fatal timeout upgrade with SIGKILL to ARGO_EXEC_TIMEOUT (#419) * chore: move pkg/exec in-tree (argoproj#22175) (argoproj#22460) Signed-off-by: Michael Crenshaw <[email protected]> * fix: add fatal timeout upgrade with SIGKILL to ARGO_EXEC_TIMEOUT (closes argoproj#20785, argoproj#18478) (argoproj#22713) Signed-off-by: Hazel Sudzilouski <[email protected]> Signed-off-by: Alexandre Gaudreault <[email protected]> Co-authored-by: Alexandre Gaudreault <[email protected]> --------- Signed-off-by: Michael Crenshaw <[email protected]> Signed-off-by: Hazel Sudzilouski <[email protected]> Signed-off-by: Alexandre Gaudreault <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]> Co-authored-by: Hazel Sudzilouski <[email protected]> Co-authored-by: Alexandre Gaudreault <[email protected]> * feat: CR-30512 stop using bitnami images (#420) * removed references from all the images except for astra healthcheck Signed-off-by: reggie-k <[email protected]> * removed reposerver/repository/testdata/helm-with-local-dependency/.argocd-helm-dep-up Signed-off-by: reggie-k <[email protected]> * reverted health check references since they are treated as text Signed-off-by: reggie-k <[email protected]> * reverted health check references since they are treated as text Signed-off-by: reggie-k <[email protected]> --------- Signed-off-by: reggie-k <[email protected]> * chore: bumps redis to 8.x (#422) * bumps Docker test container to redis 8 * bumps redis version to 8.2.1 Signed-off-by: Patroklos Papapetrou <[email protected]> * use a previous version of go-redis Signed-off-by: Patroklos Papapetrou <[email protected]> --------- Signed-off-by: Patroklos Papapetrou <[email protected]> * upgrade sqlite in docker image to address CVE-2025-6965 (#425) * final changes after rebase Signed-off-by: Patroklos Papapetrou <[email protected]> * final changes after rebase Signed-off-by: Patroklos Papapetrou <[email protected]> * address new linter issues Signed-off-by: Patroklos Papapetrou <[email protected]> --------- Signed-off-by: oleksandr-codefresh <[email protected]> Signed-off-by: reggie-k <[email protected]> Signed-off-by: Andrii Korotkov <[email protected]> Signed-off-by: Michael Crenshaw <[email protected]> Signed-off-by: Hazel Sudzilouski <[email protected]> Signed-off-by: Alexandre Gaudreault <[email protected]> Signed-off-by: Patroklos Papapetrou <[email protected]> Co-authored-by: Oleksandr Saulyak <[email protected]> Co-authored-by: Regina Voloshin <[email protected]> Co-authored-by: Nitish Kumar <[email protected]> Co-authored-by: Andrii Korotkov <[email protected]> Co-authored-by: dudinea <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]> Co-authored-by: Hazel Sudzilouski <[email protected]> Co-authored-by: Alexandre Gaudreault <[email protected]>
1 parent cfeed49 commit 389d443

File tree

114 files changed

+8315
-2453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+8315
-2453
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ manifests/
1717
hack/
1818
docs/
1919
examples/
20+
.dockerignore
21+
.git/
2022
.github/
2123
!test/container
2224
!test/e2e/testdata

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ contact_links:
55
url: https://argo-cd.readthedocs.io/
66
about: Much help can be found in the docs
77
- name: Ask a question
8-
url: https://github.com/argoproj/argo-cd/discussions/new
8+
url: https://github.com/codefresh-io/argo-cd/discussions/new
99
about: Ask a question or start a discussion about Argo CD
1010
- name: Chat on Slack
1111
url: https://argoproj.github.io/community/join-slack

.github/workflows/ci-build.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ name: Integration tests
22
on:
33
push:
44
branches:
5-
- 'master'
6-
- 'release-*'
7-
- '!release-1.4'
8-
- '!release-1.5'
5+
- 'sync-*'
6+
# - 'master'
7+
# - 'release-*'
8+
# - '!release-1.4'
9+
# - '!release-1.5'
910
pull_request:
1011
branches:
11-
- 'master'
12-
- 'release-*'
12+
- 'sync-*'
13+
# - 'master'
14+
# - 'release-*'
1315

1416
env:
1517
# Golang version to use across CI steps
@@ -392,7 +394,7 @@ jobs:
392394
env:
393395
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
394396
- name: Upload test results to Codecov
395-
if: github.ref == 'refs/heads/master' && github.event_name == 'push' && github.repository == 'argoproj/argo-cd'
397+
if: startsWith(github.ref, 'refs/heads/sync-') && github.event_name == 'push' && github.repository == 'codefresh-io/argo-cd'
396398
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
397399
with:
398400
file: test-results/junit.xml
@@ -403,7 +405,7 @@ jobs:
403405
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
404406
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
405407
uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf # v5.2.0
406-
if: env.sonar_secret != ''
408+
if: false && env.sonar_secret != ''
407409
test-e2e:
408410
name: Run end-to-end tests
409411
if: ${{ needs.changes.outputs.backend == 'true' }}
@@ -496,7 +498,7 @@ jobs:
496498
run: |
497499
docker pull ghcr.io/dexidp/dex:v2.43.0
498500
docker pull argoproj/argo-cd-ci-builder:v1.0.0
499-
docker pull redis:7.2.7-alpine
501+
docker pull redis:8.2.1-alpine
500502
- name: Create target directory for binaries in the build-process
501503
run: |
502504
mkdir -p dist

.github/workflows/image.yaml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Image
33
on:
44
push:
55
branches:
6-
- master
6+
- sync-*
77
pull_request:
88
branches:
9-
- master
9+
- sync-*
1010
types: [labeled, unlabeled, opened, synchronize, reopened]
1111

1212
concurrency:
@@ -19,17 +19,25 @@ jobs:
1919
set-vars:
2020
permissions:
2121
contents: read
22-
if: github.repository == 'argoproj/argo-cd'
22+
if: github.repository == 'codefresh-io/argo-cd'
2323
runs-on: ubuntu-22.04
2424
outputs:
25-
image-tag: ${{ steps.image.outputs.tag}}
25+
image-tag: ${{ steps.image-pr.outputs.tag || steps.image-push.outputs.tag }}
2626
platforms: ${{ steps.platforms.outputs.platforms }}
2727
steps:
2828
- uses: actions/checkout@8410ad0602e1e429cee44a835ae9f77f654a6694 # v4.0.0
2929

30-
- name: Set image tag for ghcr
31-
run: echo "tag=$(cat ./VERSION)-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
32-
id: image
30+
- name: Set image tag (push to feature branch)
31+
if: ${{ github.repository == 'codefresh-io/argo-cd' && github.event_name == 'pull_request' }}
32+
run: |
33+
CLEAN_REF=$(echo "${{ github.head_ref }}" | sed 's|^refs/[^/]*||; s|/|_|g')
34+
echo "tag=v$(cat ./VERSION)-${CLEAN_REF}-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
35+
id: image-pr
36+
37+
- name: Set image tag (push to sync-* branch)
38+
if: ${{ github.repository == 'codefresh-io/argo-cd' && github.event_name == 'push' }}
39+
run: echo "tag=v$(cat ./VERSION)-$(date +%Y-%m-%d)-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
40+
id: image-push
3341

3442
- name: Determine image platforms to use
3543
id: platforms
@@ -48,7 +56,7 @@ jobs:
4856
contents: read
4957
packages: write # for pushing packages to GHCR, which is used by cd.apps.argoproj.io to avoid polluting Quay with tags
5058
id-token: write # for creating OIDC tokens for signing.
51-
if: ${{ github.repository == 'argoproj/argo-cd' && github.event_name != 'push' }}
59+
if: ${{ false }}
5260
uses: ./.github/workflows/image-reuse.yaml
5361
with:
5462
# Note: cannot use env variables to set go-version (https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations)
@@ -63,11 +71,11 @@ jobs:
6371
contents: read
6472
packages: write # for pushing packages to GHCR, which is used by cd.apps.argoproj.io to avoid polluting Quay with tags
6573
id-token: write # for creating OIDC tokens for signing.
66-
if: ${{ github.repository == 'argoproj/argo-cd' && github.event_name == 'push' }}
74+
if: ${{ github.repository == 'codefresh-io/argo-cd' }}
6775
uses: ./.github/workflows/image-reuse.yaml
6876
with:
69-
quay_image_name: quay.io/argoproj/argocd:latest
70-
ghcr_image_name: ghcr.io/argoproj/argo-cd/argocd:${{ needs.set-vars.outputs.image-tag }}
77+
quay_image_name: ${{ github.event_name == 'pull_request' && 'quay.io/codefresh/dev/argocd' || 'quay.io/codefresh/argocd' }}:${{ needs.set-vars.outputs.image-tag }}
78+
# ghcr_image_name: ghcr.io/codefresh-io/argo-cd/argocd:${{ needs.set-vars.outputs.image-tag }}
7179
# Note: cannot use env variables to set go-version (https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations)
7280
# renovate: datasource=golang-version packageName=golang
7381
go-version: 1.24.6
@@ -86,7 +94,7 @@ jobs:
8694
actions: read # for detecting the Github Actions environment.
8795
id-token: write # for creating OIDC tokens for signing.
8896
packages: write # for uploading attestations. (https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/container/README.md#known-issues)
89-
if: ${{ github.repository == 'argoproj/argo-cd' && github.event_name == 'push' }}
97+
if: ${{ false }}
9098
# Must be refernced by a tag. https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/container/README.md#referencing-the-slsa-generator
9199
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
92100
with:
@@ -103,7 +111,7 @@ jobs:
103111
permissions:
104112
contents: write # for git to push upgrade commit if not already deployed
105113
packages: write # for pushing packages to GHCR, which is used by cd.apps.argoproj.io to avoid polluting Quay with tags
106-
if: ${{ github.repository == 'argoproj/argo-cd' && github.event_name == 'push' }}
114+
if: ${{ false }}
107115
runs-on: ubuntu-22.04
108116
steps:
109117
- uses: actions/checkout@8410ad0602e1e429cee44a835ae9f77f654a6694 # v4.0.0

.mockery.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ template-data:
77
unroll-variadic: true
88

99
packages:
10+
github.com/argoproj/argo-cd/v3/acr_controller/application:
11+
interfaces:
12+
ApplicationClient:
1013
github.com/argoproj/argo-cd/v3/applicationset/generators:
1114
interfaces:
1215
Generator: {}

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG BASE_IMAGE=docker.io/library/ubuntu:24.04@sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab
1+
ARG BASE_IMAGE=docker.io/library/ubuntu:25.04@sha256:10bb10bb062de665d4dc3e0ea36715270ead632cfcb74d08ca2273712a0dfb42
22
####################################################################################################
33
# Builder image
44
# Initial stage which pulls prepares build dependencies and CLI tooling we need for our final image
@@ -55,6 +55,9 @@ RUN groupadd -g $ARGOCD_USER_ID argocd && \
5555
apt-get clean && \
5656
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5757

58+
# To make sure that the latesst version of sqlite is installed that addresses this CVE-2025-6965
59+
RUN apt update && apt install --only-upgrade libsqlite3-0
60+
5861
COPY hack/gpg-wrapper.sh \
5962
hack/git-verify-wrapper.sh \
6063
entrypoint.sh \
@@ -138,6 +141,7 @@ COPY --from=argocd-build /go/src/github.com/argoproj/argo-cd/dist/argocd* /usr/l
138141
USER root
139142
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server && \
140143
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server && \
144+
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-change-revision-controller && \
141145
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-cmp-server && \
142146
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller && \
143147
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex && \

Dockerfile.dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ COPY argocd /usr/local/bin/
77
USER root
88
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server && \
99
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server && \
10+
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-change-revision-controller && \
1011
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller && \
1112
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex && \
1213
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-notifications && \

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ define run-in-test-client
134134
-e GITHUB_TOKEN \
135135
-e GOCACHE=/tmp/go-build-cache \
136136
-e ARGOCD_LINT_GOGC=$(ARGOCD_LINT_GOGC) \
137+
-e GOSUMDB=off \
137138
-v ${DOCKER_SRC_MOUNT} \
138139
-v ${GOPATH}/pkg/mod:/go/pkg/mod${VOLUME_MOUNT} \
139140
-v ${GOCACHE}:/tmp/go-build-cache${VOLUME_MOUNT} \
@@ -154,7 +155,7 @@ PATH:=$(PATH):$(PWD)/hack
154155

155156
# docker image publishing options
156157
DOCKER_PUSH?=false
157-
IMAGE_NAMESPACE?=
158+
IMAGE_NAMESPACE?=quay.io/codefresh
158159
# perform static compilation
159160
DEFAULT_STATIC_BUILD:=true
160161
ifeq ($(IS_DARWIN),true)

Merge-upstream.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Process of merging upstream changes
2+
3+
1. create "sync-3.0.2" branch on top of upstream v3.0.2 tag (git checkout -b sync-3.0.2 v3.0.2), push to codefresh-io/argocd
4+
2. create branch "make-cf-changes" on current release (sync-2.14.9 HEAD)
5+
3. rebase onto sync-3.0.2 ("git rebase --onto sync-3.0.2 v2.14.9 make-cf-changes)
6+
4. make a pr from "make-cf-changes" into "sync-3.0.2".
7+
1. the pr will trigger dev image builds, e2e runs, etc (quay.io/codefresh/dev/argocd)
8+
5. fix conflicts, test, fixes, whatever (by instuction in following section)
9+
6. merge pr
10+
1. merge will create official image of fork (quay.io/codefresh/argocd)
11+
2. manually create tag "v3.0.2-YYYY-MM-DD-SHA"
12+
3. THERE IS NOT GITHUB RELEASE
13+
14+
## Resolving conflicts during upstream changes merge
15+
16+
This docs include info about places where codefresh made it's customizations:
17+
18+
#### General notes:
19+
1. All files that're deleted in our branches - we can keep deleted (accept ours).
20+
2. all `xxx.pb.go` - apply theirs and after resolving conflicts re-generate.
21+
22+
#### Paths and actions on them
23+
1. `.github/workflows` - accept ours (yours).
24+
2. `applicationset` - accept theirs
25+
3. `assets / swagger` - accept ours. Later run codegen and commit new version
26+
4. `cmd / argocd` - accept ours if files deleted.
27+
5. `cmd / argocd-application-controller` - no custom thing from our side, so just resolve conflicts.
28+
6. `cmd / notifications` - no custom thing from our side, so just accept theirs.
29+
7. `cmd / argocd-repo-server` - includes our changes with codefresh related parameters.
30+
8. `cmd / common` - includes our changes with codefresh related constants (event-reporter)
31+
9. `cmd / controller / application.go` - includes our changes to resource node (to return labels and annotations getResourceTree method)
32+
10. `cmd / controller / state.go` - includes our changes (GetRepoObjs method)
33+
11. `cmd / controller / state_test.go - includes our changes. Replace manifest values with our struct `apiclient.Manifest`
34+
12. `docs` - apply theirs
35+
13. `examples` - apply theirs
36+
14. `hack` - apply theirs
37+
15. `manifests` - accept theirs
38+
16. `notification_controller` - apply theirs
39+
17. `pkg/apis/application/v1alpha` - generatedXXX - apply theirs (than re-generate). types.go - merge (includes our changes with ForceNamespace).
40+
18. `server / application.go` - merge (includes our v1 event-reporter.)
41+
19. `ui` - accept theirs.
42+
20. `util / kustomize` - merge, as it includes ours changes.
43+
21. `mkdocs.yaml` - apply theirs.
44+
22. `go.mod` - merge direct dependencies. go.sum accept theirs. Run go mod tidy. Check `replace` section, perform cleanup if needed.
45+
23. `reposerver / sepository.go` - merge, includes: cf appVersion logic; type manifest struct (with path to file, rawManifest);
46+
47+
48+
#### Post actions:
49+
1. run `go mod tidy`
50+
2. run `go mod download`
51+
3. run `go mod vendor`
52+
4. run `make install-tools-local`
53+
5. run `make lint-local`
54+
6. run `make protogen-fast` - because sometimes gogen won't work if types from protogen used
55+
7. run `make codegen`
56+
8. run `make test-local`
57+
58+
### Thoughts
59+
60+
1. Revert cherry picks before merges - as they cause issues later if in upstream decided to slightly move some parts of such changes. In this case no conflicts will occur during merge as they on different lines but then you need cleanup them manually.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package application_change_revision_controller
2+
3+
import (
4+
"context"
5+
"crypto/tls"
6+
"encoding/json"
7+
"fmt"
8+
"io"
9+
"net/http"
10+
"strings"
11+
"time"
12+
13+
"google.golang.org/grpc"
14+
15+
appclient "github.com/argoproj/argo-cd/v3/pkg/apiclient/application"
16+
)
17+
18+
type ApplicationClient interface {
19+
GetChangeRevision(ctx context.Context, in *appclient.ChangeRevisionRequest, opts ...grpc.CallOption) (*appclient.ChangeRevisionResponse, error)
20+
}
21+
22+
type httpApplicationClient struct {
23+
httpClient *http.Client
24+
baseURL string
25+
token string
26+
}
27+
28+
func NewHTTPApplicationClient(token string, address string, rootpath string) ApplicationClient {
29+
if rootpath != "" && !strings.HasPrefix(rootpath, "/") {
30+
rootpath = "/" + rootpath
31+
}
32+
33+
if !strings.Contains(address, "http") {
34+
address = "http://" + address
35+
}
36+
37+
if rootpath != "" {
38+
address = address + rootpath
39+
}
40+
41+
return &httpApplicationClient{
42+
httpClient: &http.Client{
43+
Timeout: 30 * time.Second,
44+
Transport: &http.Transport{
45+
// Support for insecure connections
46+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
47+
},
48+
},
49+
baseURL: address,
50+
token: token,
51+
}
52+
}
53+
54+
func (c *httpApplicationClient) execute(ctx context.Context, url string, result any) error {
55+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
56+
if err != nil {
57+
return err
58+
}
59+
60+
req.Header.Set("Content-Type", "application/json")
61+
req.Header.Set("Authorization", "Bearer "+c.token)
62+
63+
res, err := c.httpClient.Do(req)
64+
if err != nil {
65+
return err
66+
}
67+
defer res.Body.Close()
68+
69+
b, _ := io.ReadAll(res.Body)
70+
71+
isStatusOK := res.StatusCode >= 200 && res.StatusCode < 300
72+
if !isStatusOK {
73+
return fmt.Errorf("argocd server respond with code %d, msg is: %s", res.StatusCode, string(b))
74+
}
75+
76+
err = json.Unmarshal(b, &result)
77+
if err != nil {
78+
return err
79+
}
80+
return nil
81+
}
82+
83+
func (c *httpApplicationClient) GetChangeRevision(ctx context.Context, in *appclient.ChangeRevisionRequest, _ ...grpc.CallOption) (*appclient.ChangeRevisionResponse, error) {
84+
params := fmt.Sprintf("?appName=%s&namespace=%s&currentRevision=%s&previousRevision=%s", in.GetAppName(), in.GetNamespace(), in.GetCurrentRevision(), in.GetPreviousRevision())
85+
86+
url := fmt.Sprintf("%s/api/v1/application/changeRevision%s", c.baseURL, params)
87+
88+
changeRevisionResponse := &appclient.ChangeRevisionResponse{}
89+
err := c.execute(ctx, url, changeRevisionResponse)
90+
if err != nil {
91+
return nil, err
92+
}
93+
return changeRevisionResponse, nil
94+
}

0 commit comments

Comments
 (0)