Hey, I have a `MultipleSourcesField` where I just ...
# plugins
r
Hey, I have a
MultipleSourcesField
where I just provide the
default
field. However, in
pants peek
no sources are listed, I just see
sources_raw
. Do I need to write custom code to hydrate the sources?
1
c
I would think the answer to that is no, so feels like something fishy is up.. what’s the output look like?
r
This is for a custom Helm plugin that works with our gitops process. Here's the sources_raw from pants peek
Copy code
"sources_raw": [
      "Chart.yaml",
      "Chart.yml",
      "values.yaml",
      "values.yml",
      "values.*.yaml",
      "values.*.yml",
      "templates/*.yaml",
      "templates/*.yml",
      "ci-state.yaml",
      "ci-state.yml",
      "ci-state.*.yaml",
      "ci-state.*.yml"
    ]
and this is the field
Copy code
class CustomHelmSourcesField(MultipleSourcesField):
    default = tuple(
        itertools.chain(
            *([f"{filename}.yaml", f"{filename}.yml"] for filename in ["Chart", "values", "values.*", "templates/*", "ci-state", "ci-state.*"])
        )
    )
    expected_file_extensions = (".yaml", ".yml", ".tpl")
👀 1
c
huh… mm, trying to see what we’re missing here. in the mean time, can’t help but to suggest a minor improvement to your generators:
Copy code
tuple(itertools.chain.from_iterable(["name1", "name2"] for filename in [...]))
🙏 1
what does your target class def look like?
peek is hydrating sources, so this should work given everything is wired properly..
r
Nothing out of the ordinary in my target class, in addition to the
CustomHelmSourcesField
there's the common target fields,
Dependencies
, and a few more custom
StringField
types.
c
do you have any files that the default globs would match for the defined target?
r
Yes, right now there is a
Chart.yaml
,
values.yaml
, and
values.dev.yaml
c
given that you get the raw sources field from peek, the target exists properl, but for some reason it seems to not pick them up.
r
in the same directory as
BUILD
Is the rule for hydrating sources implemented in python or rust?
r
I found the issue
multiple sources fields
I forgot one of the other fields was also a source field
c
Ah, sorry I didn’t ask that explicitly, was on my mind.
good find
I’ve noted this in the past, that having more than one source field will break in weird ways..
r
Do I need to create a custom hydrate sources or will something similar to this work? I'm assuming this is union ruled somewhere though it's not in this module.
c
if you merely need the sources from disk as-is, you don’t need to do anything extra.
I think… at least.
r
I actually need multiple sources fields. How can I get them to populate properly if I have 2?
c
admit the details are a bit hazy now I start looking at it
since pants assumes a single source field, I think the best you can do is have an intelligent source field, or hooking into codegen to pick up a second source field that techinically does not inherit from SourcesField.
for reference, you may look at how the
instructions
field for the
docker_image
target can act as a source field replacement.
while hydrating the sources for the
docker_image
the instructions rules creates a Dockerfile out of the field value, but could just as well pick up files from disk etc.
r
That would probably be an acceptable solution, but just to check all the boxes, the built-in
helm_chart
target does have multiple source fields. https://github.com/pantsbuild/pants/blob/7fb39c28ec9a289c35ff289eff95925ec19c574d/src/python/pants/backend/helm/target_types.py#L199-L200
c
Oh, ok. yea in that case it seems to work, I guess as long as they handle source hydration in that backend then…
so you should be able to mimic that then, perhaps 😉
q is how it works with
peek
etc.. not sure if that’s been looked at
r
will try real quick
c
@witty-family-13337 may be able to provide more insight there..
r
Interesting result
Copy code
sources": [
      "buildbarn/Chart.yaml"
    ],
    "sources_fingerprint": "f1ef2543a76d156d9b705ba40578031e44d580f715b703e1cdaccd47d729195f",
    "sources_raw": [
      "values.yaml",
      "values.yml",
      "templates/*.yaml",
      "templates/*.yml",
      "templates/*.tpl",
      "crds/*.yaml",
      "crds/*.yml"
    ],
w
it's interesting indeed, I never looked to deep into the behavior of
peek
in the Helm backend so I guess this can be considered an issue. I've been considering refactoring the Helm chart target into smaller targets, both of which with a single sources field, but for a different reason. This could be yet another reason to do so
r
The main thing I'm trying to get is get the
--changed-since
flag to work correctly.
w
yeah, I guess that would be an issue with the current implementation too
may I ask... what is the motivation for writing a custom plugin? is there anything that you need that isn't covered by current implementation (other than the discussed issue)?
r
We use ArgoCD so we don't ever actually install our charts, we just update a ref in a master reference repo and Argo handles the rest. The existing helm backend also tries to fully resolve a chart whenever it sees it, but our base charts are in private registries and it's a huge pain configuring them to pull locally.
w
fair enough
authenticating with private repositories/registries is an issue across the many backends, at this point each backend relies on the underlying tools' own mechanism, hopefully we can provide a more uniform and less painful way to solve this
👍 1