config

package
v2.11.26 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// EmptySpaceError is the message returned if the user hasn't targed a space.
	EmptySpaceError = "no space targeted, use 'kf target --space SPACE' to target a space"

	// SkipVersionCheckAnnotation can be set on commands to prevent the version
	// check from running.
	SkipVersionCheckAnnotation = "skip-version-check"
)

Variables

This section is empty.

Functions

func GetKfClient

func GetKfClient(p *KfParams) kf.KfV1alpha1Interface

GetKfClient returns a kf client.

func GetKubernetes

func GetKubernetes(p *KfParams) k8sclient.Interface

GetKubernetes returns a K8s client.

func LoggingRoundTripperWrapper

func LoggingRoundTripperWrapper(params *KfParams) transport.WrapperFunc

LoggingRoundTripperWrapper returns a WrapperFunc that logs values to stderr if params.LogHTTP is true.

func NewImpersonatingRoundTripperWrapper

func NewImpersonatingRoundTripperWrapper(params *KfParams) transport.WrapperFunc

NewImpersonatingRoundTripperWrapper returns a WrapperFunc that wraps a transport with an optional RoundTripper that adds impersonation headers

func NewLoggingRoundTripper

func NewLoggingRoundTripper(params *KfParams, wrapped http.RoundTripper) http.RoundTripper

NewLoggingRoundTripper creates a new logger that logs to stderr that wraps an inner RoundTripper.

func NewLoggingRoundTripperWithStream

func NewLoggingRoundTripperWithStream(params *KfParams, wrapped http.RoundTripper, out io.Writer) http.RoundTripper

NewLoggingRoundTripperWithStream creates a new logger that logs to the given stream that wraps an inner RoundTripper.

func SetupInjection

func SetupInjection(ctx context.Context, p *KfParams) context.Context

SetupInjection sets up the injection context. XXX: This function is only necessary while we have a huge dependency on KfParams. Once that is removed, this function will no longer be necessary.

func Write

func Write(cfgPath string, config *KfParams) error

Write writes the current configuration to the path specified by the user or the default path.

Example
dir, err := ioutil.TempDir("", "kfcfg")
if err != nil {
	panic(err)
}
defer os.RemoveAll(dir)

configFile := path.Join(dir, "kf.yaml")

{
	toWrite := &KfParams{
		Space: "my-namespace",
	}

	if err := Write(configFile, toWrite); err != nil {
		panic(err)
	}
}

{
	toRead, err := NewKfParamsFromFile(configFile)
	if err != nil {
		panic(err)
	}

	fmt.Println("Read namespace:", toRead.Space)
}
Output:

Read namespace: my-namespace

Types

type KfParams

type KfParams struct {
	// Config holds the path to the configuration.
	// This field isn't serialized when the config is saved.
	Config string `json:"-"`

	// Space holds the namespace kf should connect to by default.
	Space string `json:"space"`

	// KubeCfgFile holds the path to the kubeconfig.
	KubeCfgFile string `json:"-"`

	// LogHTTP enables HTTP tracing for all Kubernetes calls.
	LogHTTP bool `json:"logHTTP"`

	// TargetSpace caches the space specified by Space to prevent it from
	// being computed multiple times.
	// Prefer using GetSpaceOrDefault instead of accessing this value
	// directly.
	TargetSpace *v1alpha1.Space `json:"-"`

	// Impersonate is the config that will be used to impersonate a user in
	// REST requests.
	Impersonate transport.ImpersonationConfig `json:"-"`
	// contains filtered or unexported fields
}

KfParams stores user settings.

func Load

func Load(cfgPath string, overrides *KfParams) (*KfParams, error)

Load reads the config at the given path (or the default config path if not provided), and merges the values with the defaults and overrides.

func NewDefaultKfParams

func NewDefaultKfParams() *KfParams

NewDefaultKfParams creates a KfParams with default values.

func NewKfParamsFromFile

func NewKfParamsFromFile(cfgPath string) (*KfParams, error)

NewKfParamsFromFile reads the config from the specified config path or the default path. If the path is the default and the file doesn't yet exist, then this function does nothing.

func (*KfParams) ConfigFlags

func (p *KfParams) ConfigFlags() (flags *genericclioptions.ConfigFlags)

ConfigFlags constructs a new ConfigFlags from KfParams that can be used to initialize a RestConfig in the same way that Kubectl does it.

func (*KfParams) FeatureFlags

func (p *KfParams) FeatureFlags(ctx context.Context) kfconfig.FeatureFlagToggles

FeatureFlags returns a map of each feature flag name to a bool indicating whether hte feature is enabled or not.

func (*KfParams) GetTargetSpace

func (p *KfParams) GetTargetSpace(ctx context.Context) (*v1alpha1.Space, error)

GetTargetSpace gets the space specified by Space. If the space doesn't exist, an error is returned

This function caches a space once retrieved in TargetSpace.

Example
target := &v1alpha1.Space{}
target.Name = "cached-target"

p := &KfParams{
	TargetSpace: target,
}

space, err := p.GetTargetSpace(context.Background())
fmt.Println("Space:", space.Name)
fmt.Println("Error:", err)
Output:

Space: cached-target
Error: <nil>

func (*KfParams) ValidateSpaceTargeted

func (p *KfParams) ValidateSpaceTargeted() error

ValidateSpaceTargeted returns an error if a Space isn't targeted.

type LoggingRoundTripper

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

LoggingRoundTripper logs HTTP requests.

func (*LoggingRoundTripper) RoundTrip

func (t *LoggingRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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