Kuberig

Kuberig

  • Docs
  • Blog
  • Help

›Resource Coding

Getting started

  • Intro
  • Quick Start
  • DSL Intro

Environments

  • Initializing an Environment
  • Managing Container Versions
  • Environment Support

Resource Coding

  • Coding Resources
  • Resource Grouping
  • Resource Apply Action
  • DSL Details

Code Samples

  • Defining a ConfigMap
  • Defining a Secret
  • Defining a Deployment
  • Defining a Service
  • Defining an Ingress

Reference

  • Configuration
  • Repository Organisation
  • Encryption Support
  • Service Account Setup

Coding Resources

KubeRig scans your Kotlin code for annotations. The main annotations are @EnvResource and @EnvResources.

From an @EnvResource annotated method you need to return a resource. From an @EnvResources annotated method you can emit multiple resources.

Additionally, there are the @EnvFilter, and the @Tick annotations.

Annotation Details

@EnvResource

You place the @EnvResource annotation on public methods. Inside the function you can use factory methods that match the kind name.

An example.

package example

import io.kuberig.annotations.EnvResource
import kinds.v1.ConfigMapDsl
import kinds.v1.configMap

class FirstResource {

    @EnvResource
    fun firstResource() : ConfigMapDsl {
        return configMap {
            metadata {
                name("first-resource")
            }
            data("some-key", "some-value")
        }
    }

}

The return type of the method must always come from inside the kinds package.

The @EnvResource annotation also has a group attribute that allows you to create groups of resources that you can deploy together. Check resource grouping for more information.

The @EnvResource annotation also has a action attribute that allows you to tweak how the resource is applied to the cluster. Check resource apply action for more information.

@EnvResources

You place the @EnvResources annotation on public methods. Inside the function you can use the DslResourceEmitter.emit function to emit resources.

An example.

package ingress

import io.kuberig.annotations.EnvResources
import io.kuberig.dsl.support.DslResourceEmitter.emit
import kinds.cert_manager.io.v1.issuer

class CertManagerResources {

    @EnvResources
    fun certManagerIssuer() {
        emit(
            issuer {
                metadata {
                    name("test-selfsigned")
                }
                spec {
                    selfSigned { }
                }
            }
        )
    }
}

You can call emit as many times as needed. You use the same factory methods that you would in an @EnvResource annotated method.

The @EnvResources annotation also has a group attribute that allows you to create groups of resources that you can deploy together. Check resource grouping for more information.

The @EnvResources annotation also has a defaultAction attribute that allows you to tweak how the resource is applied to the cluster. Check resource apply action for more information.

The emit method also has an applyActionOverwrite attribute that allows you to tweak how the emitted resources by that emit call are applied to the cluster. Check resource apply action for more information.

EnvFilter

The @EnvFilter annotation provides a way to select the environments the resource needs to be deployed to. Only needs to be added when the resource is not needed on all the environments.

An example.

package example

import io.kuberig.annotations.EnvFilter
import io.kuberig.annotations.EnvResource
import kinds.v1.ConfigMapDsl
import kinds.v1.configMap

class FirstResource {

    @EnvResource
    @EnvFilter(["dev", "test"])
    fun firstResource() : ConfigMapDsl {
        return configMap {
            metadata {
                name("first-resource")
            }
            data("some-key", "some-value")
        }
    }

}

@Tick

The @Tick annotation provides a way to do staged deployments. Methods without the @Tick annotation default to tick 1.

An example.

package example

import io.kuberig.annotations.EnvResource
import io.kuberig.annotations.Tick
import kinds.v1.ConfigMapDsl
import kinds.v1.configMap

class FirstResource {

    @EnvResource
    @Tick(10)
    fun firstResource() : ConfigMapDsl {
        return configMap {
            metadata {
                name("first-resource")
            }
            data("some-key", "some-value")
        }
    }

}

Related blogs

First blog on the topic of resource coding may also be of interest.

Last updated on 1/10/2021
← Environment SupportResource Grouping →
  • @EnvResource
  • @EnvResources
  • EnvFilter
  • @Tick
Kuberig
Docs
HomeQuick StartDSL Intro
Community
Stack OverflowDiscordTwitter
More
BlogGitHubStar
Follow @kuberigio
Copyright © 2021 Rigeldev BV