handler

package
v0.0.0-...-7b17553 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var New = component.Declare(
	func(_ Args) string { return "webhook-handler" },
	func(_ Args, fs *flag.FlagSet) Options {
		return Options{
			ColdStartDelay: fs.Duration(
				"cold-start-delay",
				0,
				"delay period before the first update of an inactive PodProtector",
			),
			RetryBackoffBase: fs.Duration(
				"retry-backoff-base",
				time.Millisecond*100,
				"base retry period after a PodProtector update fails due to conflict",
			),
			RetryJitter: fs.Duration(
				"retry-jitter",
				time.Millisecond*100,
				"the actual retry backoff is uniformly distributed between [base, base+jitter)",
			),
		}
	},
	func(args Args, requests *component.DepRequests) Deps {
		return Deps{
			getSourceProvider: args.SourceProvider(requests),
			pprInformer: component.DepPtr(
				requests,
				pprutil.NewIndexedInformer(pprutil.IndexedInformerArgs{
					Suffix:         "",
					SourceProvider: args.SourceProvider,
					Elector:        optional.None[kube.ElectorArgs](),
				}),
			),
			observer:      o11y.Request[observer.Observer](requests),
			retrybatchObs: o11y.Request[retrybatchobserver.Observer](requests),
			defaultConfig: component.DepPtr(requests, defaultconfig.New(util.Empty{})),
		}
	},
	func(_ context.Context, _ Args, options Options, deps Deps) (*State, error) {
		sourceProvider := deps.getSourceProvider()

		poolReader, poolWriter := util.NewLateInit[retrybatch.Pool[pprutil.PodProtectorKey, BatchArg, pprutil.DisruptionResult]]()

		return &State{
			sourceProvider:    sourceProvider,
			informerHasSynced: deps.pprInformer.Get().HasSynced,
			poolConfig: retrybatch.NewPool(
				deps.retrybatchObs.Get(),
				PoolAdapter{
					sourceProvider: sourceProvider,
					pprInformer:    deps.pprInformer.Get(),
					observer:       deps.observer.Get(),
					clock:          clock.RealClock{},
					retryBackoff: func() time.Duration {
						return jitterDuration(
							*options.RetryBackoffBase,
							*options.RetryBackoffBase+*options.RetryJitter,
						)
					},
					defaultConfig: deps.defaultConfig.Get(),
				},
				*options.ColdStartDelay, batchGoroutineIdleTimeout,
			),
			poolWriter: poolWriter,
			poolReader: poolReader,
		}, nil
	},
	component.Lifecycle[Args, Options, Deps, State]{
		Start: func(ctx context.Context, _ *Args, _ *Options, _ *Deps, state *State) error {
			pool := state.poolConfig.Create(ctx)
			pool.StartMonitor(ctx)

			state.poolWriter(pool)

			return nil
		},
		Join:         nil,
		HealthChecks: nil,
	},
	func(d *component.Data[Args, Options, Deps, State]) Api {
		return Api{
			state:       d.State,
			observer:    d.Deps.observer.Get(),
			pprInformer: d.Deps.pprInformer.Get(),
		}
	},
)

Functions

This section is empty.

Types

type Api

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

func (Api) Handle

func (api Api) Handle(
	ctx context.Context,
	req *admissionv1.AdmissionRequest,
	cellId string,
	auditAnnotations map[string]string,
) HandleResult

type Args

type Args struct {
	SourceProvider pprutil.SourceProviderRequest
}

type BatchArg

type BatchArg = observer.BatchArg

Hack: another type alias to resolve import cycle issues.

type Deps

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

type HandleResult

type HandleResult struct {
	Status    observer.RequestStatus
	Rejection optional.Optional[Rejection]
	Err       error
}

type Options

type Options struct {
	ColdStartDelay   *time.Duration
	RetryBackoffBase *time.Duration
	RetryJitter      *time.Duration
}

type PoolAdapter

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

func (PoolAdapter) Execute

func (PoolAdapter) PoolName

func (PoolAdapter) PoolName() string

type Rejection

type Rejection struct {
	Code    uint16
	Message string
}

func (Rejection) ToStatus

func (rejection Rejection) ToStatus() *metav1.Status

type State

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

Jump to

Keyboard shortcuts

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