k8s

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DockerDesktop = "docker-desktop"
	Kind          = "kind"
	Test          = "test"
)

TODO: add supported map

Variables

View Source
var (
	// DockerDesktopProvider represents the docker-desktop provider.
	DockerDesktopProvider = Provider{
		Name:        DockerDesktop,
		ClusterName: "docker-desktop",
		Context:     "docker-desktop",
		Kubeconfig:  filepath.Join(".kube", "config"),
		HelmNginx: []string{
			"controller.service.httpsPort.enable=false",
		},
	}

	// KindProvider represents the kind (https://kind.sigs.k8s.io/) provider.
	KindProvider = Provider{
		Name:        Kind,
		ClusterName: "airbyte-abctl",
		Context:     "kind-airbyte-abctl",
		Kubeconfig:  filepath.Join(".airbyte", "abctl", "abctl.kubeconfig"),
		HelmNginx: []string{
			"controller.hostPort.enabled=true",
			"controller.service.httpsPort.enable=false",
			"controller.service.type=NodePort",
		},
	}

	// TestProvider represents a test provider, for testing purposes
	TestProvider = Provider{
		Name:        Test,
		ClusterName: "test",
		Context:     "test-abctl",
		Kubeconfig:  filepath.Join(os.TempDir(), "abctl.kubeconfig"),
		HelmNginx:   []string{},
	}
)

Functions

This section is empty.

Types

type Cluster

type Cluster interface {
	// Create a cluster with the provided name.
	Create(portHTTP int) error
	// Delete a cluster with the provided name.
	Delete() error
	// Exists returns true if the cluster exists, false otherwise.
	Exists() bool
}

Cluster is an interface representing all the actions taken at the cluster level.

func NewCluster

func NewCluster(provider Provider) (Cluster, error)

NewCluster returns a Cluster implementation for the provider.

type DefaultK8sClient

type DefaultK8sClient struct {
	ClientSet *kubernetes.Clientset
}

DefaultK8sClient converts the official kubernetes client to our more manageable (and testable) interface

func (*DefaultK8sClient) CreateIngress

func (d *DefaultK8sClient) CreateIngress(ctx context.Context, namespace string, ingress *networkingv1.Ingress) error

func (*DefaultK8sClient) CreateOrUpdateSecret

func (d *DefaultK8sClient) CreateOrUpdateSecret(ctx context.Context, namespace, name string, data map[string][]byte) error

func (*DefaultK8sClient) DeleteNamespace

func (d *DefaultK8sClient) DeleteNamespace(ctx context.Context, namespace string) error

func (*DefaultK8sClient) ExistsIngress

func (d *DefaultK8sClient) ExistsIngress(ctx context.Context, namespace string, ingress string) bool

func (*DefaultK8sClient) ExistsNamespace

func (d *DefaultK8sClient) ExistsNamespace(ctx context.Context, namespace string) bool

func (*DefaultK8sClient) GetServerVersion

func (d *DefaultK8sClient) GetServerVersion() (string, error)

func (*DefaultK8sClient) GetService

func (d *DefaultK8sClient) GetService(ctx context.Context, namespace string, name string) (*coreV1.Service, error)

func (*DefaultK8sClient) UpdateIngress

func (d *DefaultK8sClient) UpdateIngress(ctx context.Context, namespace string, ingress *networkingv1.Ingress) error

type DockerDesktopCluster

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

DockerDesktopCluster is a Cluster that represents a docker-desktop cluster

func (DockerDesktopCluster) Create

func (d DockerDesktopCluster) Create(_ int) error

func (DockerDesktopCluster) Delete

func (d DockerDesktopCluster) Delete() error

func (DockerDesktopCluster) Exists

func (d DockerDesktopCluster) Exists() bool

type K8sClient

type K8sClient interface {
	// CreateIngress creates an ingress in the given namespace
	CreateIngress(ctx context.Context, namespace string, ingress *networkingv1.Ingress) error
	// ExistsIngress returns true if the ingress exists in the namespace, false otherwise.
	ExistsIngress(ctx context.Context, namespace string, ingress string) bool
	// UpdateIngress updates an existing ingress in the given namespace
	UpdateIngress(ctx context.Context, namespace string, ingress *networkingv1.Ingress) error

	// ExistsNamespace returns true if the namespace exists, false otherwise
	ExistsNamespace(ctx context.Context, namespace string) bool
	// DeleteNamespace deletes the existing namespace
	DeleteNamespace(ctx context.Context, namespace string) error

	// CreateOrUpdateSecret will update or create the secret name with the payload of data in the specified namespace
	CreateOrUpdateSecret(ctx context.Context, namespace, name string, data map[string][]byte) error

	// GetService returns a the service for the given namespace and name
	GetService(ctx context.Context, namespace, name string) (*coreV1.Service, error)

	// GetServerVersion returns the k8s version.
	GetServerVersion() (string, error)
}

K8sClient primarily for testing purposes

type KindCluster

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

KindCluster is a Cluster implementation for kind (https://kind.sigs.k8s.io/).

func (*KindCluster) Create

func (k *KindCluster) Create(port int) error

func (*KindCluster) Delete

func (k *KindCluster) Delete() error

func (*KindCluster) Exists

func (k *KindCluster) Exists() bool

type Provider

type Provider struct {
	// Name of this provider
	Name string
	// ClusterName is the name of the cluster this provider will interact with
	ClusterName string
	// Context this provider should use
	Context string
	// Kubeconfig location
	Kubeconfig string
	// HelmNginx additional helm values to pass to the nginx chart
	HelmNginx []string
}

Provider represents a k8s provider.

func ProviderFromString

func ProviderFromString(s string) (Provider, error)

ProviderFromString returns a provider from the given string s. If no provider is found, an error is returned.

func (Provider) MkDirs

func (p Provider) MkDirs(userHome string) error

MkDirs creates the directories for this providers kubeconfig. The kubeconfigs are always scoped to the user's home directory. TODO: rename to something more clear

Jump to

Keyboard shortcuts

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