carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.69k stars 136 forks source link

- struct has no .scrapeTimeout field or method #635

Closed ramkrishna2k3 closed 2 years ago

ramkrishna2k3 commented 2 years ago

I have a weird issue. Unable to resolve, Kindly help

error :

**ytt: Error:
- struct has no .scrapeTimeout field or method
    in <toplevel>
      config.yml:257 |       scrapeTimeout: #@ data.values.podMonitor.scrapeTimeout**

I pass the value in config.yml from values.yml

config.yml

---
#! Source: tomcat/templates/podmonitor.yaml
#@ if data.values.podMonitor.enabled:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: tomcat
  namespace: #@ data.values.podMonitor.namespace
  labels:
    app.kubernetes.io/name: tomcat
    helm.sh/chart: tomcat-10.1.12
    app.kubernetes.io/instance: release-name
spec:
  podMetricsEndpoints:
    - port: "metrics"
      path: /metrics
      interval: #@ data.values.podMonitor.interval
      _scrapeTimeout: #@ data.values.podMonitor.scrapeTimeout_
  namespaceSelector:
    matchNames:
      - default
  selector:
    matchLabels:
      app.kubernetes.io/name: tomcat
      helm.sh/chart: tomcat-10.1.12
      app.kubernetes.io/instance: release-name
#@ end

values.yml

podMonitor:
  enabled: false
  #@schema/desc "Namespace in which Prometheus is running"
  namespace: monitoring
  #@schema/desc "Interval at which metrics should be scraped."
  interval: 30s
  #@schema/desc "Specify the timeout after which the scrape is ended"
  scrapeTimeout: 30s

But when I give podMonitor, enabled false then reconcile is succeed, but when i give false reconcile get failed.

pkginstall.yml

---
apiVersion: packaging.carvel.dev/v1alpha1
kind: PackageInstall
metadata:
  name: tomcatapp-demo
spec:
  serviceAccountName: default-ns-sa
  packageRef:
    refName: tomcatapp.bitnami.vmware.com
    versionSelection:
      constraints: 10.1.12
  values:
  - secretRef:
      name: tomcatapp-demo-values
---
apiVersion: v1
kind: Secret
metadata:
  name: tomcatapp-demo-values
stringData:
  values.yml: |
    ---
    podMonitor:
      enabled: true       (note: false works fine)
    prometheusRule:
      enabled: true
    ingress:
      enabled: true

2022-03-21 (@pivotaljohn) — added code fences to make clearer the indentation of the provided YAML files (indentation doesn't show up in plain markdown).

rohitagg2020 commented 2 years ago

When podMonitor enabled is false, then ytt doesn't try to run over below code and hence it is passing

#@ if data.values.podMonitor.enabled:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
...
app.kubernetes.io/instance: release-name
#@ end

But when it is set to true, then ytt run over the above code. Can you share the files with the correct indentation. I think there might be some misindentation w.r.t. scrapeTimeout: 30s

renuy commented 2 years ago

@ramkrishna2k3 , this looks like a ytt issue, transferred to the ytt repo.

ramkrishna2k3 commented 2 years ago

rohitagg2020. Please find the attached file . config.yml.txt pkginstall.yml.txt values.yml.txt

ramkrishna2k3 commented 2 years ago

@ramkrishna2k3 , this looks like a ytt issue, transferred to the ytt repo.

@renuy : how do that, please help.

pivotaljohn commented 2 years ago

@ramkrishna2k3

I can't seem to make out where values.yml is located. It must be in the bundle of your package in order to be the schema for your package. Given the fact that a data value that is most definitely defined in your schema is apparently undefined, I suspect values.yml is not in the package.

Unrelated: heads-up, the tomcat credential (i.e. Secret named tomcat) appears to not have been redacted in the file you've uploaded to this ticket; we recommend you consider that password compromised.

pivotaljohn commented 2 years ago

@ramkrishna2k3 if you still need assistance with this issue, please feel free to comment here and we'll be notified.

For now, closing.