From 6610d35bd3354a9c6b844524ab5ac66c620e036f Mon Sep 17 00:00:00 2001 From: Ian Pittwood Date: Wed, 14 May 2025 14:06:33 -0600 Subject: [PATCH 1/5] Add helper functions for Chronicle agent --- charts/rstudio-library/Chart.yaml | 4 +- charts/rstudio-library/NEWS.md | 5 ++ .../templates/_chronicle-agent.tpl | 49 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 charts/rstudio-library/templates/_chronicle-agent.tpl diff --git a/charts/rstudio-library/Chart.yaml b/charts/rstudio-library/Chart.yaml index c497be93f..35b003957 100644 --- a/charts/rstudio-library/Chart.yaml +++ b/charts/rstudio-library/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: rstudio-library description: Helm library helpers for use by official RStudio charts type: library -version: 0.1.31 -appVersion: 0.1.31 +version: 0.1.32 +appVersion: 0.1.32 icon: https://rstudio.com/wp-content/uploads/2018/10/RStudio-Logo-Flat.png home: https://www.rstudio.com diff --git a/charts/rstudio-library/NEWS.md b/charts/rstudio-library/NEWS.md index 109c88286..c4b981890 100644 --- a/charts/rstudio-library/NEWS.md +++ b/charts/rstudio-library/NEWS.md @@ -1,5 +1,10 @@ # Changelog +## 0.1.32 + +- Add `rstudio-library.chronicle-agent.image` and `rstudio-library.chronicle-agent.serverAddress` helper functions for + Chronicle server deployment auto-discovery. + ## 0.1.31 - Add helm unit test scaffold. diff --git a/charts/rstudio-library/templates/_chronicle-agent.tpl b/charts/rstudio-library/templates/_chronicle-agent.tpl new file mode 100644 index 000000000..a4787257b --- /dev/null +++ b/charts/rstudio-library/templates/_chronicle-agent.tpl @@ -0,0 +1,49 @@ +{{/* +Attempts to determine an image tag for the chronicle-agent image by looking up a Chronicle server in the current +namespace. If no server is found, it will default to "latest". If a tag is specified in the passed config, it will be +used instead of the server tag. +Takes a dict: + - .chronicleAgent: the chronicle-agent config + - .chronicleAgent.image.registry: the registry to use for the image + - .chronicleAgent.image.repository: the repository to use for the image + - .chronicleAgent.image.tag: the tag to use for the image (optional) + */}} +{{- define "rstudio-library.chronicle-agent.image" }} +{{- $registry := required "registry must be specified for the chronicle-agent config." .chronicleAgent.image.registry }} +{{- $repository := required "repository must be specified for the chronicle-agent config." .chronicleAgent.image.repository }} +{{- $version := "latest" }} +{{- if not .chronicleAgent.image.tag }} +{{- range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }} +{{- $name := get $service.metadata.labels "app.kubernetes.io/name" }} +{{- $component := get $service.metadata.labels "app.kubernetes.io/component" }} +{{- if and (contains "posit-chronicle" $name) (eq $component "server") }} +{{- $version = get $service.metadata.labels "app.kubernetes.io/version" }} +{{- end }} +{{- end }} +{{- else }} +{{- $version = .chronicleAgent.image.tag }} +{{- end }} +{{ $registry }}/{{ $repository }}:{{ $version }} +{{- end }} + +{{/* +Attempts to determine the server address for the chronicle-agent image by looking up a Chronicle server in the current +namespace. If no server is found, it will default to "". If a serverAddress is specified in the passed config, +it will be used instead of the server address. +Takes a dict: + - .chronicleAgent: the chronicle-agent config + - .chronicleAgent.serverAddress: the server address to use for the image (optional) +*/}} +{{- define "rstudio-library.chronicle-agent.serverAddress" }} +{{- if .chronicleAgent.serverAddress }} +{{- .chronicleAgent.serverAddress}} +{{- else }} +{{- range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }} +{{- $name := get $service.metadata.labels "app.kubernetes.io/name "}} +{{- $component := get $service.metadata.labels "app.kubernetes.io/component "}} +{{- if and (contains "posit-chronicle" $name) (eq $component "server") }} +{{ $name }}.{{ $service.metadata.namespace }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} From e1ba2a8524acdc56922f95c9fc9485d45f766f48 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 14 May 2025 20:09:13 +0000 Subject: [PATCH 2/5] Update helm-docs and README.md --- charts/rstudio-library/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/rstudio-library/README.md b/charts/rstudio-library/README.md index eea6e6196..b05d0147d 100644 --- a/charts/rstudio-library/README.md +++ b/charts/rstudio-library/README.md @@ -1,6 +1,6 @@ # rstudio-library -![Version: 0.1.31](https://img.shields.io/badge/Version-0.1.31-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: 0.1.31](https://img.shields.io/badge/AppVersion-0.1.31-informational?style=flat-square) +![Version: 0.1.32](https://img.shields.io/badge/Version-0.1.32-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: 0.1.32](https://img.shields.io/badge/AppVersion-0.1.32-informational?style=flat-square) #### _Helm library helpers for use by official RStudio charts_ From 8516918df2287f1a733c3a25f796e512b79ac899 Mon Sep 17 00:00:00 2001 From: Ian Pittwood Date: Wed, 14 May 2025 14:09:53 -0600 Subject: [PATCH 3/5] Trigger CI From 0275fc1444fb6cf4396139cac0385e5cc06273a1 Mon Sep 17 00:00:00 2001 From: Ian Pittwood Date: Wed, 14 May 2025 14:18:36 -0600 Subject: [PATCH 4/5] Remove excessive whitespace trim in helper --- charts/rstudio-library/templates/_chronicle-agent.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/rstudio-library/templates/_chronicle-agent.tpl b/charts/rstudio-library/templates/_chronicle-agent.tpl index a4787257b..3e8282433 100644 --- a/charts/rstudio-library/templates/_chronicle-agent.tpl +++ b/charts/rstudio-library/templates/_chronicle-agent.tpl @@ -36,7 +36,7 @@ Takes a dict: */}} {{- define "rstudio-library.chronicle-agent.serverAddress" }} {{- if .chronicleAgent.serverAddress }} -{{- .chronicleAgent.serverAddress}} +{{ .chronicleAgent.serverAddress}} {{- else }} {{- range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }} {{- $name := get $service.metadata.labels "app.kubernetes.io/name "}} From a3cef3dbb68e5fdf51886c9551b93eefc91f46d8 Mon Sep 17 00:00:00 2001 From: Ian Pittwood Date: Thu, 15 May 2025 09:14:51 -0600 Subject: [PATCH 5/5] Allow a namespace to be passed for the chronicle server lookup --- charts/rstudio-library/templates/_chronicle-agent.tpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/charts/rstudio-library/templates/_chronicle-agent.tpl b/charts/rstudio-library/templates/_chronicle-agent.tpl index 3e8282433..74a59ffb6 100644 --- a/charts/rstudio-library/templates/_chronicle-agent.tpl +++ b/charts/rstudio-library/templates/_chronicle-agent.tpl @@ -7,13 +7,14 @@ Takes a dict: - .chronicleAgent.image.registry: the registry to use for the image - .chronicleAgent.image.repository: the repository to use for the image - .chronicleAgent.image.tag: the tag to use for the image (optional) + - .chronicleAgent.serverNamespace: the namespace to search for the Chronicle server, defaults to the current release namespace */}} {{- define "rstudio-library.chronicle-agent.image" }} {{- $registry := required "registry must be specified for the chronicle-agent config." .chronicleAgent.image.registry }} {{- $repository := required "repository must be specified for the chronicle-agent config." .chronicleAgent.image.repository }} {{- $version := "latest" }} {{- if not .chronicleAgent.image.tag }} -{{- range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }} +{{- range $index, $service := (lookup "v1" "Service" (default .Release.Namespace .chronicleAgent.serverNamespace) "").items }} {{- $name := get $service.metadata.labels "app.kubernetes.io/name" }} {{- $component := get $service.metadata.labels "app.kubernetes.io/component" }} {{- if and (contains "posit-chronicle" $name) (eq $component "server") }} @@ -33,12 +34,13 @@ it will be used instead of the server address. Takes a dict: - .chronicleAgent: the chronicle-agent config - .chronicleAgent.serverAddress: the server address to use for the image (optional) + - .chronicleAgent.serverNamespace: the namespace to search for the Chronicle server, defaults to the current release namespace */}} {{- define "rstudio-library.chronicle-agent.serverAddress" }} {{- if .chronicleAgent.serverAddress }} {{ .chronicleAgent.serverAddress}} {{- else }} -{{- range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }} +{{- range $index, $service := (lookup "v1" "Service" (default .Release.Namespace .chronicleAgent.serverNamespace) "").items }} {{- $name := get $service.metadata.labels "app.kubernetes.io/name "}} {{- $component := get $service.metadata.labels "app.kubernetes.io/component "}} {{- if and (contains "posit-chronicle" $name) (eq $component "server") }}