Documentation
¶
Overview ¶
Package secret provides functions for manipulating Secret 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 GenerateSecret(c Conf) (s *corev1.Secret, err error)
- func MaybeUpdate(original interfaces.Object, new interfaces.Object) (bool, error)
- func Update(c Conf) (reconcile.Result, error)
- type Conf
- type GenDataFunc
- type GenSecretFunc
- type GenStringDataFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
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 ¶
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 ¶
Delete generates the ObjectMeta for Secret as per the `Conf` struct passed and deletes it from the cluster
func GenerateSecret ¶
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 ¶
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 ¶
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