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

Creator: The `config` section

Tako Schotanus edited this page Apr 3, 2020 · 6 revisions

If you are here it's assumed that you've at least read HOWTO Create a Generator. If not it's best you do so first otherwise what we have to tell you won't make a lot of sense.

When reading through the HOWTos we can see it seems pretty easy to make things work. You create a directory, some files that get copied and an info.yaml file that might look like this:

type: generator
config:
  base: runtime-vertx

While others might have more or different properties. So, what's that about? What can a Generator actually do?

Well, that's a good question, so let's start what Generators can do by default:

Default Generator Actions

Any non-custom Generator performs, or tries to perform, the following list of actions (in order):

⚠️ Any properties mentioned from now on are assumed to be children of the config section. Also if the property mentioned does not exist the action does not take place unless stated otherwise.

  1. First applies the Generator mentioned in the base property
  2. Checks if this Generator was already applied before, if so it skips to item 20
  3. Adds the Resources for the application image mentioned in the image property
  4. Applies the runtime-base-support Generator if this is a Runtime Generator
  5. Copies the entire contents of the files folder to the target project
  6. Copies the entire contents of the files-VERSION folder to the target project, where VERSION would be the same as the runtime.version value passed to the Generator in the properties
  7. Applies the maven-setup Generator if a pom.xml file was found in the root of files folder
  8. Merges the file merge/pom.xml with the pom.xml file in the root of the target project
  9. Merges any merge-VERSION/pom.xml files with the pom.xml file in the root of the target project, where VERSION would be the same as the runtime.version value passed to the Generator in the properties
  10. Merges the file merge/package.json with the package.json file in the root of the target project
  11. Merges the file merge-VERSION/package.json with the package.json file in the root of the target project, where VERSION would be the same as the runtime.version value passed to the Generator in the properties
  12. Sets the default Readiness Probe for the K8s/OpenShift service (by default a GET /health). This can be overridden by using the readinessProbe property. This can either be a string containing a different URL to check, or an object containing the Resource Definitions to insert directly. See Define Readiness Probes.
  13. The same as the previous point, but for the Liveness Probe. See Define Liveness Probes.
  14. Sets the service's CPU limit using the value from cpuLimit
  15. Sets the service's memory limit using the value from memoryLimit
  16. Reads any Yaml files from the resources folder and adds their contents to the project resources (it actually first runs a cases transformation on their contents)
  17. Reads any Yaml files from the resources-VERSION folder, where VERSION would be the same as the runtime.version value passed to the Generator in the properties, and adds their contents to the project resources (it actually first runs a cases transformation on their contents)
  18. Takes any actions defined in the moreActions section and executes them
  19. Checks the property transformFiles for a list of file patterns. Any files in the target project that match any of those patterns will be transformed using the cases transformer.
  20. Adds the values defined in props.env to the service's build and runtime environments (resp. in the BuildConfig and DeploymentConfig)
  21. Takes any actions defined in the actionsAlways section and executes them
  22. Adds the values defined in extra to the properties returned by the Generator to its caller

As you can see Generators can do a whole bunch of things by default!

It might seem somewhat overwhelming but those actions really just boil down to three things:

  • Copy and change files
  • Add resources (as in K8s Resource Definitions)
  • Delegate some of the first two points to another Generator

Not so complicated now, right?

Well not so fast. We're not done yet. There's still one other property to mention.

Determine your own Actions to run

If the property actions exists none of the default actions will be executed and the above list will become much shorter:

  1. Takes any actions defined in the actions section and executes them
  2. Takes any actions defined in the actionsAlways section and executes them
  3. Adds the values defined in extra to the properties returned by the Generator to its caller

Executing specific Actions

All the actions mentioned above can also be executed independently and can often be configured in several way to behave differently.

An action in its simplest form looks like this:

actions:
- action: "NAME"

Any other properties that are found in the same object will be passed on the the action while it executes.

actions:
- action: "NAME"
  any: dummy
  other: dummy
  props: dummy

So what actions are available?

Available Actions

Name Function Arguments
apply Apply another Generator generator - The name of the Generator to apply
copy Copy files from - Source directory (in Generator, default files)
to - Target directory (in project)
move Move a file from - Source file (in project)
to - Target file (in project)
transform Transforms files files - File pattern (in project)
... - See The transform Action for more information
mergePoms Merges two Maven POM files from - Source POM (in Generator, default merge/pom.xml)
to - Target POM (in project, default pom.xml)
mergePackageJson Merges two Nodejs Package files from - Source JSON (in Generator, default merge/package.json)
to - Target JSON (in project, default package.xml)
route Creates a Route for the Service name - The name for the Route (default routeName from the properties)

Further Reading