config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuildClient

func GetBuildClient(p *KfParams) build.BuildV1alpha1Interface

GetBuildClient returns a Build interface.

func GetDynamicClient

func GetDynamicClient(p *KfParams) dynamic.Interface

GetDynamicClient gets a dynamic Kubernetes client. Dynamic clients can work on any type of Kubernetes object, but only support the common fields.

Dynamic clients can be used to get alternative representations of objects like tables, or traverse multiple types of object in a single pass e.g. to construct a tree based on OwnerReferences.

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 GetServiceCatalogClient

func GetServiceCatalogClient(p *KfParams) servicecatalogclient.Interface

GetServiceCatalogClient returns a ServiceCatalogClient.

func GetServingClient

func GetServingClient(p *KfParams) serving.ServingV1alpha1Interface

GetServingClient returns a Serving interface.

func GetSvcatApp

func GetSvcatApp(p *KfParams) marketplace.SClientFactory

GetSvcatApp returns a SvcatClient.

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 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{
		Namespace: "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.Namespace)
}
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:"-"`

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

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

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

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

KfParams stores everything needed to interact with the user and Knative.

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) GetTargetSpaceOrDefault

func (p *KfParams) GetTargetSpaceOrDefault() (*v1alpha1.Space, error)

GetTargetSpaceOrDefault gets the space specified by Namespace or a default space with minimal configuration.

This function caches a space once retrieved in CurrentSpace.

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

p := &KfParams{
	TargetSpace: target,
}

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

Space: cached-target
Error: <nil>

func (*KfParams) SetTargetSpaceToDefault

func (p *KfParams) SetTargetSpaceToDefault()

SetTargetSpaceToDefault sets TargetSpace to the default, overwriting any existing values.

Example
defaultSpace := &v1alpha1.Space{}
defaultSpace.SetDefaults(context.Background())

p := &KfParams{}
p.SetTargetSpaceToDefault()

fmt.Printf("Set to default: %v\n", reflect.DeepEqual(p.TargetSpace, defaultSpace))
Output:

Set to default: true

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.

type WrapperFunc

type WrapperFunc func(http.RoundTripper) http.RoundTripper

WrapperFunc wraps an http.RoundTripper when a new transport is created for a client, allowing per connection behavior to be injected.

func LoggingRoundTripperWrapper

func LoggingRoundTripperWrapper(params *KfParams) WrapperFunc

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

Jump to

Keyboard shortcuts

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