k8s

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWaitingTimeout     = 120 * time.Second
	DefaultErrorWindowTimeout = 2 * time.Second
)
View Source
const (
	KubernetesDeployerName = "raw"

	DefaultLivenessEndpoint  = "/health/liveness"
	DefaultReadinessEndpoint = "/health/readiness"
	DefaultHTTPPort          = 8080
)

Variables

View Source
var SocatImage = "ghcr.io/knative/func-utils:v2"
View Source
var TarImage = "ghcr.io/knative/func-utils:v2"

Functions

func CheckResourcesArePresent added in v0.48.0

func CheckResourcesArePresent(ctx context.Context, namespace string, referencedSecrets, referencedConfigMaps, referencedPVCs *sets.Set[string], referencedServiceAccount string) error

CheckResourcesArePresent returns error if Secrets or ConfigMaps referenced in input sets are not deployed on the cluster in the specified namespace

func CreatePersistentVolumeClaim

func CreatePersistentVolumeClaim(ctx context.Context, name, namespaceOverride string, labels map[string]string, annotations map[string]string, accessMode corev1.PersistentVolumeAccessMode, resourceRequest resource.Quantity, storageClassName string) (err error)

func DeletePersistentVolumeClaims

func DeletePersistentVolumeClaims(ctx context.Context, namespaceOverride string, listOptions metav1.ListOptions) (err error)

func DeleteSecrets

func DeleteSecrets(ctx context.Context, namespaceOverride string, listOptions metav1.ListOptions) (err error)

func EnsureDockerRegistrySecretExist

func EnsureDockerRegistrySecretExist(ctx context.Context, name, namespaceOverride string, labels map[string]string, annotations map[string]string, username, password, server string) (err error)

func EnsureSecretExist

func EnsureSecretExist(ctx context.Context, secret corev1.Secret, namespaceOverride string) (err error)

func GetACRCredentialLoader added in v0.47.0

func GetACRCredentialLoader() []creds.CredentialsCallback

func GetClientConfig

func GetClientConfig() clientcmd.ClientConfig

func GetConfigMap

func GetConfigMap(ctx context.Context, name, namespaceOverride string) (*corev1.ConfigMap, error)

func GetDefaultNamespace added in v0.41.0

func GetDefaultNamespace() (namespace string, err error)

GetDefaultNamespace returns default namespace

func GetDefaultOpenShiftRegistry added in v0.38.1

func GetDefaultOpenShiftRegistry() string

func GetECRCredentialLoader added in v0.47.0

func GetECRCredentialLoader() []creds.CredentialsCallback

func GetGoogleCredentialLoader added in v0.47.0

func GetGoogleCredentialLoader() []creds.CredentialsCallback

func GetManifestivalClient added in v0.38.0

func GetManifestivalClient() (manifestival.Client, error)

func GetOpenShiftDockerCredentialLoaders added in v0.38.1

func GetOpenShiftDockerCredentialLoaders() []creds.CredentialsCallback

func GetOpenShiftServiceCA added in v0.38.1

func GetOpenShiftServiceCA(ctx context.Context) (*x509.Certificate, error)

func GetPersistentVolumeClaim

func GetPersistentVolumeClaim(ctx context.Context, name, namespaceOverride string) (*corev1.PersistentVolumeClaim, error)

func GetPodLogs

func GetPodLogs(ctx context.Context, namespace, podName, containerName string) (string, error)

GetPodLogs returns logs from a specified Container in a Pod, if container is empty string, then the first container in the pod is selected.

func GetPodLogsBySelector added in v0.48.0

func GetPodLogsBySelector(ctx context.Context, namespace, labelSelector, containerName, image string, since *time.Time, out io.Writer) error

GetPodLogsBySelector will get logs of a pod.

It will do so by gathering logs of the given container of all affiliated pods. In addition, filtering on image can be done so only logs for given image are logged.

