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

Sorry, but I just can't figure it out with overlays #917

Open
scastria opened this issue Jun 9, 2024 · 3 comments
Open

Sorry, but I just can't figure it out with overlays #917

scastria opened this issue Jun 9, 2024 · 3 comments
Labels
helping with an issue Debugging happening to identify the problem

Comments

@scastria
Copy link

scastria commented Jun 9, 2024

I have watched the primer youtube video, but I don't think any of those examples apply to my situation. I am trying to add a map item to ONLY the Plan_Containers_development step without using hardcoded indexes since the Plan_Containers_development step could be anywhere. The issue, I think, is that I have arrays of maps of arrays of maps of maps.

My source yaml is:

image:
  name: image:1234

pipelines:
  branches:
    dynamic:
      - parallel:
        - step:
            name: build_generic
        - step:
            name: build_containers
        - step:
            name: build_lambdas
        - step:
            name: publish_docs
      - parallel:
        - step:
            name: 'Plan_Containers_development'
            deployment: 'development_containers_plan'
        - step:
            name: 'Plan_Containers_stage'
            deployment: 'stage_containers_plan'
        - step:
            name: 'Plan_Containers_production'
            deployment: 'production_containers_plan'
      - parallel:
        - step:
            name: 'Apply_Containers_development'
            deployment: 'development_containers_apply'
            trigger: 'automatic'
        - step:
            name: 'Apply_Containers_stage'
            deployment: 'stage_containers_apply'
        - step:
            name: 'Apply_Containers_production'
            deployment: 'production_containers_apply'

My current overlay is:

#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
pipelines:
  branches:
    #@overlay/match by=overlay.all
    _:
      #@overlay/match by=overlay.all, expects="0+"
      - parallel:
        #@overlay/match by=overlay.all, expects="0+"
        -
          #@overlay/match by=overlay.subset({"name": "Plan_Containers_development"}), missing_ok=True
          step:
            new: "value"
@scastria scastria added the carvel triage This issue has not yet been triaged for relevance label Jun 9, 2024
@scastria
Copy link
Author

scastria commented Jun 9, 2024

I CAN get it to work if I use hardcoded indicies which I would like to avoid:

#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
pipelines:
  branches:
    #@overlay/match by=overlay.all
    _:
      #@overlay/match by=overlay.index(1)
      - parallel:
        #@overlay/match by=overlay.index(0)
        - step:
            #@overlay/match missing_ok=True
            new: "value"

@scastria
Copy link
Author

This seems to work by using a custom matcher function, but is this efficient? Plus, I would like to match on other step names. Is there a way to reuse my matcher function but pass in a fourth parameter on what step name to look for?

#@ load("@ytt:overlay", "overlay")

#@ def parallel(i, l, r):
#@   for s in l["parallel"]:
#@     if s["step"]["name"] == "Plan_Containers_development":
#@       return True
#@     end
#@   end
#@   return False
#@ end
#@ def step(i, l, r):
#@   return l["step"]["name"] == "Plan_Containers_development"
#@ end

#@overlay/match by=overlay.all
---
pipelines:
  branches:
    #@overlay/match by=overlay.all
    _:
      #@overlay/match by=parallel
      - parallel:
        #@overlay/match by=step
        - step:
            #@overlay/match missing_ok=True
            new: "value"

@prembhaskal
Copy link
Contributor

@scastria You can pass stepname using closure. I will see if this can be done in a better way somehow.

#@ load("@ytt:overlay", "overlay")

#@ def parallelc(stepname):
#@   def parallel(i, l, r):
#@     for s in l["parallel"]:
#@       if s["step"]["name"] == stepname:
#@         return True
#@       end
#@     end
#@     return False
#@   end
#@   return parallel
#@ end
#@ def stepc(stepname):
#@   def step(i, l, r):
#@     return l["step"]["name"] == stepname
#@   end
#@  return step
#@ end

#@overlay/match by=overlay.all
---
pipelines:
  branches:
    #@overlay/match by=overlay.all
    _:
      #@overlay/match by=parallelc("Plan_Containers_development")
      - parallel:
        #@overlay/match by=stepc("Plan_Containers_development")
        - step:
            #@overlay/match missing_ok=True
            new: "value"

@renuy renuy added helping with an issue Debugging happening to identify the problem and removed carvel triage This issue has not yet been triaged for relevance labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
helping with an issue Debugging happening to identify the problem
Projects
Status: Unprioritized
Development

No branches or pull requests

3 participants