Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: substitutevalues:5: function "instance" not defined #565

Closed
rbjorklin opened this issue May 28, 2024 · 3 comments
Closed

BUG: substitutevalues:5: function "instance" not defined #565

rbjorklin opened this issue May 28, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@rbjorklin
Copy link

Problem Description

I'm trying to provision Prometheus but unfortunately I'm met with:

k describe clustersummaries prometheus-capi-management
Status:
  Dependencies:  All dependencies deployed
  Feature Summaries:
    Failure Message:    failed to instantiate resource with substitute values: template: prometheus-capi-management-substitutevalues:5: function "instance" not defined: template: prometheus-capi-management-substitutevalues:5: function "instance" not defined
    Feature ID:         Kustomize
    Hash:               /alDzQ3OupAvIbPgZTTZwElQL4vp6Y4M/znsJXxzATk=
    Last Applied Time:  2024-05-28T03:44:30Z
    Status:             Provisioning
Events:                 <none>

My Cluster Profile looks like this:

apiVersion: config.projectsveltos.io/v1alpha1
kind: ClusterProfile
metadata:
  name: prometheus
  namespace: projectsveltos
spec:
  dependsOn:
    - hcloud-mvp
  clusterSelector: environment=hcloud
  syncMode: ContinuousWithDriftDetection
  kustomizationRefs:
    - kind: GitRepository
      name: cluster-repo
      namespace: projectsveltos
      path: "manifests/overlays/{{ .Cluster.metadata.name }}/prometheus"

My Kustomization file looks like this:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../../../base/prometheus/59.0.0-1

And the contents of the folder referenced via the kustomization.yaml file was generated by executing:

helm template \
        --include-crds \
        --values values.yaml \
        --version 59.0.0 \
        --namespace prometheus \
        prometheus \
        prometheus-community/kube-prometheus-stack \
        | kubectl slice --output-dir=../base/prometheus/59.0.0-1

System Information

CLUSTERAPI VERSION: v1.7.2
SVELTOS VERSION: 0.30.0
KUBERNETES VERSION: v1.30.1

Logs

@rbjorklin rbjorklin added the bug Something isn't working label May 28, 2024
@rbjorklin
Copy link
Author

After looking at the section on templating and also the kustomize specific section I tried disabling templating by patching all of my configmaps with this addition to my kustomization.yaml:

patches:
  - target:
      version: v1
      kind: ConfigMap
    patch: |-
      apiVersion: v1
      kind: Configmap
      metadata:
        name: ignored # required but not used
        annotations:
          projectsveltos.io/template: "false"

Unfortunately it doesn't seem to have helped.

@gianlucam76
Copy link
Member

Thank you @rbjorklin

This is a use case I have not considered. Looking at the kustomize output, I see for instance

data:
  alertmanager-overview.json: |-
  ... legendFormat":"{{instance}}","refId":"A"}],...

that needs no instantiation.

I believe in your case you want to express path as a template

path: "manifests/overlays/{{ .Cluster.metadata.name }}/prometheus"

but then what is found inside that path requires no instantiation. So I will change Sveltos logic.

Do not assume the content of a Kustomize output is a template unless there are

// Values is a map[string]string type that allows to define a set of key-value pairs.
	// These key-value pairs can optionally leverage Go templates for further processing.
	// With Sveltos, you can define key-value pairs where the values can be Go templates.
	// These templates have access to management cluster information during deployment. This allows
	// to do more than just replace placeholders. Variables can be used to dynamically
	// construct values based on other resources or variables within the Kustomize output.
	// For example, imagine you have a Region key with a template value like:
	// '{{ index .Cluster.metadata.labels "region" }}'.
	// This template retrieves the region label from the cluster instance metadata.
	// Finally, Sveltos uses these processed values to fill placeholders in the Kustomize output.
	// The output itself can also contain templates, like:
	// region: '{{ default "west" .Region }}'.
	// This way, the final output from Kustomize will have the region set dynamically based on
	// the actual region retrieved earlier.
	// +optional
	Values map[string]string `json:"values,omitempty"`

	// ValuesFrom can reference ConfigMap/Secret instances. Within the ConfigMap or Secret data,
	// it is possible to define key-value pairs. These key-value pairs can optionally leverage
	// Go templates for further processing.
	// With Sveltos, you can define key-value pairs where the values can be Go templates.
	// These templates have access to management cluster information during deployment. This allows
	// to do more than just replace placeholders. Variables can be used to dynamically
	// construct values based on other resources or variables within the Kustomize output.
	// For example, imagine you have a Region key with a template value like:
	// '{{ index .Cluster.metadata.labels "region" }}'.
	// This template retrieves the region label from the cluster instance metadata.
	// Finally, Sveltos uses these processed values to fill placeholders in the Kustomize output.
	// The output itself can also contain templates, like:
	// region: '{{ default "west" .Region }}'.
	// This way, the final output from Kustomize will have the region set dynamically based on
	// the actual region retrieved earlier.
	// +optional
	ValuesFrom []ValueFrom `json:"valuesFrom,omitempty"`

@gianlucam76
Copy link
Member

Resolved. Fix will be in v0.31.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants