Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Add --allow_unused_images resolver flag #161

Closed
calder opened this issue Jul 15, 2018 · 4 comments · Fixed by #162
Closed

Add --allow_unused_images resolver flag #161

calder opened this issue Jul 15, 2018 · 4 comments · Fixed by #162
Assignees

Comments

@calder
Copy link
Contributor

calder commented Jul 15, 2018

Background

Some macros will instantiate k8s_object(...) multiple times with different SKUs. When an image is only used by some SKUs and not others, the default resolver dies when it doesn't find the image in a particular SKU's template:

rules_k8s/k8s/resolver.py

Lines 190 to 195 in 4348f8e

if len(unseen_strings) > 0:
print('ERROR: The following image references were not found in %r:' %
args.template, file=sys.stderr)
for ref in unseen_strings:
print(' %s' % ref, file=sys.stderr)
sys.exit(1)

For cases like this, it would be nice to be able to relax the unused image error.

Proposal

Add an --allow_unused_images flag to resolver.py. Add a resolver_args parameter to k8s_object that allows arguments to be passed directly to the resolver. This would be useful for custom resolvers as well.

@calder calder changed the title Add --allow_unused_images resolver arg, and support for passing it Add --allow_unused_images resolver arg, and support for passing custom args to resolvers Jul 15, 2018
@calder calder changed the title Add --allow_unused_images resolver arg, and support for passing custom args to resolvers Add --allow_unused_images resolver arg Jul 15, 2018
@calder calder changed the title Add --allow_unused_images resolver arg Add --allow_unused_images resolver flag Jul 15, 2018
@fejta
Copy link
Contributor

fejta commented Jul 18, 2018

Can you give a concrete example of what you mean by multiple SKUs?

The image reference not found is usually an important safeguard against launching the wrong image and image typos.

@fejta
Copy link
Contributor

fejta commented Jul 18, 2018

/assign

@calder
Copy link
Contributor Author

calder commented Jul 18, 2018

As a safeguard, it's a bit like a very sturdy guard rail on only one side of a road with cliffs on both sides. :-) (See #147) However, this change still leaves the guard rail on by default and just allows it to be disabled when it's more trouble than its worth.

Example: Let's say you want to generate deployment targets for the same service across multiple environments. To do this:

  1. You describe environments in Jsonnet files that are compiled to JSON files by jsonnet_to_json targets.
  2. You describe services in Jsonnet files that can consume configuration from the current environment.
  3. To generate all deployment targets, you invoke a single macro with your service's Jsonnet file, a list of environments, and a list of image dependencies. The macro generates a jsonnet_to_json and k8s_object rule for each environment.

The problem arises when a service uses an image in only some environments. This is pretty common in test vs. production environments. In this case the k8s_object targets will fail in environments that don't use a listed image.

@calder
Copy link
Contributor Author

calder commented Jul 21, 2018

@fejta: Friendly ping!

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

Successfully merging a pull request may close this issue.

2 participants