Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions docs/operator-manual/deep_links.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ Each link in the list has five subfields:
As mentioned earlier the links and conditions can be templated to use data from the resource, each category of links can access different types of data linked to that resource.
Overall we have these 4 resources available for templating in the system:

- `application`: this key is used to access the application resource data.
- `app` or `application`: this key is used to access the application resource data.
- `resource`: this key is used to access values for the actual k8s resource.
- `cluster`: this key is used to access the related destination cluster data like name, server, namespaces etc.
- `project`: this key is used to access the project resource data.

The above resources are accessible in particular link categories, here's a list of resources available in each category:

- `resource.links`: `resource`, `application`, `cluster` and `project`
- `application.links`: `application` and `cluster`
- `application.links`: `app`/`application` and `cluster`
- `project.links`: `project`

An example `argocd-cm.yaml` file with deep links and their variations :
Expand All @@ -60,16 +60,16 @@ An example `argocd-cm.yaml` file with deep links and their variations :
# sample application level links
application.links: |
# pkg.go.dev/text/template is used for evaluating url templates
- url: https://mycompany.splunk.com?search={{.application.spec.destination.namespace}}&env={{.project.metadata.labels.env}}
- url: https://mycompany.splunk.com?search={{.app.spec.destination.namespace}}&env={{.project.metadata.labels.env}}
title: Splunk
# conditionally show link e.g. for specific project
# github.com/antonmedv/expr is used for evaluation of conditions
- url: https://mycompany.splunk.com?search={{.application.spec.destination.namespace}}
- url: https://mycompany.splunk.com?search={{.app.spec.destination.namespace}}
title: Splunk
if: application.spec.project == "default"
- url: https://{{.application.metadata.annotations.splunkhost}}?search={{.application.spec.destination.namespace}}
- url: https://{{.app.metadata.annotations.splunkhost}}?search={{.app.spec.destination.namespace}}
title: Splunk
if: application.metadata.annotations.splunkhost != ""
if: app.metadata.annotations.splunkhost != ""
# sample resource level links
resource.links: |
- url: https://mycompany.splunk.com?search={{.resource.metadata.name}}&env={{.project.metadata.labels.env}}
Expand Down
9 changes: 6 additions & 3 deletions server/deeplinks/deeplinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (

"github.com/Masterminds/sprig/v3"
"github.com/antonmedv/expr"
"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/util/settings"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/pointer"

"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/util/settings"
)

var sprigFuncMap = sprig.GenericFuncMap() // a singleton for better performance
Expand All @@ -27,6 +28,7 @@ func init() {
const (
ResourceDeepLinkKey = "resource"
AppDeepLinkKey = "application"
AppDeepLinkShortKey = "app"
ClusterDeepLinkKey = "cluster"
ProjectDeepLinkKey = "project"
)
Expand Down Expand Up @@ -67,6 +69,7 @@ func CreateDeepLinksObject(resourceObj *unstructured.Unstructured, app *unstruct
}
if app != nil {
deeplinkObj[AppDeepLinkKey] = app.Object
deeplinkObj[AppDeepLinkShortKey] = app.Object
}
if cluster != nil {
deeplinkObj[ClusterDeepLinkKey] = cluster.Object
Expand Down
23 changes: 20 additions & 3 deletions server/deeplinks/deeplinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"strings"
"testing"

"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/util/settings"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/pointer"

"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/util/settings"
)

type deepLinkTC struct {
Expand Down Expand Up @@ -83,6 +84,22 @@ func TestDeepLinks(t *testing.T) {
}},
error: []string{},
},
{
appObj: appObj,
resourceObj: resourceObj,
projectObj: projectObj,
clusterObj: clusterObj,
inputLinks: []settings.DeepLink{{
Title: "link",
URL: "http://example.com/{{ .app.metadata.name }}&{{ .resource.data.key }}&{{ index .project.spec.sourceRepos 0}}&{{ .cluster.name }}",
Condition: pointer.String(`app.metadata.name == "test" && project.metadata.name == "test-project"`),
}},
outputLinks: []*application.LinkInfo{{
Title: pointer.String("link"),
Url: pointer.String("http://example.com/test&value1&test-repo.git&test-cluster"),
}},
error: []string{},
},
{
appObj: appObj,
resourceObj: resourceObj,
Expand Down