utils

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

Operator SDK Utils



This repository contains a Go module with utilities to build Kubernetes Operators using the Operator SDK.

Requirements

  • Operator SDK
  • Go (Version >=1.20)

Usage

Install the Go module:

go get github.com/cedrichopf/operator-utils
Utils Package

The utils package contains reconcile functions for many Kubernetes objects. While reconciling, the given object will be either created or updated.

Additionally, the function will add a revision hash of the current object configuration as a label to the object. Once the function is called again, the current active object can be easily compared with the expected object using the provided revision hash.

Example:

func() {
  service := &corev1.Service{
    ObjectMeta: metav1.ObjectMeta{
      Name:      "example-service",
      Namespace: "default",
    },
    Spec: corev1.ServiceSpec{
      Ports: []corev1.ServicePort{
        {
          Port: 3000,
        },
      },
    },
  }

  result, err := utils.ReconcileConfigMap(ctx, service, owner, r.Client, r.Scheme)
  if err != nil {
    log.Println(err)
  }

  if result.Updated {
    log.Println("Object has been updated")
  }
}
Hash Package

The hash package contains functions to generate a revision hash and the related label for a given object.

Network Package

The network package contains functions to check and verify network functionalities. E.g. checking if a host is resolvable over DNS.

License

This project is licensed under Apache-2.0 license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteResources

func DeleteResources(ctx context.Context, client client.Client, objects []client.Object) error

DeleteResources takes a slice of Kubernetes objects and deletes them from a Kubernetes cluster

DeleteResources returns an error if it fails to delete the object

func RemoveFinalizer

func RemoveFinalizer(object metav1.Object, finalizer string) bool

RemoveFinalizer deletes a given finalizer from a Kubernetes object

RemoveFinalizer returns a bool value that indicates if the given finalizer has been removed

Types

type ReconcileParams

type ReconcileParams struct {
	Context  context.Context
	Client   client.Client
	Scheme   *runtime.Scheme
	Expected client.Object
	Owner    metav1.Object
	// contains filtered or unexported fields
}

ReconcileParams contains all required information to reconcile an object

type ReconcileResult

type ReconcileResult struct {
	Updated      bool
	Requeue      bool
	RequeueAfter time.Duration
}

ReconcileResult contains information about a reconciled resource.

Updated shows that the reconciled resource has been updated on the Kubernetes cluster. Requeue shows that the operator should requeue the current reconcile. RequeueAfter provides a timeout which should be used by the operator to requeue the current reconcile.

func ReconcileConfigMap

func ReconcileConfigMap(ctx context.Context, expected *corev1.ConfigMap, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileConfigMap takes a ConfigMap and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileConfigMap returns a ReconcileResult and nil. A failed ReconcileConfigMap returns an empty ReconsileResult and an error.

func ReconcileDeployment

func ReconcileDeployment(ctx context.Context, expected *appsv1.Deployment, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileDeployment takes a Deployment and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileDeployment returns a ReconcileResult and nil. A failed ReconcileDeployment returns an empty ReconsileResult and an error.

func ReconcileIngress

func ReconcileIngress(ctx context.Context, expected *networkingv1.Ingress, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileIngress takes an Ingress and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileIngress returns a ReconcileResult and nil. A failed ReconcileIngress returns an empty ReconsileResult and an error.

func ReconcileSecret

func ReconcileSecret(ctx context.Context, expected *corev1.Secret, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileSecret takes a Secret and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileSecret returns a ReconcileResult and nil. A failed ReconcileSecret returns an empty ReconsileResult and an error.

func ReconcileService

func ReconcileService(ctx context.Context, expected *corev1.Service, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileService takes a Service and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileService returns a ReconcileResult and nil. A failed ReconcileService returns an empty ReconsileResult and an error.

func ReconcileStatefulSet

func ReconcileStatefulSet(ctx context.Context, expected *appsv1.StatefulSet, owner metav1.Object, client client.Client, scheme *runtime.Scheme) (ReconcileResult, error)

ReconcileStatefulSet takes a StatefulSet and creates or updates it on a Kubernetes cluster. It will generate a revision hash that will be added to the object as a label and add the controller reference to the given owner object.

A successful ReconcileStatefulSet returns a ReconcileResult and nil. A failed ReconcileStatefulSet returns an empty ReconsileResult and an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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