k8s

package
Version: v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: Apache-2.0 Imports: 31 Imported by: 7

Documentation

Overview

Package k8s gathers abstractions on top of Kubernetes Objects

Index

Constants

View Source
const FinalizerName = "steward.sap.com"

FinalizerName name to register finalizer

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientFactory

type ClientFactory interface {
	// CoreV1 returns the core/v1 Kubernetes client
	CoreV1() corev1client.CoreV1Interface

	// NetworkingV1 returns the networking/v1 Kubernetes client
	NetworkingV1() networkingv1client.NetworkingV1Interface

	// RbacV1 returns the rbac/v1 Kubernetes client
	RbacV1() rbacv1client.RbacV1Interface

	// Dynamic returns the dynamic Kubernetes client
	Dynamic() dynamic.Interface

	// StewardV1alpha1 returns the steward.sap.com/v1alpha1 Kubernetes client
	StewardV1alpha1() stewardv1alpha1client.StewardV1alpha1Interface

	// StewardInformerFactory returns the informer factory for Steward
	StewardInformerFactory() stewardinformers.SharedInformerFactory

	// TektonV1beta1 returns the tekton.dev/v1beta1 Kubernetes client
	TektonV1beta1() tektonv1beta1client.TektonV1beta1Interface

	// TektonInformerFactory returns the informer factory for Tekton
	TektonInformerFactory() tektoninformers.SharedInformerFactory
}

ClientFactory is the interface for Kubernet client factories.

func NewClientFactory

func NewClientFactory(config *rest.Config, resyncPeriod time.Duration) ClientFactory

NewClientFactory creates new client factory based on rest config

type NamespaceManager

type NamespaceManager interface {
	Create(ctx context.Context, name string, annotations map[string]string) (string, error)
	Delete(ctx context.Context, name string) error
}

NamespaceManager manages namespaces

func NewNamespaceManager

func NewNamespaceManager(factory ClientFactory, prefix string, suffixLength uint8) NamespaceManager

NewNamespaceManager creates a new NamespaceManager.

type PipelineRun

type PipelineRun interface {
	fmt.Stringer
	GetAPIObject() *api.PipelineRun
	GetStatus() *api.PipelineStatus
	GetSpec() *api.PipelineSpec
	GetName() string
	GetKey() string
	GetRunNamespace() string
	GetAuxNamespace() string
	GetNamespace() string
	GetPipelineRepoServerURL() (string, error)
	HasDeletionTimestamp() bool
	AddFinalizer(ctx context.Context) error
	CommitStatus(ctx context.Context) ([]*api.StateItem, error)
	DeleteFinalizerIfExists(ctx context.Context) error
	InitState() error
	UpdateState(api.State, metav1.Time) error
	UpdateResult(api.Result, metav1.Time)
	UpdateContainer(*corev1.ContainerState)
	StoreErrorAsMessage(error, string) error
	UpdateRunNamespace(string)
	UpdateAuxNamespace(string)
	UpdateMessage(string)
}

PipelineRun is a wrapper for the K8s PipelineRun resource

func NewPipelineRun

func NewPipelineRun(ctx context.Context, apiObj *api.PipelineRun, factory ClientFactory) (PipelineRun, error)

NewPipelineRun creates a managed pipeline run object. If a factory is provided a new version of the pipelinerun is fetched. All changes are done on the fetched object. If no pipeline run can be found matching the apiObj, nil,nil is returned. An error is only returned if a Get for the pipelinerun returns an error other than a NotFound error. If you call with factory nil you can only use the Get* functions If you use functions changing the pipeline run without factroy set you will get an error. The provided PipelineRun object is never modified and copied as late as possible.

type PipelineRunByKeyFetcher

type PipelineRunByKeyFetcher interface {
	// ByKey fetches PipelineRun resource from Kubernetes
	// Return nil,nil if pipeline with key does not exist
	ByKey(ctx context.Context, key string) (*api.PipelineRun, error)
}

PipelineRunByKeyFetcher provides a function to fetch PipelineRuns by their key

type PipelineRunByNameFetcher

type PipelineRunByNameFetcher interface {
	// ByName fetches PipelineRun resource from Kubernetes by name and namespace
	// Return nil,nil if specified pipeline does not exist
	ByName(ctx context.Context, namespace, name string) (*api.PipelineRun, error)
}

PipelineRunByNameFetcher provides a function to fetch PipelineRuns by their name

type PipelineRunFetcher

type PipelineRunFetcher interface {
	PipelineRunByKeyFetcher
	PipelineRunByNameFetcher
}

PipelineRunFetcher combines PipelineRunByKeyFetcher and PipelineRunByNameFetcher