This function runs as long as the passed context is active (i.e. it is required cancel the context to stop log gathering).

func GetSecret

func GetSecret(ctx context.Context, name, namespaceOverride string) (*corev1.Secret, error)

func GetServiceAccount added in v0.38.0

func GetServiceAccount(ctx context.Context, referencedServiceAccount, namespace string) error

func HandleDockerCfgJSONContent

func HandleDockerCfgJSONContent(username, password, email, server string) ([]byte, error)

func IsOpenShift added in v0.38.1

func IsOpenShift() bool

func ListConfigMapsNamesIfConnected

func ListConfigMapsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)

ListConfigMapsNamesIfConnected lists names of ConfigMaps present and the current k8s context returns empty list, if not connected to any cluster

func ListPersistentVolumeClaimsNamesIfConnected added in v0.38.0

func ListPersistentVolumeClaimsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)

ListPersistentVolumeClaimsNamesIfConnected lists names of PersistentVolumeClaims present and the current k8s context returns empty list, if not connected to any cluster

func ListSecretsNamesIfConnected

func ListSecretsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)

ListSecretsNamesIfConnected lists names of Secrets present and the current k8s context returns empty list, if not connected to any cluster

func NewClientAndResolvedNamespace

func NewClientAndResolvedNamespace(ns string) (*kubernetes.Clientset, string, error)

func NewDynamicClient

func NewDynamicClient() (dynamic.Interface, error)

func NewInClusterDialer

func NewInClusterDialer(ctx context.Context, clientConfig clientcmd.ClientConfig) (*contextDialer, error)

NewInClusterDialer creates context dialer that will dial TCP connections via POD running in k8s cluster. This is useful when accessing k8s services that are not exposed outside cluster (e.g. openshift image registry).

Usage:

dialer, err := k8s.NewInClusterDialer(ctx)
if err != nil {
    return err
}
defer dialer.Close()

transport := &http.Transport{
    DialContext: dialer.DialContext,
}

var client = http.Client{
    Transport: transport,
}

func NewKubernetesClientset

func NewKubernetesClientset() (*kubernetes.Clientset, error)

func NewLazyInitInClusterDialer

func NewLazyInitInClusterDialer(clientConfig clientcmd.ClientConfig) *lazyInitInClusterDialer

func NewLister added in v0.48.0

func NewLister(verbose bool) fn.Lister

func ProcessEnvs added in v0.48.0

func ProcessEnvs(envs []fn.Env, referencedSecrets, referencedConfigMaps *sets.Set[string]) ([]corev1.EnvVar, []corev1.EnvFromSource, error)

ProcessEnvs generates array of EnvVars and EnvFromSources from a function config envs:

  • name: EXAMPLE1 # ENV directly from a value value: value1
  • name: EXAMPLE2 # ENV from the local ENV var value: {{ env:MY_ENV }}
  • name: EXAMPLE3 value: {{ secret:example-secret:key }} # ENV from a key in Secret
  • value: {{ secret:example-secret }} # all ENVs from Secret
  • name: EXAMPLE4 value: {{ configMap:configMapName:key }} # ENV from a key in ConfigMap
  • value: {{ configMap:configMapName }} # all key-pair values from ConfigMap are set as ENV

func ProcessVolumes added in v0.48.0

func ProcessVolumes(volumes []fn.Volume, referencedSecrets, referencedConfigMaps, referencedPVCs *sets.Set[string]) ([]corev1.Volume, []corev1.VolumeMount, error)

ProcessVolumes generates Volumes and VolumeMounts from a function config volumes:

  • secret: example-secret # mount Secret as Volume path: /etc/secret-volume
  • configMap: example-configMap # mount ConfigMap as Volume path: /etc/configMap-volume
  • persistentVolumeClaim: { claimName: example-pvc } # mount PersistentVolumeClaim as Volume path: /etc/secret-volume
  • emptyDir: {} # mount EmptyDir as Volume path: /etc/configMap-volume

