Skip to content
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

fix(repo-server): excess git requests, short-circuit GenerateManifests ref only (Issue #14725) #1

Open
wants to merge 38 commits into
base: lsremote-part1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cbe6e2b
chore(deps): bump github.com/go-jose/go-jose/v3 from 3.0.0 to 3.0.1 (…
dependabot[bot] Nov 22, 2023
78460c4
chore: Bump otel to 1.21.0 (#16420)
dlorenc Nov 22, 2023
1600c03
chore: Update USERS.md (#16425)
seniorquico Nov 22, 2023
2f2958a
fix: fixed cli admin dashboard cmd (#16430)
gdsoumya Nov 27, 2023
11df990
feat(opentelemetry): :sparkles: support for secured OTLP endpoint and…
prashant-shahi Nov 27, 2023
0cb9980
Renamed/corrected OCI proposal filename (#16452)
sabre1041 Nov 27, 2023
b34e587
fix(ui): User Info blob is too far to the right relative to Applicati…
shijiadong2022 Nov 28, 2023
820f4d8
feat(server): log app Spec along with event (#16416)
nandinisingh759 Nov 28, 2023
0c21ef9
fix: upgrade notifications-engine (#16354)
GilUpstream Nov 29, 2023
23f2767
fix(cli): pass redis compression to cluster stats and shards commands…
phanama Nov 29, 2023
4875b02
fix(controller): Address diff cache miss issues (#16458)
leoluz Nov 29, 2023
c602302
fix PerconaXtraDBCluster health (#16434)
filiprafaj Nov 30, 2023
8070725
feat(cli): Added example to admin-cluster.go and projectwindow.go fil…
surajyadav1108 Nov 30, 2023
9e92f55
fix(ui): add exec check to avoid API calls (#16168)
ashutosh16 Nov 30, 2023
673d661
Fix extra space in application tree pod group (#16358)
ashinsabu3 Nov 30, 2023
5c187a1
fix(repo-server): excess git requests, resolveReferencedSources and r…
nromriell Nov 30, 2023
27e927b
chore(deps): bump cosign-installer from 3.1.2 to 3.2.0 (#16495)
crenshaw-dev Nov 30, 2023
19fa5b9
feat: Argocd notification self service (#16488)
mayzhang2000 Nov 30, 2023
8656585
fix: Tooltips point in wrong direction#11935 (#12578)
JessieTeng89 Dec 1, 2023
a08c573
feat(appset): Advanced Templating using templatePatch (#14893)
speedfl Dec 1, 2023
017b08a
feat(ui): Add sourceNamespaces in Projects UI and only show it if App…
jdvgh Dec 1, 2023
7408292
fix(appset): Don't use revision cache when reconciling after webhook …
dhruvang1 Dec 4, 2023
30b92b2
fix(doc): Fix documentation templatePatch (#16522)
speedfl Dec 4, 2023
8886874
fix: cert-manager.io/certificate health.lua for consistent issuing (I…
chr15murray Dec 4, 2023
99c2859
fix: Use math.MaxInt (instead of math.MaxInt64) to fix builds on 32bi…
ondrejsika Dec 4, 2023
7484f1d
Added missing 'alias:' prefix for repository name as described here: …
ffppmm Dec 5, 2023
5c51dcb
fix(ui): use background delete to match k8s terminology (#15579)
jsoref Dec 5, 2023
07a2e64
docs: Fix format issue in rbac.md (#16521)
elouanKeryell-Even Dec 5, 2023
86f79ec
docs: Fix minor typo in Declarative Setup (#16550)
philnichol Dec 6, 2023
710777e
chore: update PR template to suggest cherry-pick releases (#16560)
jessesuen Dec 6, 2023
35f1ee7
resource_customizations/db.atlasgo.io: atlas operator resources (#16364)
rotemtam Dec 7, 2023
9179835
fix(appset): Always remove ownerReferences when appset policy doesn't…
mikutas Dec 8, 2023
f67dcac
docs: Add Kong Inc. as a user (#16582)
reversearrow Dec 8, 2023
a761a49
chore: upgrade kubernetes dependencies from 0.26.4 to 0.26.11 (#16581)
reegnz Dec 8, 2023
10bb8b0
docs: fix broken link in secret-management.md (#16588)
elouanKeryell-Even Dec 11, 2023
c46f5aa
fix(repo-server): excess git requests part 2, short-circuit GenerateM…
nromriell Dec 1, 2023
4e84097
chore(logging): pr feedback, add debug log to short circuit
nromriell Dec 5, 2023
6e08acf
chore: pr feedback, add ref to debug statement
nromriell Dec 12, 2023
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
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ Checklist:
* [ ] I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
* [ ] Does this PR require documentation updates?
* [ ] I've updated documentation as required by this PR.
* [ ] Optional. My organization is added to USERS.md.
* [ ] I have signed off all my commits as required by [DCO](https://github.com/argoproj/argoproj/blob/master/community/CONTRIBUTING.md#legal)
* [ ] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
* [ ] My build is green ([troubleshooting builds](https://argo-cd.readthedocs.io/en/latest/developer-guide/ci/)).
* [ ] My new feature complies with the [feature status](https://github.com/argoproj/argoproj/blob/master/community/feature-status.md) guidelines.
* [ ] I have added a brief description of why this PR is necessary and/or what this PR solves.
* [ ] Optional. My organization is added to USERS.md.
* [ ] Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

<!-- Please see [Contribution FAQs](https://argo-cd.readthedocs.io/en/latest/developer-guide/faq/) if you have questions about your pull-request. -->
7 changes: 6 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ jobs:

# CodeQL runs on ubuntu-latest and windows-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

# Use correct go version. https://github.com/github/codeql-action/issues/1842#issuecomment-1704398087
- name: Setup Golang
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.0.0
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/image-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ jobs:
go-version: ${{ inputs.go-version }}

- name: Install cosign
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2
uses: sigstore/cosign-installer@1fc5bd396d372bee37d608f955b336615edf79c8 # v3.2.0
with:
cosign-release: 'v2.0.2'
cosign-release: 'v2.2.1'

- uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
Expand Down
3 changes: 2 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ git-server: test/fixture/testrepos/start-git.sh
helm-registry: test/fixture/testrepos/start-helm-registry.sh
dev-mounter: [[ "$ARGOCD_E2E_TEST" != "true" ]] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source}
applicationset-controller: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-applicationset-controller $COMMAND --loglevel debug --metrics-addr localhost:12345 --probe-addr localhost:12346 --argocd-repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}"
notification: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_BINARY_NAME=argocd-notifications $COMMAND --loglevel debug"
notification: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_BINARY_NAME=argocd-notifications $COMMAND --loglevel debug --application-namespaces=${ARGOCD_APPLICATION_NAMESPACES:-''} --self-service-notification-enabled=${ARGOCD_NOTIFICATION_CONTROLLER_SELF_SERVICE_NOTIFICATION_ENABLED:-'false'}"

2 changes: 2 additions & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [Kinguin](https://www.kinguin.net/)
1. [KintoHub](https://www.kintohub.com/)
1. [KompiTech GmbH](https://www.kompitech.com/)
1. [Kong Inc.](https://konghq.com/)
1. [KPMG](https://kpmg.com/uk)
1. [KubeSphere](https://github.com/kubesphere)
1. [Kurly](https://www.kurly.com/)
Expand Down Expand Up @@ -243,6 +244,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [Robotinfra](https://www.robotinfra.com)
1. [Rubin Observatory](https://www.lsst.org)
1. [Saildrone](https://www.saildrone.com/)
1. [Salad Technologies](https://salad.com/)
1. [Saloodo! GmbH](https://www.saloodo.com)
1. [Sap Labs](http://sap.com)
1. [Sauce Labs](https://saucelabs.com/)
Expand Down
49 changes: 39 additions & 10 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// Do not attempt to further reconcile the ApplicationSet if it is being deleted.
if applicationSetInfo.ObjectMeta.DeletionTimestamp != nil {
if controllerutil.ContainsFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName) {
deleteAllowed := utils.DefaultPolicy(applicationSetInfo.Spec.SyncPolicy, r.Policy, r.EnablePolicyOverride).AllowDelete()
if !deleteAllowed {
if err := r.removeOwnerReferencesOnDeleteAppSet(ctx, applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
controllerutil.RemoveFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName)
if err := r.Update(ctx, &applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
deleteAllowed := utils.DefaultPolicy(applicationSetInfo.Spec.SyncPolicy, r.Policy, r.EnablePolicyOverride).AllowDelete()
if !deleteAllowed {
if err := r.removeOwnerReferencesOnDeleteAppSet(ctx, applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
controllerutil.RemoveFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName)
if err := r.Update(ctx, &applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
Expand Down Expand Up @@ -524,6 +522,7 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli

for _, p := range a.Params {
app, err := r.Renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.SyncPolicy, p, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions)

if err != nil {
logCtx.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
Error("error generating application from params")
Expand All @@ -534,6 +533,24 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli
}
continue
}

if applicationSetInfo.Spec.TemplatePatch != nil {
patchedApplication, err := r.applyTemplatePatch(app, applicationSetInfo, p)

if err != nil {
log.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
Error("error generating application from params")

if firstError == nil {
firstError = err
applicationSetReason = argov1alpha1.ApplicationSetReasonRenderTemplateParamsError
}
continue
}

app = patchedApplication
}

res = append(res, *app)
}
}
Expand All @@ -545,6 +562,16 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli
return res, applicationSetReason, firstError
}

func (r *ApplicationSetReconciler) applyTemplatePatch(app *argov1alpha1.Application, applicationSetInfo argov1alpha1.ApplicationSet, params map[string]interface{}) (*argov1alpha1.Application, error) {
replacedTemplate, err := r.Renderer.Replace(*applicationSetInfo.Spec.TemplatePatch, params, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions)

if err != nil {
return nil, fmt.Errorf("error replacing values in templatePatch: %w", err)
}

return applyTemplatePatch(app, replacedTemplate)
}

func ignoreNotAllowedNamespaces(namespaces []string) predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
Expand Down Expand Up @@ -619,6 +646,8 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context,
var firstError error
// Creates or updates the application in appList
for _, generatedApp := range desiredApplications {
// The app's namespace must be the same as the AppSet's namespace to preserve the appsets-in-any-namespace
// security boundary.
generatedApp.Namespace = applicationSet.Namespace

appLog := logCtx.WithFields(log.Fields{"app": generatedApp.QualifiedName()})
Expand Down
12 changes: 12 additions & 0 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func (g *generatorMock) GenerateParams(appSetGenerator *v1alpha1.ApplicationSetG
return args.Get(0).([]map[string]interface{}), args.Error(1)
}

func (g *generatorMock) Replace(tmpl string, replaceMap map[string]interface{}, useGoTemplate bool, goTemplateOptions []string) (string, error) {
args := g.Called(tmpl, replaceMap, useGoTemplate, goTemplateOptions)

return args.Get(0).(string), args.Error(1)
}

type rendererMock struct {
mock.Mock
}
Expand All @@ -107,6 +113,12 @@ func (r *rendererMock) RenderTemplateParams(tmpl *v1alpha1.Application, syncPoli

}

func (r *rendererMock) Replace(tmpl string, replaceMap map[string]interface{}, useGoTemplate bool, goTemplateOptions []string) (string, error) {
args := r.Called(tmpl, replaceMap, useGoTemplate, goTemplateOptions)

return args.Get(0).(string), args.Error(1)
}

func TestExtractApplications(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
Expand Down
46 changes: 46 additions & 0 deletions applicationset/controllers/templatePatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package controllers

import (
"encoding/json"
"fmt"

"k8s.io/apimachinery/pkg/util/strategicpatch"

"github.com/argoproj/argo-cd/v2/applicationset/utils"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)

func applyTemplatePatch(app *appv1.Application, templatePatch string) (*appv1.Application, error) {

appString, err := json.Marshal(app)
if err != nil {
return nil, fmt.Errorf("error while marhsalling Application %w", err)
}

convertedTemplatePatch, err := utils.ConvertYAMLToJSON(templatePatch)

if err != nil {
return nil, fmt.Errorf("error while converting template to json %q: %w", convertedTemplatePatch, err)
}

if err := json.Unmarshal([]byte(convertedTemplatePatch), &appv1.Application{}); err != nil {
return nil, fmt.Errorf("invalid templatePatch %q: %w", convertedTemplatePatch, err)
}

data, err := strategicpatch.StrategicMergePatch(appString, []byte(convertedTemplatePatch), appv1.Application{})

if err != nil {
return nil, fmt.Errorf("error while applying templatePatch template to json %q: %w", convertedTemplatePatch, err)
}

finalApp := appv1.Application{}
err = json.Unmarshal(data, &finalApp)
if err != nil {
return nil, fmt.Errorf("error while unmarhsalling patched application: %w", err)
}

// Prevent changes to the `project` field. This helps prevent malicious template patches
finalApp.Spec.Project = app.Spec.Project

return &finalApp, nil
}
Loading