func NewClientBasedPipelineRunFetcher

func NewClientBasedPipelineRunFetcher(client stewardv1alpha1.StewardV1alpha1Interface) PipelineRunFetcher

NewClientBasedPipelineRunFetcher returns a PipelineRunFetcher that retrieves the objects from the given API client.

func NewListerBasedPipelineRunFetcher

func NewListerBasedPipelineRunFetcher(lister stewardLister.PipelineRunLister) PipelineRunFetcher

NewListerBasedPipelineRunFetcher returns a PipelineRunFetcher that retrieves the objects from the given `PipelineRunLister`. The returned fetcher provides the original pointers from the lister. Typically the lister is backed by a shared cache which must not be modified. Consumers should not mutate the original objects, but create deep copies when modification is required.

type RoleName

type RoleName string

RoleName to be attached

type ServiceAccountHelper added in v0.3.10

type ServiceAccountHelper interface {
	GetServiceAccountSecretNameRepeat(ctx context.Context) (string, error)
	GetServiceAccountSecretName(ctx context.Context) (string, error)
}

ServiceAccountHelper implements functions to get service account secret

type ServiceAccountManager

type ServiceAccountManager interface {
	CreateServiceAccount(ctx context.Context, name string, pipelineCloneSecretName string, imagePullSecretNames []string) (*ServiceAccountWrap, error)
	GetServiceAccount(ctx context.Context, name string) (*ServiceAccountWrap, error)
}

ServiceAccountManager manages serviceAccounts

func NewServiceAccountManager

func NewServiceAccountManager(factory ClientFactory, namespace string) ServiceAccountManager

NewServiceAccountManager creates ServiceAccountManager

type ServiceAccountWrap

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

ServiceAccountWrap wraps a Service Account and enriches it with futher things

func (*ServiceAccountWrap) AddRoleBinding

func (a *ServiceAccountWrap) AddRoleBinding(ctx context.Context, clusterRole RoleName, targetNamespace string) (*rbacv1.RoleBinding, error)

AddRoleBinding creates a role binding in the targetNamespace connecting the service account with the specified cluster role

func (*ServiceAccountWrap) AttachImagePullSecrets

func (a *ServiceAccountWrap) AttachImagePullSecrets(secretNames ...string)

AttachImagePullSecrets attaches a number of secrets to the service account. It does NOT create or update the resource via the underlying client.

func (*ServiceAccountWrap) AttachSecrets

func (a *ServiceAccountWrap) AttachSecrets(secretNames ...string)

AttachSecrets attaches a number of secrets to the service account. It does NOT create or update the resource via the underlying client.

func (*ServiceAccountWrap) GetHelper added in v0.3.10

GetHelper returns a ServiceAccountHelper

func (*ServiceAccountWrap) GetServiceAccount

func (a *ServiceAccountWrap) GetServiceAccount() *corev1.ServiceAccount

GetServiceAccount returns *v1.ServiceAccount

func (ServiceAccountWrap) SetDoAutomountServiceAccountToken added in v0.3.10

func (a ServiceAccountWrap) SetDoAutomountServiceAccountToken(doAutomount bool)

SetDoAutomountServiceAccountToken sets the `automountServiceAccountToken` flag in the service account spec. It does NOT create or update the resource via the underlying client.

func (*ServiceAccountWrap) Update

func (a *ServiceAccountWrap) Update(ctx context.Context) error

Update performs an update of the service account resource object via the underlying client.

type TenantFetcher

type TenantFetcher interface {
	// ByKey fetches Tenant resource from Kubernetes.
	//     key    has to be "<namespace>/<name>"
	// Return nil,nil if tenant with key does not exist
	ByKey(ctx context.Context, key string) (*api.Tenant, error)
}

TenantFetcher has methods to fetch tenants from Kubernetes

func NewClientBasedTenantFetcher

func NewClientBasedTenantFetcher(factory ClientFactory) TenantFetcher

NewClientBasedTenantFetcher returns an operative implementation of TenantFetcher

func NewListerBasedTenantFetcher

func NewListerBasedTenantFetcher(lister stewardLister.TenantLister) TenantFetcher

NewListerBasedTenantFetcher creates a new lister based tenant fetcher

type TenantNamespace

type TenantNamespace interface {
	GetSecretProvider() secrets.SecretProvider
	TargetClientFactory() ClientFactory
}

TenantNamespace representing the client

func NewTenantNamespace

func NewTenantNamespace(factory ClientFactory, namespace string) TenantNamespace

NewTenantNamespace creates new TenantNamespace object

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
client-go/corev1
Package corev1 is a generated GoMock package.
Package corev1 is a generated GoMock package.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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