registry

package
v0.0.0-...-2c282e7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

registration package for K8s client-go based tools/handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, name string, clientset *kubernetes.Clientset, namespace string) (interface{}, error)
	Executes a specific handler by name by implementing the core logic.
		- Looks up handler by name using Get().
       	- Calls handler.Execute() with provided parameters.

   	Args:
       ctx       - Context for cancellation/timeout control.
       name      - Name of the handler to execute.
       clientset - Kubernetes client for API interactions.
       namespace - Target namespace for handler operations.

   	Returns:
       - Handler output (interface{}) if execution succeeds.
       - Error if handler is not found or fails during execution.

   	Security:
       Ensure handler implementations avoid exposing sensitive
       Kubernetes data (e.g., Secret contents, credentials).

func List

func List() map[string]string
    Provides all registered handlers with their descriptions.
	Safe concurrent access via read lock.

  	Returns: A map where with hey as handler name and value as handler description.

  	Use Case:Useful for dynamically discovering available handlers
       (e.g., listing via CLI or API endpoints).

func Register

func Register(handler Handler)

Adds a new handler implementation to the global registry. - Acquires write lock for thread-safe registration. - Panics if a handler with the same name already exists. - Logs registration success to standard output. - Safe — does not execute handler logic, only stores references.

Args:An instance implementing the Handler interface.

Types

type Handler

type Handler interface {
	Name() string
	Execute(ctx context.Context, clientset *kubernetes.Clientset, namespace string) (interface{}, error)
	Description() string
}
	Defines a standard contract for all handler implementations
    that can be registered and executed via this registry.

   	Each handler must implement:
       - Name() string          → Returns a unique handler name.
       - Description() string   → Describes what the handler does.
       - Execute(...)           → Executes the handler logic.

func Get

func Get(name string) (Handler, error)
    Retrieves a registered handler by its unique name.
	Uses a read lock (RLock) to allow safe concurrent reads.

   	Args:
       name - The handler name to look up.

   	Returns:
       - Handler instance if found.
       - Error if handler name not found in registry.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}
	Manages all registered handler instances and provides
    thread-safe access and execution. Handlers can self-register
	at package init time, allowing for modular and extensible system design.

   Fields:
       - handlers : Map of handler name → handler instance.
       - mu       : RWMutex for concurrency-safe access.

Jump to

Keyboard shortcuts

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