Skip to content

Commit

Permalink
feat(kong): Generate Admin API service name if requested (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap authored Jul 17, 2023
1 parent cce876c commit 09c2764
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions charts/kong/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.25.0

- Generate the `adminApiService.name` value from `.Release.Name` rather than
hardcoding to `kong`
[#839](https://github.com/Kong/charts/pull/839)

## 2.24.0

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion charts/kong/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ maintainers:
name: kong
sources:
- https://github.com/Kong/charts/tree/main/charts/kong
version: 2.24.0
version: 2.25.0
appVersion: "3.3"
dependencies:
- name: postgresql
Expand Down
7 changes: 6 additions & 1 deletion charts/kong/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ section of `values.yaml` file:
| userDefinedVolumeMounts | Create volumeMounts. Please go to Kubernetes doc for the spec of the volumeMounts | |
| terminationGracePeriodSeconds | Sets the [termination grace period](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-handler-execution) for Deployment pod | 30 |
| gatewayDiscovery.enabled | Enables Kong instance service discovery (for more details see [gatewayDiscovery section][gd_section]) | false |
| gatewayDiscovery.generateAdminApiService | Generate the admin API service name based on the release name (for more details see [gatewayDiscovery section][gd_section]) | false |
| gatewayDiscovery.adminApiService.namespace | The namespace of the Kong admin API service (for more details see [gatewayDiscovery section][gd_section]) | `.Release.Namespace` |
| gatewayDiscovery.adminApiService.name | The name of the Kong admin API service (for more details see [gatewayDiscovery section][gd_section]) | "" |
| konnect.enabled | Enable synchronisation of data plane configuration with Konnect Runtime Group | false |
Expand Down Expand Up @@ -798,12 +799,16 @@ You'll be able to configure this feature through configuration section under
service.
(provided under the hood via `CONTROLLER_KONG_ADMIN_SVC` environment variable).

The following admin API Service flags have to be provided in order for gateway
The following admin API Service flags have to be present in order for gateway
discovery to work:

- `ingressController.gatewayDiscovery.adminApiService.name`
- `ingressController.gatewayDiscovery.adminApiService.namespace`

If you set `ingressController.gatewayDiscovery.generateAdminApiService` to `true`,
the chart will generate values for `name` and `namespace` based on the current release name and
namespace. This is useful when consuming the `kong` chart as a subchart.

Using this feature requires a split release installation of Gateways and Ingress Controller.
For exemplar `values.yaml` files which use this feature please see: [examples README.md](./example-values/README.md).

Expand Down
17 changes: 13 additions & 4 deletions charts/kong/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,18 @@ Return the admin API service name for service discovery
{{- $gatewayDiscovery := .Values.ingressController.gatewayDiscovery -}}
{{- if $gatewayDiscovery.enabled -}}
{{- $adminApiService := $gatewayDiscovery.adminApiService -}}
{{- $_ := required ".ingressController.gatewayDiscovery.adminApiService has to be provided when .Values.ingressController.gatewayDiscovery.enabled is set to true" $adminApiService -}}
{{- $adminApiServiceName := $gatewayDiscovery.adminApiService.name -}}
{{- $generateAdminApiService := $gatewayDiscovery.generateAdminApiService -}}

{{- if and $generateAdminApiService $adminApiService.name -}}
{{- fail (printf ".Values.ingressController.gatewayDiscovery.adminApiService and .Values.ingressController.gatewayDiscovery.generateAdminApiService must not be provided at the same time") -}}
{{- end -}}

{{- if $generateAdminApiService -}}
{{- $adminApiServiceName = (printf "%s-%s" .Release.Name "gateway-admin") -}}
{{- else }}
{{- $_ := required ".ingressController.gatewayDiscovery.adminApiService.name has to be provided when .Values.ingressController.gatewayDiscovery.enabled is set to true" $adminApiServiceName -}}
{{- end }}

{{- if (semverCompare "< 2.9.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
{{- fail (printf "Gateway discovery is available in controller versions 2.9 and up. Detected %s" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
Expand All @@ -381,9 +392,7 @@ Return the admin API service name for service discovery
{{- end }}

{{- $namespace := $adminApiService.namespace | default ( include "kong.namespace" . ) -}}
{{- $name := $adminApiService.name -}}
{{- $_ := required ".ingressController.gatewayDiscovery.adminApiService.name has to be provided when .Values.ingressController.gatewayDiscovery.enabled is set to true" $name -}}
{{- printf "%s/%s" $namespace $name -}}
{{- printf "%s/%s" $namespace $adminApiServiceName -}}
{{- else -}}
{{- fail "Can't use gateway discovery when .Values.ingressController.gatewayDiscovery.enabled is set to false." -}}
{{- end -}}
Expand Down
1 change: 1 addition & 0 deletions charts/kong/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ ingressController:

gatewayDiscovery:
enabled: false
generateAdminApiService: false
adminApiService:
namespace: ""
name: ""
Expand Down

0 comments on commit 09c2764

Please sign in to comment.