client

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package client provides utilities for creating and managing Kubernetes clients.

This package includes functions and types for configuring and creating Kubernetes clients tailored to specific requirements, such as accessing AWS EKS clusters with appropriate authentication.

Example usage:

specify the opts with Kubernetes Cluster type, such as EKSClientOption, otherwise the default local client will be created.

* for EKS setup:

client, err := client.New(&NewClientInput{ClusterType: ClusterTypeEKS}, EKSClientOption(ctx, "test-cluster-01", "us-east-1"))
if err != nil {
    fmt.Printf("failed to create client: %v", err)
    return
}

* for localhost setup:

client, err := client.New(&NewClientInput{ClusterType: ClusterTypeLOCAL, KuberKubernetesConfigPath: *configFilePath})

Index

Constants

View Source
const (
	ClusterTypeEKS   = "eks"
	ClusterTypeLOCAL = "local"
)

ClusterTypes must match with the cmd/root.go kubernetes-type flag

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// ClientSet returns the rest clientset to be used.
	ClientSet() kubernetes.Interface
	// ControllerClient returns the controller-runtime client to be used.
	ControllerClient() *controllerClient.Client
	// Config returns the rest.Config to be used.
	Config() *rest.Config
}

func New

func New(input *NewClientInput, opts ...NewClientOption) (Interface, error)

New creates new Kubernetes clients with the specified options.

type NewClientInput

type NewClientInput struct {
	// ClusterType is a type of the Kubernetes cluster (required)
	ClusterType string
	// KubernetesConfigPath is a path to the kubeconfig file (optional)
	KubernetesConfigPath string
	// contains filtered or unexported fields
}

type NewClientOption

type NewClientOption func(*NewClientInput)

func EKSClientOption

func EKSClientOption(ctx context.Context, clusterID string) NewClientOption

EKSClientOption sets up a Kubernetes client for accessing an AWS EKS cluster.

This function assumes that the AWS SDK configuration can obtain the necessary credentials from the environment. This is the default behavior of the AWS SDK. It is recommended to use IAM Roles for Service Accounts (IRSA) for EKS clusters to grant IAM roles to the pods. Using IRSA provides fine-grained permissions and security best practices. If IRSA is not used, the pod will attempt to use the instance credentials and generate an STS token for accessing the EKS cluster.

Parameters:

  • ctx: the context for the AWS SDK client.

  • clusterID: the name of the EKS cluster.

type TokenRefresher

type TokenRefresher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TokenRefresher) WrapTransport

func (t *TokenRefresher) WrapTransport(rt http.RoundTripper) http.RoundTripper

Jump to

Keyboard shortcuts

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