singleton

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 12 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIServerConfig = NewSingleton[*server.Config](nil)

APIServerConfig the global server.Config for APIServer to use

View Source
var DynamicClient = NewSingletonE[dynamic.Interface](func() (dynamic.Interface, error) {
	return dynamic.NewForConfig(KubeConfig.Get())
})

DynamicClient .

GenericAPIServer .

View Source
var KubeClient = NewSingletonE[client.Client](func() (client.Client, error) {
	return client.New(KubeConfig.Get(), client.Options{
		Scheme: scheme.Scheme,
		Mapper: RESTMapper.Get(),
	})
})

KubeClient .

View Source
var KubeConfig = NewSingleton[*rest.Config](func() *rest.Config {
	cfg := config.GetConfigOrDie()
	cfg.UserAgent = UserAgent.Get()
	return cfg
})

KubeConfig .

RESTMapper .

StaticClient .

View Source
var UserAgent = NewSingleton[string](nil)

UserAgent .

Functions

func InitGenericAPIServer

func InitGenericAPIServer(server *builder.GenericAPIServer) *builder.GenericAPIServer

InitGenericAPIServer load the global unique GenericAPIServer

func InitServerConfig

func InitServerConfig(config *server.RecommendedConfig) *server.RecommendedConfig

InitServerConfig initialize APIServerConfig

func ReloadClients

func ReloadClients()

ReloadClients should be called when KubeConfig is called to update related clients

Types

type Singleton

type Singleton[T any] struct {
	// contains filtered or unexported fields
}

Singleton global unique data struct

func NewSingleton

func NewSingleton[T any](loader func() T) *Singleton[T]

NewSingleton create a new singleton with loader

func NewSingletonE

func NewSingletonE[T any](loaderE func() (T, error)) *Singleton[T]

NewSingletonE create a new singleton with error-returned loader

func (*Singleton[T]) Get

func (in *Singleton[T]) Get() T

Get retrieve underlying data, if not initialized, will trigger initialization

func (*Singleton[T]) Reload

func (in *Singleton[T]) Reload()

Reload trigger loader

func (*Singleton[T]) Set

func (in *Singleton[T]) Set(data T)

Set write the underlying data

Jump to

Keyboard shortcuts

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