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

Support ytt (or don't lose it when a file has ytt annotations) #2033

Open
emmjohnson opened this issue May 8, 2024 · 1 comment
Open

Support ytt (or don't lose it when a file has ytt annotations) #2033

emmjohnson opened this issue May 8, 2024 · 1 comment

Comments

@emmjohnson
Copy link

Please describe your feature request.
I wish I could use yq to evaluate a file with ytt annotations

Describe the solution you'd like
If we have input.yml like:
(please keep to around 10 lines )

#@ load("@ytt:data", "data")
#@ load("@ytt:template", "template")
#@ load("@env_vars:feature_flag.lib.yaml", "feature_flag_env_vars")
#@ load("@env_vars:database.lib.yaml", "database_env_vars")
#@ load("@env_vars:rabbitmq.lib.yaml", "rabbitmq_env_vars")

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grylls
spec:
  template:
    spec:
      containers:
        - name: grylls
          image: #@ data.values.image_id
          ports:
            - containerPort: 80
          env:
            - name: GRYLLS_METRIC_PORT
              value: "8080"

            -  #@ template.replace(feature_flag_env_vars())

            - name: DRY_RUN
              value: "false"

            -  #@ template.replace(database_env_vars())
            -  #@ template.replace(rabbitmq_env_vars())

          resources:
            limits:
              memory: 3600Mi
            requests:
              cpu: "1.5"
              memory: 1700Mi

And in my go app, I run:

evaluator := yqlib.NewStringEvaluator()
operation := `select(.kind == "Deployment").spec.template.spec.containers.0.resources.limits.memory = "2Mi"`
fileContent, err = evaluator.Evaluate(operation, fileContent, encoder, decoder)

it could output

#@ load("@ytt:data", "data")
#@ load("@ytt:template", "template")
#@ load("@env_vars:feature_flag.lib.yaml", "feature_flag_env_vars")
#@ load("@env_vars:database.lib.yaml", "database_env_vars")
#@ load("@env_vars:rabbitmq.lib.yaml", "rabbitmq_env_vars")

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grylls
spec:
  template:
    spec:
      containers:
        - name: grylls
          image: #@ data.values.image_id
          ports:
            - containerPort: 80
          env:
            - name: GRYLLS_METRIC_PORT
              value: "8080"

            -  #@ template.replace(feature_flag_env_vars())

            - name: DRY_RUN
              value: "false"

            -  #@ template.replace(database_env_vars())
            -  #@ template.replace(rabbitmq_env_vars())

          resources:
            limits:
              memory: 2Mi
            requests:
              cpu: "1.5"
              memory: 1700Mi

Currently, it moves ytt on to new lines -

#@ load("@ytt:data", "data")
#@ load("@ytt:template", "template")
#@ load("@env_vars:feature_flag.lib.yaml", "feature_flag_env_vars")
#@ load("@env_vars:database.lib.yaml", "database_env_vars")
#@ load("@env_vars:rabbitmq.lib.yaml", "rabbitmq_env_vars")

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grylls
spec:
  template:
    spec:
      containers:
        - name: grylls
          image: #@ data.values.image_id
          ports:
            - containerPort: 80
          env:
            - name: GRYLLS_METRIC_PORT
              value: "8080"
            -
            #@ template.replace(feature_flag_env_vars())
            - name: DRY_RUN
              value: "false"
            -
            -
          #@ template.replace(rabbitmq_env_vars())

          #@ template.replace(database_env_vars())
          resources:
            limits:
              memory: 2Mi
            requests:
              cpu: "1.5"
              memory: 1700Mi

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@emmjohnson emmjohnson changed the title Support ytt (or don't lose it when a file has ytt) Support ytt (or don't lose it when a file has ytt annotations) May 8, 2024
@emmjohnson
Copy link
Author

Its possible this is a dupe of #1976

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant