configmap

package
v0.0.0-...-a212bfd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package configmap provides functions for manipulating Configmap object in Kubernetes cluster.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(c Conf) (reconcile.Result, error)

Create generates the ConfigMap as per the `Conf` struct passed and creates it in the cluster

Example
package main

import (
	"log"

	"github.com/ankitrgadiya/operatorlib/pkg/configmap"
	"github.com/ankitrgadiya/operatorlib/pkg/interfaces"
)

var ownerObject interfaces.Object
var ownerReconcile interfaces.Reconcile

func main() {
	result, err := configmap.Create(configmap.Conf{
		// Instance is the pointer to owner object under which
		// Configmap is being created.
		Instance: ownerObject,
		// OwnerReference can be used to tell if owner reference is
		// required to set on the configmap object.
		OwnerReference: true,
		// Reconcile is the reconcile struct of the owner object which
		// implements the interfaces.Reconcile struct. For more
		// details check Reconcile interface documentation.
		Reconcile: ownerReconcile,
		// Name is the name of generated Configmap. There are several
		// options defines in configmap.Conf which can be used to
		// manipulate ObjectMeta of the generated object.
		Name: "cm-test",
		// GenDataFunc is the function that generates Data to be put
		// into Configmap. This can be anonymous function like this or
		// can be defined somewhere else and just pass the name of the
		// function here. The configmap.Conf struct can also accept
		// GenBinaryDataFunc which generates map of string to byte
		// slice.
		GenDataFunc: func(interfaces.Object) (map[string]string, error) {
			return map[string]string{"key": "value"}, nil
		},
	})
	if err != nil {
		log.Fatal(result, err)
	}
}
Output:

func CreateOrUpdate

func CreateOrUpdate(c Conf) (reconcile.Result, error)

CreateOrUpdate is a combination of `Create` and `Update` functions. It creates the ConfigMap object if it is not already in the cluster and updates the ConfigMap if one exists.

func Delete

func Delete(c Conf) (reconcile.Result, error)

Delete generates the ObjectMeta for ConfigMap as per the `Conf` struct passed and deletes it from the cluster

func GenerateConfigMap

func GenerateConfigMap(c Conf) (cm *corev1.ConfigMap, err error)

GenerateConfigMap generates ConfigMap object as per the `Conf` struct passed

func MaybeUpdate

func MaybeUpdate(original interfaces.Object, new interfaces.Object) (bool, error)

MaybeUpdate implements MaybeUpdateFunc for Configmap object. It compares the two Configmaps being passed and update the first one if required.

func Update

func Update(c Conf) (reconcile.Result, error)

Update generates the ConfigMap as per the `Conf` struct passed and compares it with the in-cluster version. If required, it updates the in-cluster ConfigMap with the changes. For comparing the ConfigMaps, it uses `MaybeUpdate` function by default but can also use `MaybeUpdateFunc` from `Conf` if passed.

Types

type Conf

type Conf struct {
	// Instance is the Owner object which manages the Configmap
	Instance interfaces.Object
	// Reconcile is the pointer to reconcile struct of owner object
	interfaces.Reconcile
	// Name of the Configmap
	Name string
	// Namespace of the Configmap
	Namespace string
	// GenLalebsFunc is used to generate labels for ObjectMeta
	meta.GenLabelsFunc
	// GenAnnotationsFunc is used to generate annotations for ObjectMeta
	meta.GenAnnotationsFunc
	// GenFinalizers is used to generate finalizers for ObjectMeta
	meta.GenFinalizersFunc
	// AppendLabels is used to determine if labels from Owner object
	// are to be inherited
	AppendLabels bool
	// OwnerReference is used to determine if owner reference needs to
	// be set on Configmap before creating it in cluster
	OwnerReference bool
	// MaybeUpdateFunc defines an update function with custom logic
	// for Configmap update
	operation.MaybeUpdateFunc
	// AfterCreateFunc hook is called after creating the Configmap
	operation.AfterCreateFunc
	// AfterUpdateFunc hook is called after updating the Configmap
	operation.AfterUpdateFunc
	// AfterDeleteFunc hook is called after deleting the Configmap
	operation.AfterDeleteFunc
	// GenConfigMapFunc defines a function to generate the Configmap
	// object. The package comes with default configmap generator
	// function which is used by operation functions. By specifying
	// this field, user can override the default function with a
	// custom one.
	GenConfigMapFunc
	// GenDataFunc defines a function to generate data for Configmap
	GenDataFunc
	// GenBinaryDataFunc defines a function to generate binary data
	// for Configmap
	GenBinaryDataFunc
}

Conf is used to pass parameters to functions in this package to perform operations on Configmap objects.

type GenBinaryDataFunc

type GenBinaryDataFunc func(interfaces.Object) (map[string][]byte, error)

GenBinaryDataFunc defines a function which generates binary data (map of string to byte slice) for Configmap.

type GenConfigMapFunc

type GenConfigMapFunc func(Conf) (*corev1.ConfigMap, error)

GenConfigMapFunc defines a function which generates ConfigMap.

type GenDataFunc

type GenDataFunc func(interfaces.Object) (map[string]string, error)

GenDataFunc defines a function which generates data (string map) for Configmap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL