k8srestconfig

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package k8srestconfig provides interface to create client-go rest config which can be used to construct various clients.

Example usage:

import (
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"

	"github.com/giantswarm/apiextensions/pkg/clientset/versioned"
	"github.com/giantswarm/k8sclient/k8srestconfig"
	"github.com/giantswarm/microerror"
)

func f(config Config) error {
	var err error

	var restConfig *rest.Config
	{
		c := k8srestconfig.Config{
			Logger: config.Logger,

			Address:    config.Viper.GetString(config.Flag.Service.Kubernetes.Address),
			InCluster:  config.Viper.GetBool(config.Flag.Service.Kubernetes.InCluster),
			KubeConfig: config.Viper.GetBool(config.Flag.Service.Kubernetes.KubeConfig),
			TLS: k8srestconfig.ConfigTLS{
				CAFile:  config.Viper.GetString(config.Flag.Service.Kubernetes.TLS.CAFile),
				CrtFile: config.Viper.GetString(config.Flag.Service.Kubernetes.TLS.CrtFile),
				KeyFile: config.Viper.GetString(config.Flag.Service.Kubernetes.TLS.KeyFile),
			},
		}

		restConfig, err = k8srestconfig.New(c)
		if err != nil {
			return microerror.Mask(err)
		}
	}

	k8sClient, err := kubernetes.NewForConfig(restConfig)
	if err != nil {
		return micorerror.Mask(err)
	}

	k8sExtClient, err := apiextensionsclient.NewForConfig(restConfig)
	if err != nil {
		return micorerror.Mask(err)
	}

	g8sClient, err := versioned.NewForConfig(restConfig)
	if err != nil {
		return microerror.Mask(err)
	}
}

Index

Constants

View Source
const (
	// Maximum QPS to the master from this client.
	MaxQPS = 100
	// Maximum burst for throttle.
	MaxBurst       = 100
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func New

func New(config Config) (*rest.Config, error)

New returns a Kubernetes REST configuration for clients.

Types

type Config

type Config struct {
	// Dependencies.
	Logger micrologger.Logger

	// Settings
	Address    string
	KubeConfig string
	InCluster  bool
	Timeout    time.Duration
	TLS        ConfigTLS
}

Config contains the common attributes to create a Kubernetes Clientset.

type ConfigTLS

type ConfigTLS struct {
	// CAFile is the CA certificate for the cluster.
	CAFile string
	// CrtFile is the TLS client certificate.
	CrtFile string
	// KeyFile is the key for the TLS client certificate.
	KeyFile string
	// CAData holds PEM-encoded bytes. CAData takes precedence over CAFile.
	CAData []byte
	// CrtData holds PEM-encoded bytes. CrtData takes precedence over CrtFile.
	CrtData []byte
	// KeyData holds PEM-encoded bytes. KeyData takes precedence over KeyFile.
	KeyData []byte
}

ConfigTLS contains settings to enable transport layer security.

Jump to

Keyboard shortcuts

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