secret

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: 9 Imported by: 0

Documentation

Overview

Package secret provides functions for manipulating Secret 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 Secret as per the `Conf` struct passed and creates it in the cluster

Example
package main

import (
	"log"

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

var ownerObject interfaces.Object
var ownerReconcile interfaces.Reconcile

func main() {
	result, err := secret.Create(secret.Conf{
		// Instance is the pointer to owner object under which
		// Secret is being created.
		Instance: ownerObject,
		// OwnerReference can be used to tell if owner reference is
		// required to set on the secret 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 Secret. There are several
		// options defines in secret.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 Secret. This can be anonymous function like this or
		// can be defined somewhere else and just pass the name of the
		// function here. The secret.Conf struct can also accept
		// GenBinaryDataFunc which generates map of string to byte
		// slice.
		GenDataFunc: func(interfaces.Object) (map[string][]byte, error) {
			return map[string][]byte{"key": []byte("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 Secret object if it is not already in the cluster and updates the Secret if one exists.

func Delete

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

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

func GenerateSecret

func GenerateSecret(c Conf) (s *corev1.Secret, err error)

GenerateSecret generates Secret object as per the `Conf` struct passed. However, this does one special thing while generating Secret. StringData is merged into Data because of how Secrets are handled by Kubernetes. API Server never returns StringData field and converts it into Data. One might thing that is fine since API Server is already doing the conversion but the way this library manages Update will break if the generated object, Secret do not match the one in cluster. Merging the StringData ensures that if no genuine change is made then generated Secret will match the one in cluster.

func MaybeUpdate

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

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

func Update

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

Update generates the Secret as per the `Conf` struct passed and compares it with the in-cluster version. If required, it updates the in-cluster Secret with the changes. For comparing the Secrets, 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 Secret
	Instance interfaces.Object
	// Reconcile is the pointer to reconcile struct of owner object
	interfaces.Reconcile
	// Name of the Secret
	Name string
	// Namespace of the Secret
	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 Secret before creating it in cluster
	OwnerReference bool
	// MaybeUpdateFunc defines an update function with custom logic
	// for Secret update
	operation.MaybeUpdateFunc
	// AfterCreateFunc hook is called after creating the Secret
	operation.AfterCreateFunc
	// AfterUpdateFunc hook is called after updating the Secret
	operation.AfterUpdateFunc
	// AfterDeleteFunc hook is called after deleting the Secret
	operation.AfterDeleteFunc
	// GenSecretFunc defines a function to generate Secret object. The
	// package comes with a default generate function. This field can
	// be used to override the default function which is used by the
	// operation functions.
	GenSecretFunc
	// GenDataFunc defines a function to generate data for Secret
	GenDataFunc
	// GenBinaryDataFunc defines a function to generate binary data
	// for Secret
	GenStringDataFunc
	// Type defines the type of Secret
	Type string
}

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

type GenDataFunc

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

GenDataFunc defines a function which generates map of string to byte slice for `Data` field in Secret object

type GenSecretFunc

type GenSecretFunc func(Conf) (*corev1.Secret, error)

GenSecretFunc defiens a function which generates Service object.

type GenStringDataFunc

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

GenStringDataFunc defines a function which generates string map for `StringData` field in Secret object

Jump to

Keyboard shortcuts

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