Skip to content

Commit 1a6973a

Browse files
authored
feat: Add the ability to not autogenerate external URLs from ingress object (argoproj#13705) (argoproj#25383)
Signed-off-by: rkevin <rk@rkevin.dev>
1 parent 860eed5 commit 1a6973a

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

common/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ const (
225225
// Ex: "http://grafana.example.com/d/yu5UH4MMz/deployments"
226226
// Ex: "Go to Dashboard|http://grafana.example.com/d/yu5UH4MMz/deployments"
227227
AnnotationKeyLinkPrefix = "link.argocd.argoproj.io/"
228+
// AnnotationKeyIgnoreDefaultLinks tells the Application to not add autogenerated links from this object into its externalURLs
229+
// This applies to ingress objects and takes effect if set to "true"
230+
// This only disables the default behavior of generating links based on the ingress spec, and does not disable AnnotationKeyLinkPrefix
231+
AnnotationKeyIgnoreDefaultLinks = "argocd.argoproj.io/ignore-default-links"
228232

229233
// AnnotationKeyAppSkipReconcile tells the Application to skip the Application controller reconcile.
230234
// Skip reconcile when the value is "true" or any other string values that can be strconv.ParseBool() to be true.

controller/cache/info.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,19 @@ func populateIngressInfo(un *unstructured.Unstructured, res *ResourceInfo) {
225225
if res.NetworkingInfo != nil {
226226
urls = res.NetworkingInfo.ExternalURLs
227227
}
228-
for url := range urlsSet {
229-
urls = append(urls, url)
228+
229+
enableDefaultExternalURLs := true
230+
if ignoreVal, ok := un.GetAnnotations()[common.AnnotationKeyIgnoreDefaultLinks]; ok {
231+
if ignoreDefaultLinks, err := strconv.ParseBool(ignoreVal); err == nil {
232+
enableDefaultExternalURLs = !ignoreDefaultLinks
233+
}
230234
}
235+
if enableDefaultExternalURLs {
236+
for url := range urlsSet {
237+
urls = append(urls, url)
238+
}
239+
}
240+
231241
res.NetworkingInfo = &v1alpha1.ResourceNetworkingInfo{TargetRefs: targets, Ingress: ingress, ExternalURLs: urls}
232242
}
233243

controller/cache/info_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,40 @@ var (
126126
ingress:
127127
- ip: 107.178.210.11`)
128128

129+
testIgnoreDefaultLinksIngress = strToUnstructured(`
130+
apiVersion: extensions/v1beta1
131+
kind: Ingress
132+
metadata:
133+
name: helm-guestbook
134+
namespace: default
135+
uid: "4"
136+
annotations:
137+
link.argocd.argoproj.io/external-link: http://my-grafana.example.com/ingress-link
138+
argocd.argoproj.io/ignore-default-links: "true"
139+
spec:
140+
backend:
141+
serviceName: not-found-service
142+
servicePort: 443
143+
rules:
144+
- host: helm-guestbook.example.com
145+
http:
146+
paths:
147+
- backend:
148+
serviceName: helm-guestbook
149+
servicePort: 443
150+
path: /
151+
- backend:
152+
serviceName: helm-guestbook
153+
servicePort: https
154+
path: /
155+
tls:
156+
- host: helm-guestbook.example.com
157+
secretName: my-tls-secret
158+
status:
159+
loadBalancer:
160+
ingress:
161+
- ip: 107.178.210.11`)
162+
129163
testIngressWildCardPath = strToUnstructured(`
130164
apiVersion: extensions/v1beta1
131165
kind: Ingress
@@ -1200,6 +1234,30 @@ func TestGetLinkAnnotatedIngressInfo(t *testing.T) {
12001234
}, info.NetworkingInfo)
12011235
}
12021236

1237+
func TestGetIgnoreDefaultLinksIngressInfo(t *testing.T) {
1238+
info := &ResourceInfo{}
1239+
populateNodeInfo(testIgnoreDefaultLinksIngress, info, []string{})
1240+
assert.Empty(t, info.Info)
1241+
sort.Slice(info.NetworkingInfo.TargetRefs, func(i, j int) bool {
1242+
return info.NetworkingInfo.TargetRefs[i].Name < info.NetworkingInfo.TargetRefs[j].Name
1243+
})
1244+
assert.Equal(t, &v1alpha1.ResourceNetworkingInfo{
1245+
Ingress: []corev1.LoadBalancerIngress{{IP: "107.178.210.11"}},
1246+
TargetRefs: []v1alpha1.ResourceRef{{
1247+
Namespace: "default",
1248+
Group: "",
1249+
Kind: kube.ServiceKind,
1250+
Name: "helm-guestbook",
1251+
}, {
1252+
Namespace: "default",
1253+
Group: "",
1254+
Kind: kube.ServiceKind,
1255+
Name: "not-found-service",
1256+
}},
1257+
ExternalURLs: []string{"http://my-grafana.example.com/ingress-link"},
1258+
}, info.NetworkingInfo)
1259+
}
1260+
12031261
func TestGetIngressInfoWildCardPath(t *testing.T) {
12041262
info := &ResourceInfo{}
12051263
populateNodeInfo(testIngressWildCardPath, info, []string{})

docs/user-guide/annotations-and-labels.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
| argocd.argoproj.io/sync-options | any | [see sync options docs](sync-options.md) | Provides a variety of settings to determine how an Application's resources are synced. |
1616
| argocd.argoproj.io/sync-wave | any | [see sync waves docs](sync-waves.md) | |
1717
| argocd.argoproj.io/tracking-id | any | any | Used by Argo CD to track resources it manages. See [resource tracking docs](resource_tracking.md) for details. |
18-
| argocd.argoproj.io/ignore-resource-updates | any | `"true"`, `false` | Used by Argo CD to ignore resource updates. See [reconcile docs](..%2Foperator-manual%2Freconcile.md)reconcile_docs for details. |
18+
| argocd.argoproj.io/ignore-default-links | any | `"true"`, `false` | Do not add autogenerated links to the ArgoCD UI from this resource. [external URL docs](external-url.md) for details. |
19+
| argocd.argoproj.io/ignore-resource-updates | any | `"true"`, `false` | Used by Argo CD to ignore resource updates. See [reconcile docs](..%2Foperator-manual%2Freconcile.md)reconcile_docs for details. |
1920
| link.argocd.argoproj.io/{some link name} | any | An http(s) URL | Adds a link to the Argo CD UI for the resource. See [external URL docs](external-url.md) for details. |
2021
| pref.argocd.argoproj.io/default-pod-sort | Application | [see UI customization docs](../operator-manual/ui-customization.md) | Sets the Application's default grouping mechanism. |
2122
| pref.argocd.argoproj.io/default-view | Application | [see UI customization docs](../operator-manual/ui-customization.md) | Sets the Application's default view mode (e.g. "tree" or "list") |

docs/user-guide/external-url.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
# Add external URL
1+
# External URL Links
2+
3+
ArgoCD automatically generates clickable links to external pages that your application exposes.
4+
This is usually done via detecting hosts / URLs from your `Ingress` resources.
5+
6+
## Add external URL
27

38
You can add additional external links to Argo CD dashboard. For example
4-
links monitoring pages or documentation instead of just ingress hosts or other apps.
9+
links to monitoring pages or documentation, instead of just ingress hosts or other apps.
510

6-
ArgoCD generates a clickable links to external pages for a resource based on per resource annotation.
11+
ArgoCD generates clickable links to external pages for a resource based on per resource annotation.
712

813
Example:
914
```yaml
@@ -20,3 +25,23 @@ The external link icon will be visible for respective resource on ArgoCD applica
2025
2126
![External link](../assets/external-link-1.png)
2227
28+
## Ignore autogenerated external URLs
29+
30+
If an ingress object should be ignored by ArgoCD's autodetection of external URLs, such as a dummy ingress
31+
pointing to a 404 page, you can add the `argocd.argoproj.io/ignore-default-links: "true"` annotation. This will
32+
remove any links inferred from the ingress spec from the ArgoCD UI. Any links added by `link.argocd.argoproj.io`
33+
annotations are unchanged.
34+
35+
Example:
36+
```yaml
37+
apiVersion: networking.k8s.io/v1
38+
kind: Ingress
39+
metadata:
40+
annotations:
41+
link.argocd.argoproj.io/external-link: https://optional.show-me-instead.example.com/
42+
argocd.argoproj.io/ignore-default-links: "true"
43+
spec:
44+
rules:
45+
- host: dont-show-me.internal.example.com
46+
...
47+
```

0 commit comments

Comments
 (0)