Documentation
¶
Index ¶
- Constants
- Variables
- func CheckResourcesArePresent(ctx context.Context, namespace string, ...) error
- func CreatePersistentVolumeClaim(ctx context.Context, name, namespaceOverride string, labels map[string]string, ...) (err error)
- func DeletePersistentVolumeClaims(ctx context.Context, namespaceOverride string, listOptions metav1.ListOptions) (err error)
- func DeleteSecrets(ctx context.Context, namespaceOverride string, listOptions metav1.ListOptions) (err error)
- func EnsureDockerRegistrySecretExist(ctx context.Context, name, namespaceOverride string, labels map[string]string, ...) (err error)
- func EnsureSecretExist(ctx context.Context, secret corev1.Secret, namespaceOverride string) (err error)
- func GetACRCredentialLoader() []creds.CredentialsCallback
- func GetClientConfig() clientcmd.ClientConfig
- func GetConfigMap(ctx context.Context, name, namespaceOverride string) (*corev1.ConfigMap, error)
- func GetDefaultNamespace() (namespace string, err error)
- func GetDefaultOpenShiftRegistry() string
- func GetECRCredentialLoader() []creds.CredentialsCallback
- func GetGoogleCredentialLoader() []creds.CredentialsCallback
- func GetManifestivalClient() (manifestival.Client, error)
- func GetOpenShiftDockerCredentialLoaders() []creds.CredentialsCallback
- func GetOpenShiftServiceCA(ctx context.Context) (*x509.Certificate, error)
- func GetPersistentVolumeClaim(ctx context.Context, name, namespaceOverride string) (*corev1.PersistentVolumeClaim, error)
- func GetPodLogs(ctx context.Context, namespace, podName, containerName string) (string, error)
- func GetPodLogsBySelector(ctx context.Context, namespace, labelSelector, containerName, image string, ...) error
- func GetSecret(ctx context.Context, name, namespaceOverride string) (*corev1.Secret, error)
- func GetServiceAccount(ctx context.Context, referencedServiceAccount, namespace string) error
- func HandleDockerCfgJSONContent(username, password, email, server string) ([]byte, error)
- func IsOpenShift() bool
- func ListConfigMapsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)
- func ListPersistentVolumeClaimsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)
- func ListSecretsNamesIfConnected(ctx context.Context, namespaceOverride string) (names []string, err error)
- func NewClientAndResolvedNamespace(ns string) (*kubernetes.Clientset, string, error)
- func NewDynamicClient() (dynamic.Interface, error)
- func NewInClusterDialer(ctx context.Context, clientConfig clientcmd.ClientConfig) (*contextDialer, error)
- func NewKubernetesClientset() (*kubernetes.Clientset, error)
- func NewLazyInitInClusterDialer(clientConfig clientcmd.ClientConfig) *lazyInitInClusterDialer
- func NewLister(verbose bool) fn.Lister
- func ProcessEnvs(envs []fn.Env, referencedSecrets, referencedConfigMaps *sets.Set[string]) ([]corev1.EnvVar, []corev1.EnvFromSource, error)
- func ProcessVolumes(volumes []fn.Volume, ...) ([]corev1.Volume, []corev1.VolumeMount, error)
- func SetHealthEndpoints(f fn.Function, container *corev1.Container)
- func SetSecurityContext(container *corev1.Container)
- func UploadToVolume(ctx context.Context, content io.Reader, claimName, namespace string) error
- func UsesRawDeployer(annotations map[string]string) bool
- func WaitForDeploymentAvailable(ctx context.Context, clientset *kubernetes.Clientset, ...) error
- func WaitForDeploymentAvailableBySelector(ctx context.Context, clientset *kubernetes.Clientset, ...) error
- func WaitForServiceRemoved(ctx context.Context, clientset *kubernetes.Clientset, namespace, name string, ...) error
- type Deployer
- type DeployerOpt
- type Describer
- type Lister
- type OpenshiftMetadataDecorator
- type Remover
- type SynchronizedBuffer
Constants ¶
const ( DefaultWaitingTimeout = 120 * time.Second DefaultErrorWindowTimeout = 2 * time.Second )
const ( KubernetesDeployerName = "raw" DefaultLivenessEndpoint = "/health/liveness" DefaultReadinessEndpoint = "/health/readiness" DefaultHTTPPort = 8080 )
Variables ¶
var SocatImage = "ghcr.io/knative/func-utils:v2"
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 DeleteSecrets ¶
func EnsureSecretExist ¶
func GetACRCredentialLoader ¶ added in v0.47.0
func GetACRCredentialLoader() []creds.CredentialsCallback
func GetClientConfig ¶
func GetClientConfig() clientcmd.ClientConfig
func GetConfigMap ¶
func GetDefaultNamespace ¶ added in v0.41.0
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 GetPodLogs ¶
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 GetServiceAccount ¶ added in v0.38.0
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 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 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
SetHealthEndpoints configures health probes for a container
func SetSecurityContext ¶ added in v0.48.0
SetSecurityContext configures security settings for a container
func UploadToVolume ¶
UploadToVolume uploads files (passed in form of tar stream) into volume.
func UsesRawDeployer ¶ added in v0.48.0
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 WaitForServiceRemoved ¶ added in v0.48.0
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
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
type OpenshiftMetadataDecorator ¶ added in v0.38.1
type OpenshiftMetadataDecorator struct{}
func (OpenshiftMetadataDecorator) UpdateAnnotations ¶ added in v0.38.1
func (OpenshiftMetadataDecorator) UpdateLabels ¶ added in v0.38.1
type Remover ¶ added in v0.48.0
type Remover struct {
// contains filtered or unexported fields
}
func NewRemover ¶ added in v0.48.0
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