func SetHealthEndpoints added in v0.48.0

func SetHealthEndpoints(f fn.Function, container *corev1.Container)

SetHealthEndpoints configures health probes for a container

func SetSecurityContext added in v0.48.0

func SetSecurityContext(container *corev1.Container)

SetSecurityContext configures security settings for a container

func UploadToVolume

func UploadToVolume(ctx context.Context, content io.Reader, claimName, namespace string) error

UploadToVolume uploads files (passed in form of tar stream) into volume.

func UsesRawDeployer added in v0.48.0

func UsesRawDeployer(annotations map[string]string) bool

func WaitForDeploymentAvailable added in v0.48.0

func WaitForDeploymentAvailable(ctx context.Context, clientset *kubernetes.Clientset, namespace, deploymentName string, timeout time.Duration) error

WaitForDeploymentAvailable waits for a specific deployment to be fully available. A deployment is considered available when: - The number of available replicas matches the desired replicas - All replicas are updated to the latest version - There are no unavailable replicas - All pods associated with the deployment are running

func WaitForDeploymentAvailableBySelector added in v0.48.0

func WaitForDeploymentAvailableBySelector(ctx context.Context, clientset *kubernetes.Clientset, namespace, selector string, timeout time.Duration) error

func WaitForServiceRemoved added in v0.48.0

func WaitForServiceRemoved(ctx context.Context, clientset *kubernetes.Clientset, namespace, name string, timeout time.Duration) error

Types

type Deployer added in v0.48.0

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

func NewDeployer added in v0.48.0

func NewDeployer(opts ...DeployerOpt) *Deployer

func (*Deployer) Deploy added in v0.48.0

func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (fn.DeploymentResult, error)

type DeployerOpt added in v0.48.0

type DeployerOpt func(*Deployer)

func WithDeployerDecorator added in v0.48.0

func WithDeployerDecorator(decorator deployer.DeployDecorator) DeployerOpt

func WithDeployerVerbose added in v0.48.0

func WithDeployerVerbose(verbose bool) DeployerOpt

type Describer added in v0.48.0

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

func NewDescriber added in v0.48.0

func NewDescriber(verbose bool) *Describer

func (*Describer) Describe added in v0.48.0

func (d *Describer) Describe(ctx context.Context, name, namespace string) (fn.Instance, error)

Describe a function by name.

type Lister added in v0.48.0

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

func (*Lister) List added in v0.48.0

func (l *Lister) List(ctx context.Context, namespace string) ([]fn.ListItem, error)

type OpenshiftMetadataDecorator added in v0.38.1

type OpenshiftMetadataDecorator struct{}

func (OpenshiftMetadataDecorator) UpdateAnnotations added in v0.38.1

func (o OpenshiftMetadataDecorator) UpdateAnnotations(f fn.Function, annotations map[string]string) map[string]string

func (OpenshiftMetadataDecorator) UpdateLabels added in v0.38.1

func (o OpenshiftMetadataDecorator) UpdateLabels(f fn.Function, labels map[string]string) map[string]string

type Remover added in v0.48.0

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

func NewRemover added in v0.48.0

func NewRemover(verbose bool) *Remover

func (*Remover) Remove added in v0.48.0

func (remover *Remover) Remove(ctx context.Context, name, ns string) error

type SynchronizedBuffer added in v0.48.0

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

func (*SynchronizedBuffer) Read added in v0.48.0

func (b *SynchronizedBuffer) Read(p []byte) (n int, err error)

func (*SynchronizedBuffer) Reset added in v0.48.0

func (b *SynchronizedBuffer) Reset()

func (*SynchronizedBuffer) String added in v0.48.0

func (b *SynchronizedBuffer) String() string

func (*SynchronizedBuffer) Write added in v0.48.0

func (b *SynchronizedBuffer) Write(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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