[common]: Add externalRefs registry for reusable external dependencies - #172
Open
rbcb-dev wants to merge 4 commits into
Open
[common]: Add externalRefs registry for reusable external dependencies#172rbcb-dev wants to merge 4 commits into
rbcb-dev wants to merge 4 commits into
Conversation
…upport Signed-off-by: Patrik Deke <patrik.deke@bedag.ch>
Signed-off-by: Patrik Deke <patrik.deke@bedag.ch>
Signed-off-by: Patrik Deke <patrik.deke@bedag.ch>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
externalRefs, a shared registry for external dependencies that can be referenced by ID from multiple parts of the chartConfigMap,Secret,PersistentVolumeClaim, andServiceentries in the same registryServicewithspec.type: ExternalNamefrom chart values and referencing an already existingServiceexternalServiceRefso container env vars can resolve an external service throughexternalRefsexternalRefsas an array so Flux/KustomizenameReferencerules stay simpleWhy
Today, charts often need to refer to external resources from several different places, for example:
Secretused inenvFromConfigMapused invalueFromPersistentVolumeClaimmounted as a volumeServicewithspec.type: ExternalNameWithout a shared registry, the same resource names need to be repeated at each usage site. That makes values harder to read, increases the risk of drift when names change, and makes GitOps overlays more verbose.
This PR introduces
externalRefsas a single place to declare those dependencies once and then reference them by ID from supported chart fields.The same mechanism also supports external services through
kind: Service, so the chart can either create aServicewithspec.type: ExternalNameor point at an already existingService.What is
externalRefsexternalRefsis a top-level array invalues.yaml.Each entry:
idkindSupported kinds in this PR:
ConfigMapSecretPersistentVolumeClaimServiceOther chart fields can then reference an
externalRefsentry byidinstead of repeating the raw resource name.What changed
New capabilities
externalRefskind: ServiceexternalRefsentries to represent external servicesmode: create / referenceexternalServiceReffullnameOverrideannotationsIntegration points
externalRefsentries can now be used in:envFrom(ConfigMap/Secret)env[].valueFrom.secretKeyRef/configMapKeyRefenv[].externalServiceRef(Service)volumes(ConfigMap/Secret/PVC)ingresses[].rules[].secretName(Secret)servicemonitor.basicAuth.existingSecret(Secret)imagePullSecrets(Secret)Feature toggle
includes.externalRefscontrols whether chart-managedServiceresources declared throughexternalRefsare rendered.Schema & validation
required: ["id", "kind"]mode: createrequiresexternalName+kind: Service;mode: referencerequiresnameminLength: 1onid,name, andexternalNamefieldsidenforcement at template levelBackwards compatibility
Kustomize compatibility
The array format preserves simple Kustomize
nameReferenceconfiguration:Example
In this example:
app-configdeclares a reusable externalConfigMapext-databasedeclares aServicethat the chart should create withspec.type: ExternalNamepartner-apideclares an already existing service that should only be referencedapp-config,ext-database, andpartner-apiare then reused by ID from component configurationDATABASE_HOSTandPARTNER_API_HOSTresolve service names throughexternalServiceRefFiles changed
charts/common/templates/helpers/_externalrefs.tpl(new)charts/common/templates/_externalname-service.yaml(new)charts/common/templates/_container.yamlcharts/common/templates/_pod.yamlcharts/common/templates/includes.yamlcharts/common/values.yamlcharts/common/values.schema.jsoncharts/common/ci/values.test.yamlcharts/common/README.md.gotmplcharts/common/README.mdcharts/common/Chart.yamlTesting
helm lintpasseshelm templateverified: renderedServiceresources usespec.type: ExternalName, env resolution works, and existing integration points (secretKeyRef,configMapKeyRef,envFrom,volumes, ingress TLS, ServiceMonitor,imagePullSecrets) continue to function