Overboard


Working with metadata

Setting metadata like name, namespace, labels, and annotations are a common part of defining a Kubernetes resource.

// Using an inline metadata builder
k8s {
    deployment {
        metadata {
            name "my-name"
            ns "my-namespace" // `ns` used since namespace is a keyword in F#
            labels ["label1", "value1"]
            annotations ["annotation-key", "annotation-value"]
        }
    }
}

It is of course always possible to pass in a variable instead.

// Assign the builder result to a variable first
let meta = metadata {
            name "my-name"
            ns "my-namespace"
            labels ["label1", "value1"]
            annotations ["annotation-key", "annotation-value"]
        }
k8s {
    deployment {
        set_metadata meta
    }
}

A convention that is enabled is that you can set the metadata on a resource using any of the following operations _name, _namespace, _labels, and _annotations

// use the _ convention
k8s {
    deployment {
        _name "my-name"
        _namespace "my-namespace"
        _labels ["label1", "value1"]
        _annotations ["annotation-key", "annotation-value"]
    }
}

Another convention is that instead of using _name you can drop a string into the body of most resources and it will be assigned to the metadata.name property. This also works for some data that does not have metadata but has a name property.

// use the _ convention
k8s {
    deployment {
        "my-name" // <- No operation specified
        _labels ["label1", "value1"]
    }
}

One last neat trick for metadata and many other resources is that you can just drop the variable into the body of the builder. For this to work, the type of the variable must be unique to a single field on the builder.

let deploymentMetadata = 
        metadata {
            name "my-name"
            ns "my-namespace"
            labels ["label1", "value1"]
            annotations ["annotation-key", "annotation-value"]
        }

// use the _ convention
k8s {
    deployment {
        deploymentMetadata // <- just drop the variable in the resource expression
    }
}

So there are many ways to define your metadata. I suggest you decide for one on your project and use that method throughout.

namespace Overboard
namespace Overboard.Common
namespace Overboard.Workload
val k8s: K8sBuilder
val deployment: DeploymentBuilder
val metadata: MetadataBuilder
custom operation: name (string) Calls MetadataBuilder.Name
custom operation: ns (string) Calls MetadataBuilder.Namespace
custom operation: labels ((string * string) list) Calls MetadataBuilder.Labels
custom operation: annotations ((string * string) list) Calls MetadataBuilder.Annotations
val meta: Metadata
custom operation: set_metadata (Metadata) Calls DeploymentBuilder.SetMetadata
<summary> Sets the Deployment metadata </summary>
custom operation: _name (string) Calls DeploymentBuilder.Name
<summary> Name of the Deployment. Name must be unique within a namespace. https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/object-meta/#ObjectMeta </summary>
custom operation: _namespace (string) Calls DeploymentBuilder.Namespace
<summary> Namespace of the Deployment. Namespace defines the space within which each name must be unique. Default is "default". https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/object-meta/#ObjectMeta </summary>
custom operation: _labels ((string * string) list) Calls DeploymentBuilder.Labels
<summary> Labels for the Deployment </summary>
custom operation: _annotations ((string * string) list) Calls DeploymentBuilder.Annotations
<summary> Annotations for the Deployment </summary>
val deploymentMetadata: Metadata