Repository navigation
feat: instantiate policyRefs remoteURL.url as a template per cluster - #2001
Merged
Merged
Conversation
spec.policyRefs[].remoteURL.url can now be a template, instantiated for each matching cluster before Sveltos fetches it, the same way remoteURL.secretRef and ConfigMap/Secret policyRef names already are. One ClusterProfile can then pull a different artifact for each cluster. It uses text/template rather than the html/template-based helper, so values taken from cluster fields are not HTML-escaped into the URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gianlucam76
approved these changes
Sep 28, 2026
gianlucam76
left a comment
Member
There was a problem hiding this comment.
Thank you @monadic. This is great.
We can avoid some duplication by exporting a method in libsveltos. But that is not a problem with this PR. It is something already existing that I will handle in separate PRs.
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.
Gianluca is this ok? alexis
What
spec.policyRefs[].remoteURL.urlcan now be a template, instantiated for eachmatching cluster before Sveltos fetches it. This works the same way as
remoteURL.secretRef.name/namespaceand ConfigMap/Secret policyRef names,with the same template data (
.Cluster,.ClusterNamespace,.ClusterName) andthe same functions. One ClusterProfile can then pull a different artifact for
each cluster:
Why
Today the URL is used as written. A templated URL fails with
failed to parse OCI reference ...: invalid reference, so per-clustercontent needs one ClusterProfile per cluster, even though the secretRef
next to the URL is already templated.
How
controllers/url_source.go: newinstantiateRemoteURLhelper. It returns a URLwithout
{{unchanged and does not read the Cluster. Otherwise it rendersthe URL with
text/template, using the data libsveltos uses for referencenames and
missingkey=error. It usestext/template, not thehtml/template-basedlibsveltos helper, because
html/templateHTML-escapes values that come fromcluster fields. For example,
+becomes+and&becomes&,which would corrupt a URL.
deployContentOfURLinstantiates the URL before fetching, for both OCI andHTTP(S). A failure is returned as
TemplateInstantiationError(reported asFailedNonRetriable), even when the ref is optional. This matches howConfigMap/Secret names behave. The deployed resources' reference-name
annotation records the instantiated URL.
urlPolicyRefsHashinstantiates the URL before fetching it for the hash, socontent changes are detected for each cluster. A template error is logged
and skipped there, as
getInstantiatedPolicyRefInfoalready does forConfigMap/Secret names. The deploy step reports the error.
api/v1beta1/spec.go: theRemoteURL.URLdoc now says it can be a template.CRDs,
lib/crdandmanifest/manifest.yamlwere regenerated (description only).KustomizationRef.remoteURLis unchanged. The same helper could be appliedthere in a follow-up.
Tests
controllers/url_source_test.go, new "RemoteURL templating" specs (envtestCluster plus an in-process OCI registry and httptest server):
urlPolicyRefsHashfetches that artifactin the query: the URL is fetched without HTML escaping (this spec fails
if the
html/templatehelper is used instead)instantiateRemoteURLreturns an error,deployContentOfURLreturns
TemplateInstantiationError(optional ref too), and the hash skipsthe ref
make testandmake lintpass (0 issues), on main at be25edd.with url
oci://<registry>/space/demo-{{ .Cluster.metadata.name }}:latestdeployed the demo-w1 artifact to cluster w1 (Provisioned). Pushing new
content to demo-w1 was redeployed within the 1m interval. A URL using a
missing label reported
FailedNonRetriablewith the template error. Stockv1.15.0 reports
Failedwithinvalid referencefor the same profile.🤖 Generated with Claude Code