Documentation ¶
Overview ¶
Package configmap provides functions for manipulating Configmap object in Kubernetes cluster.
Index ¶
- func Create(c Conf) (reconcile.Result, error)
- func CreateOrUpdate(c Conf) (reconcile.Result, error)
- func Delete(c Conf) (reconcile.Result, error)
- func GenerateConfigMap(c Conf) (cm *corev1.ConfigMap, err error)
- func MaybeUpdate(original interfaces.Object, new interfaces.Object) (bool, error)
- func Update(c Conf) (reconcile.Result, error)
- type Conf
- type GenBinaryDataFunc
- type GenConfigMapFunc
- type GenDataFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
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 ¶
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 ¶
Delete generates the ObjectMeta for ConfigMap as per the `Conf` struct passed and deletes it from the cluster
func GenerateConfigMap ¶
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 ¶
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 ¶
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.