Skip to content

Commit

Permalink
Merge branch 'appset-resource-events' of https://github.com/alexymant…
Browse files Browse the repository at this point in the history
  • Loading branch information
reggie-k committed Apr 8, 2024
2 parents 5e84225 + 6292aeb commit dfe2363
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 399 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,7 @@ start: test-tools-image

# Starts a local instance of ArgoCD
.PHONY: start-local
start-local: mod-vendor-local start-local-fast

# Starts a local instance of ArgoCD without vendoring dependencies
.PHONY: start-local-fast
start-local-fast: dep-ui-local cli-local
start-local: mod-vendor-local dep-ui-local cli-local
# check we can connect to Docker to start Redis
killall goreman || true
kubectl create ns argocd || true
Expand Down
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [SCRM Lidl International Hub](https://scrm.lidl)
1. [SEEK](https://seek.com.au)
1. [Semgrep](https://semgrep.com)
1. [Shield](https://shield.com)
1. [SI Analytics](https://si-analytics.ai)
1. [Skit](https://skit.ai/)
1. [Skyscanner](https://www.skyscanner.net/)
Expand Down
25 changes: 18 additions & 7 deletions docs/user-guide/multiple_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
the first source is specified. Full UI/CLI support will be added in a future release.
This feature is subject to change in backwards incompatible ways until it is marked stable.

By default an Argo CD application is a link between a single source and a cluster. Sometimes however, you want to combine
files from multiple locations to form a single Application.

Argo CD has the ability to specify multiple sources for a single Application. Argo CD compiles all the sources
and reconciles the combined resources.

Expand All @@ -17,34 +20,42 @@ See the below example for specifying multiple sources:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
name: my-billing-app
namespace: argocd
spec:
project: default
destination:
server: https://kubernetes.default.svc
namespace: default
sources:
- chart: elasticsearch
repoURL: https://helm.elastic.co
- repoURL: https://github.com/mycompany/billing-app.git
path: manifests
targetRevision: 8.5.1
- repoURL: https://github.com/argoproj/argocd-example-apps.git
path: guestbook
- repoURL: https://github.com/mycompany/common-settings.git
path: configmaps-billing
targetRevision: HEAD
```
The above example has two sources specified. Argo CD will generate the manifests for each source separately and combine
The above example has two sources specified that need to be combined in order to create the "billing" application. Argo CD will generate the manifests for each source separately and combine
the resulting manifests.
!!! warning "Do not abuse multiple sources"
Note that the example above is just for illustration purposes. This feature is **NOT** destined as a generic way to group your applications. Take a look at [applicationsets](../user-guide/application-set.md) and the [app-of-apps](../../operator-manual/cluster-bootstrapping/) pattern if you want to have a single entity for multiple applications. If you find yourself using more than 2-3 items in the `sources` array then you are almost certainly abusing this feature and you need to rethink your application grouping strategy.
Note this feature is **NOT** destined as a generic way to group different/unrelated applications. Take a look at [applicationsets](../user-guide/application-set.md) and the [app-of-apps](../../operator-manual/cluster-bootstrapping/) pattern if you want to have a single entity for multiple applications. If you find yourself using more than 2-3 items in the `sources` array then you are almost certainly abusing this feature and you need to rethink your application grouping strategy.

If multiple sources produce the same resource (same `group`, `kind`, `name`, and `namespace`), the last source to
produce the resource will take precedence. Argo CD will produce a `RepeatedResourceWarning` in this case, but it will
sync the resources. This provides a convenient way to override a resource from a chart with a resource from a Git repo.

## Helm value files from external Git repository

One of the most common scenarios for using multiple sources is the following

1. Your organization wants to use an external/public Helm chart
1. You want to override the Helm values with your own local values
1. You don't want to clone the Helm chart locally as well because that would lead to duplication and you would need to monitor it manually for upstream changes.

In this scenario you can use the multiple sources features to combine the external chart with your own local values.

Helm sources can reference value files from git sources. This allows you to use a third-party Helm chart with custom,
git-hosted values.

Expand Down
94 changes: 47 additions & 47 deletions pkg/apiclient/applicationset/applicationset.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/argoproj/argo-cd/v2/server/rbacpolicy"
"github.com/argoproj/argo-cd/v2/util/argo"
argoutil "github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/broadcast"
"github.com/argoproj/argo-cd/v2/util/collections"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/env"
Expand Down Expand Up @@ -82,7 +83,7 @@ type Server struct {
appclientset appclientset.Interface
appLister applisters.ApplicationLister
appInformer cache.SharedIndexInformer
appBroadcaster Broadcaster
appBroadcaster broadcast.Broadcaster[appv1.ApplicationWatchEvent]
repoClientset apiclient.Clientset
kubectl kube.Kubectl
db db.ArgoDB
Expand All @@ -102,7 +103,7 @@ func NewServer(
appclientset appclientset.Interface,
appLister applisters.ApplicationLister,
appInformer cache.SharedIndexInformer,
appBroadcaster Broadcaster,
appBroadcaster broadcast.Broadcaster[appv1.ApplicationWatchEvent],
repoClientset apiclient.Clientset,
cache *servercache.Cache,
kubectl kube.Kubectl,
Expand All @@ -114,7 +115,9 @@ func NewServer(
enabledNamespaces []string,
) (application.ApplicationServiceServer, AppResourceTreeFn) {
if appBroadcaster == nil {
appBroadcaster = &broadcasterHandler{}
appBroadcaster = broadcast.NewHandler(func(app *appv1.Application, eventType watch.EventType) *appv1.ApplicationWatchEvent {
return &appv1.ApplicationWatchEvent{Application: *app, Type: eventType}
})
}
_, err := appInformer.AddEventHandler(appBroadcaster)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions server/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import (
appinformer "github.com/argoproj/argo-cd/v2/pkg/client/informers/externalversions"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient/mocks"
appmocks "github.com/argoproj/argo-cd/v2/server/application/mocks"
servercache "github.com/argoproj/argo-cd/v2/server/cache"
"github.com/argoproj/argo-cd/v2/server/rbacpolicy"
"github.com/argoproj/argo-cd/v2/test"
"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/assets"
broadcastermocks "github.com/argoproj/argo-cd/v2/util/broadcast/mocks"
"github.com/argoproj/argo-cd/v2/util/cache"
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
"github.com/argoproj/argo-cd/v2/util/cache/appstate"
Expand Down Expand Up @@ -221,7 +221,7 @@ func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T,
panic("Timed out waiting for caches to sync")
}

broadcaster := new(appmocks.Broadcaster)
broadcaster := new(broadcastermocks.Broadcaster[appsv1.ApplicationWatchEvent])
broadcaster.On("Subscribe", mock.Anything, mock.Anything).Return(func() {}).Run(func(args mock.Arguments) {
// Simulate the broadcaster notifying the subscriber of an application update.
// The second parameter to Subscribe is filters. For the purposes of tests, we ignore the filters. Future tests
Expand Down Expand Up @@ -401,7 +401,7 @@ func newTestAppServerWithEnforcerConfigureWithBenchmark(f func(*rbac.Enforcer),
panic("Timed out waiting for caches to sync")
}

broadcaster := new(appmocks.Broadcaster)
broadcaster := new(broadcastermocks.Broadcaster[appsv1.ApplicationWatchEvent])
broadcaster.On("Subscribe", mock.Anything, mock.Anything).Return(func() {}).Run(func(args mock.Arguments) {
// Simulate the broadcaster notifying the subscriber of an application update.
// The second parameter to Subscribe is filters. For the purposes of tests, we ignore the filters. Future tests
Expand Down
Loading

0 comments on commit dfe2363

Please sign in to comment.