Skip to content

Resource helpers

Gregory Nickonov edited this page Mar 1, 2019 · 1 revision

Resource helpers are methods that can be defined for the specific resource kinds to extend the functionality of those kinds. The syntax is R.define_helper NAME [, RESOURCE, RESOURCE, ...] do |r| ... end, where NAME is the name of the helper and RESOURCE is the resource kind that will receive the helper.

Let's imagine that we would like to label some of the ConfigMaps or Secrets with the application label. We know that not all of the ConfigMaps or Secrets should be marked, so we can not use Resource initializer, but we don't want to repeat the same code either, so we define a helper:

R.define_helper :add_application_label, :config_map, :secret do |r|
  r.metadata.add_label application: :hello
end

Now we can use that helper in actual resource definition:

R.config_map :frontend do
  add_application_label

  set BACKEND_URL: 'http://backend'
end
Clone this wiki locally