controller

package
v0.0.0-...-11e986d Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

MIT License

Copyright (c) 2025 ngrok, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	FinalizerName = "k8s.ngrok.com/finalizer"
)

Variables

This section is empty.

Functions

func AddAnnotations

func AddAnnotations(o client.Object, annotations map[string]string)

AddAnnotations adds the given annotations to the object.

func AddFinalizer

func AddFinalizer(o client.Object) bool

AddFinalizer accepts an Object and adds the ngrok finalizer if not already present. It returns an indication of whether it updated the object's list of finalizers. It is our wrapper around controllerutil.AddFinalizer.

func CtrlResultForErr

func CtrlResultForErr(err error) (ctrl.Result, error)

CtrlResultForErr is a helper function to convert an error into a ctrl.Result passing through ngrok error mappings

func HasFinalizer

func HasFinalizer(o client.Object) bool

HasFinalizer returns true if the object has the ngrok finalizer present. It is our wrapper around controllerutil.ContainsFinalizer.

func IsDelete

func IsDelete(o client.Object) bool

IsDelete returns true if the object is being deleted. That is, if the deletion timestamp is set and non-zero.

func IsUpsert

func IsUpsert(o client.Object) bool

IsUpsert returns true if the object is being created or updated. That is, if the deletion timestamp is not set.

func RegisterAndSyncFinalizer

func RegisterAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error

RegisterAndSyncFinalizer adds the ngrok finalizer to the object if not already present. If it adds the finalizer, it updates the object in the Kubernetes API.

func RemoveAndSyncFinalizer

func RemoveAndSyncFinalizer(ctx context.Context, c client.Writer, o client.Object) error

RemoveAndSyncFinalizer removes the ngrok finalizer from the object if present. If it removes the finalizer, it updates the object in the Kubernetes API.

func RemoveFinalizer

func RemoveFinalizer(o client.Object) bool

RemoveFinalizer accepts an Object and removes the ngrok finalizer if present. It returns an indication of whether it updated the object's list of finalizers. It is our wrapper around controllerutil.RemoveFinalizer.

Types

type BaseController

type BaseController[T client.Object] struct {
	// Kube is the base client for interacting with the Kubernetes API
	Kube client.Client

	// Log is the logger for the controller
	Log logr.Logger

	// Recorder is the event recorder for the controller
	Recorder record.EventRecorder

	// Namespace is optional for controllers
	Namespace *string

	StatusID  func(obj T) string
	Create    func(ctx context.Context, obj T) error
	Update    func(ctx context.Context, obj T) error
	Delete    func(ctx context.Context, obj T) error
	ErrResult func(op BaseControllerOp, obj T, err error) (ctrl.Result, error)
}

BaseController is our standard pattern for writing controllers

Note: Non-provided methods are not called during reconcile

func (*BaseController[T]) NewEnqueueRequestForMapFunc

func (self *BaseController[T]) NewEnqueueRequestForMapFunc(f func(ctx context.Context, obj client.Object) []reconcile.Request) handler.EventHandler

NewEnqueueRequestForMapFunc wraps a map function to be used as an event handler. It also takes care to make sure that the controllers logger is passed through to the map function, so that we can use our common pattern of getting the logger from the context.

func (*BaseController[T]) Reconcile

func (self *BaseController[T]) Reconcile(ctx context.Context, req ctrl.Request, obj T) (ctrl.Result, error)

reconcile is the primary function that a manager calls for this controller to reconcile an event for the give client.Object

func (*BaseController[T]) ReconcileStatus

func (self *BaseController[T]) ReconcileStatus(ctx context.Context, obj T, origErr error) error

ReconcileStatus is a helper function to reconcile the status of an object and requeue on update errors Note: obj must be the latest resource version from k8s api

type BaseControllerOp

type BaseControllerOp int

BaseControllerOp is an enum for the different operations that can be performed by a BaseController

const (
	// createOp is the operation for creating a resource
	CreateOp BaseControllerOp = iota

	// updateOp is the operation for updating a resource (upsert)
	UpdateOp

	// deleteOp is the operation for deleting a resource (and finalizers)
	DeleteOp
)

type StatusError

type StatusError struct {
	// contains filtered or unexported fields
}

StatusError wraps .Status().*() errors returned from k8s client

func (StatusError) Error

func (e StatusError) Error() string

func (StatusError) Unwrap

func (e StatusError) Unwrap() error

Directories

Path Synopsis
MIT License
MIT License
MIT License
MIT License
MIT License
MIT License

Jump to

Keyboard shortcuts

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