Overboard


Generating Kubernetes config

Overboard gives a powerful way to define your Kubernetes config but for that to be useful, we need to generate the kubernetes config. Overboard provides some helpers for doing just this in KubeCtlWriter.

let kubeConfig = k8s {
    deployment {
        "my-name" // <- No operation specified
        _labels ["label1", "value1"]
    }
}

Printing to screen

If you would like to see what is generated on your screen you can use the print function.

Note that the print also prints any validation errors.

KubeCtlWriter.print kubeConfig
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    label1: value1
  name: my-name
  namespace: default
spec:
  minReadySeconds: 0
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  template: {}

Writing to file

If you would like to save your K8s config to file, you can use either the KubeCtlWriter.toJsonFile or KubeCtlWriter.toYamlFile function. As the names imply, these will save your config as JSON or YAML respectively.

KubeCtlWriter.toYamlFile kubeConfig "deployment.yaml"

Getting the content

You can also get the K8sOutput, which gives you access to not only the JSON or YAML K8sOutput.content, but also to the K8sOutput.errors. This is an array of validation errors that Overboard has found in the schema. Overboard prevents many schema issues by being strongly typed but it also runs validation on values that should not be empty or should follow certain formatting. It will still generate the config you specify but gives you errors that you can check before submitting the config to a Kubernetes cluster.

let k8sOutput = KubeCtlWriter.toYaml kubeConfig
makeYaml k8sOutput.content
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    label1: value1
  name: my-name
  namespace: default
spec:
  minReadySeconds: 0
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  template: {}

Validation errors

As mentioned, K8sOutput contains an errors field that contains a list of validation errors.

Each ValidationProblem has a Message field on it that gives back a string. You can print these errors out:

k8sOutput.errors 
|> List.map (fun err -> err.Message)
|> List.iter (eprintfn "%s")
val makeYaml: text: 'a -> string
val text: 'a
namespace Overboard
namespace Overboard.Common
namespace Overboard.Workload
val kubeConfig: K8s
val k8s: K8sBuilder
val deployment: DeploymentBuilder
custom operation: _labels ((string * string) list) Calls DeploymentBuilder.Labels
<summary> Labels for the Deployment </summary>
module KubeCtlWriter from Overboard.K8s
val print: k8s: K8s -> unit
val k8sOutput': K8sOutput
val toYaml: k8s: K8s -> K8sOutput
K8sOutput.content: string
val k8sOutput: K8sOutput
K8sOutput.errors: ValidationProblem list
Multiple items
module List from Microsoft.FSharp.Collections
<summary>Contains operations for working with values of type <see cref="T:Microsoft.FSharp.Collections.list`1" />.</summary>
<namespacedoc><summary>Operations for collections such as lists, arrays, sets, maps and sequences. See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/fsharp-collection-types">F# Collection Types</a> in the F# Language Guide. </summary></namespacedoc>


--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
<summary>The type of immutable singly-linked lists.</summary>
<remarks>Use the constructors <c>[]</c> and <c>::</c> (infix) to create values of this type, or the notation <c>[1;2;3]</c>. Use the values in the <c>List</c> module to manipulate values of this type, or pattern match against the values directly. </remarks>
<exclude />
val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
<summary>Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection.</summary>
<param name="mapping">The function to transform elements from the input list.</param>
<param name="list">The input list.</param>
<returns>The list of transformed elements.</returns>
<example id="map-1"><code lang="fsharp"> let inputs = [ "a"; "bbb"; "cc" ] inputs |&gt; List.map (fun x -&gt; x.Length) </code> Evaluates to <c>[ 1; 3; 2 ]</c></example>
val err: ValidationProblem
property ValidationProblem.Message: string with get
val iter: action: ('T -> unit) -> list: 'T list -> unit
<summary>Applies the given function to each element of the collection.</summary>
<param name="action">The function to apply to elements from the input list.</param>
<param name="list">The input list.</param>
<example id="iter-1"><code lang="fsharp"> let inputs = [ "a"; "b"; "c" ] inputs |&gt; List.iter (printfn "%s") </code> Evaluates to <c>unit</c> and prints <code lang="fsharp"> a b c </code> in the console. </example>
val eprintfn: format: Printf.TextWriterFormat<'T> -> 'T
<summary>Print to <c>stderr</c> using the given format, and add a newline.</summary>
<param name="format">The formatter.</param>
<returns>The formatted result.</returns>
<example>See <c>Printf.eprintfn</c> (link: <see cref="M:Microsoft.FSharp.Core.PrintfModule.PrintFormatLineToError``1" />) for examples.</example>