mainhelper

package
v0.0.0-...-d19fc40 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mainhelper provides helper functions for common boilerplate code in writing a main function such as setting up kube informers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessEnvConfigOrDie

func ProcessEnvConfigOrDie(env interface{})

ProcessEnvConfigOrDie retrieves environment variables.

func ProcessGCPProfilerEnvConfigOrDie

func ProcessGCPProfilerEnvConfigOrDie(component string, logger *zap.SugaredLogger)

ProcessGCPProfilerEnvConfigOrDie tries to enable the GCP Profiler if env vars have configured it.

func RunProfilingServer

func RunProfilingServer(ctx context.Context, logger *zap.SugaredLogger, h *pkgprofiling.Handler)

RunProfilingServer starts a profiling server.

Types

type InitOption

type InitOption func(*initArgs)
var WithKubeFakes InitOption = func(args *initArgs) {
	args.injection = injection.Fake

	args.kubeConfig = &rest.Config{}
	args.skipK8sVersionCheck = true
}

WithKubeFakes uses knative injections fakes for any k8s related setup. This is used in tests.

func WithContext

func WithContext(ctx context.Context) InitOption

WithContext specifies the context to use.

func WithEnv

func WithEnv(env interface{}) InitOption

WithEnv specifies a pointer to an envConfig struct.

func WithMetricNamespace

func WithMetricNamespace(metricNamespace string) InitOption

WithMetricNamespace specifies the metric namespace to use.

type InitRes

type InitRes struct {
	Logger     *zap.SugaredLogger
	KubeClient kubernetes.Interface
	CMPWatcher configmap.Watcher
	Cleanup    func()
}

InitRes holds a collection of objects after init for convenient access by other custom logic in the main function.

func Init

func Init(component string, opts ...InitOption) (context.Context, *InitRes)

Init runs common logic in starting a main function, similar to sharedmain. it returns a result object that contains useful artifacts for later use. Unlike sharedmain.Main, Init is meant to be run as a helper function in any main functions, while sharedmain.Main runs controllers with predefined method signatures.

When a command is converted to use this function, please update the list of commands that support profiling in docs/development/profiling.md.

Jump to

Keyboard shortcuts

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