k8s

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package k8s provides Kubernetes-specific implementations of the infra providers.

Package k8s provides Kubernetes-specific implementations of the infra providers.

Package k8s provides Kubernetes-specific implementations of the infra providers.

Package k8s provides Kubernetes-specific implementations of the infra providers.

Package k8s provides Kubernetes-specific implementations of the infra providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient() (kubernetes.Interface, error)

NewClient creates a Kubernetes client from the default kubeconfig resolution. Used by infra when building K8s providers and exposed so the harness can set h.Cluster.

func NewClientAndConfig

func NewClientAndConfig() (kubernetes.Interface, *rest.Config, error)

NewClientAndConfig returns a Kubernetes client and rest config from the default kubeconfig. The config is needed for port-forward and exec. Use NewClient() when only the interface is needed.

func NewSecretsProvider

func NewSecretsProvider(client kubernetes.Interface, infraP *InfraProvider) (infra.SecretsProvider, error)

NewSecretsProvider creates a new K8s SecretsProvider. infraP is used to resolve namespace for GetSecretDataForService; pass nil only if not using that method. If client is nil, it is created from the default kubeconfig.

Types

type InfraProvider

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

InfraProvider implements infra.InfraProvider for Kubernetes environments.

func NewInfraProvider

func NewInfraProvider(namespace string) (*InfraProvider, error)

NewInfraProvider creates a new K8s InfraProvider. If namespace is empty, it will be auto-detected via the k8s client.

func NewInfraProviderWithConfig

func NewInfraProviderWithConfig(namespace string, config *infra.EnvironmentConfig, client kubernetes.Interface) (*InfraProvider, error)

NewInfraProviderWithConfig creates a new K8s InfraProvider with explicit configuration. client is optional; when nil a client is created from default kubeconfig for namespace detection. External namespace: config.Namespace (e.g. FLIGHTCTL_NS) or detect from pods with label flightctl.service=flightctl-api. Internal namespace: FLIGHTCTL_INTERNAL_NS or detect from pods with label flightctl.service=flightctl-worker. No fallbacks; returns error if detection fails when override not set.

func (*InfraProvider) BuiltinDatabaseWorkloadAvailable

func (p *InfraProvider) BuiltinDatabaseWorkloadAvailable() bool

BuiltinDatabaseWorkloadAvailable reports whether a flightctl-db pod exists in the internal namespace. External PostgreSQL (Helm db.type=external) does not deploy this workload; backup tests that exec pg_dump into the DB pod must be skipped.

func (*InfraProvider) ExecInService

func (p *InfraProvider) ExecInService(service infra.ServiceName, command []string) (string, error)

ExecInService executes a command in the context of a service's pod.

func (*InfraProvider) ExecInServiceWithStdin

func (p *InfraProvider) ExecInServiceWithStdin(service infra.ServiceName, command []string, stdin io.Reader) (string, error)

ExecInServiceWithStdin executes a command in the context of a service's pod with stdin attached.

func (*InfraProvider) ExposeService

func (p *InfraProvider) ExposeService(service infra.ServiceName, protocol string) (string, func(), error)

ExposeService makes an internal K8s service accessible from the test host via port-forwarding. Repeated calls for the same (service, protocol) return the same URL so polling (e.g. WaitForQueueAccessible) does not spawn a new port-forward every time. Port-forwards to svc/<ServiceName> in the service's namespace (internal for Redis/flightctl-kv). Returns the localhost URL and a cleanup function (no-op when cached; callers must not close the shared forward).

func (*InfraProvider) GetAPILoginToken

func (p *InfraProvider) GetAPILoginToken() (string, error)

GetAPILoginToken returns a token for flightctl login --token. KIND: kubectl create token flightctl-admin -n <external namespace> (where API pods run, e.g. flightctl-external). OCP: oc whoami -t.

func (*InfraProvider) GetConfigValue

func (p *InfraProvider) GetConfigValue(name, key string) (string, error)

GetConfigValue retrieves a configuration value from a ConfigMap.

func (*InfraProvider) GetEnvironmentType

func (p *InfraProvider) GetEnvironmentType() string

GetEnvironmentType returns "kind" or "ocp".

func (*InfraProvider) GetExternalNamespace

func (p *InfraProvider) GetExternalNamespace() string

GetExternalNamespace returns the namespace where external services (API, UI, etc.) run (release namespace).

func (*InfraProvider) GetInternalNamespace

func (p *InfraProvider) GetInternalNamespace() string

GetInternalNamespace returns the namespace where internal services (worker, db, kv, etc.) run.

func (*InfraProvider) GetSecretValue

func (p *InfraProvider) GetSecretValue(name, key string) (string, error)

GetSecretValue retrieves a secret value from a Secret (base64 decoded).

func (*InfraProvider) GetServiceConfig

func (p *InfraProvider) GetServiceConfig(service infra.ServiceName) (string, error)

GetServiceConfig retrieves the full configuration content for a service.

func (*InfraProvider) GetServiceEndpoint

func (p *InfraProvider) GetServiceEndpoint(service infra.ServiceName) (string, int, error)

GetServiceEndpoint returns the host and port for a named service. For K8s, this returns the service DNS name and port within the cluster.

func (*InfraProvider) GetServiceNamespaceAndMetadata

func (p *InfraProvider) GetServiceNamespaceAndMetadata(service infra.ServiceName) (deploymentName, label, namespace string, err error)

GetServiceNamespaceAndMetadata returns deployment name, pod label, and namespace for a service. Used by ServiceLifecycleProvider so all service/namespace resolution stays in InfraProvider.

func (*InfraProvider) InvalidateExposeCache

func (p *InfraProvider) InvalidateExposeCache(service infra.ServiceName)

InvalidateExposeCache stops any cached port-forward for the service (kills the process) and removes it from the cache. Call after restarting a service so the next ExposeService creates a new port-forward.

func (*InfraProvider) SetServiceConfig

func (p *InfraProvider) SetServiceConfig(service infra.ServiceName, configKey, content string) error

SetServiceConfig updates a service's ConfigMap data key with the given content.

type RBACProvider

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

RBACProvider implements infra.RBACProvider for Kubernetes environments.

func NewRBACProvider

func NewRBACProvider(client kubernetes.Interface, releaseName string) (*RBACProvider, error)

NewRBACProvider creates a new K8s RBACProvider. releaseName is the external namespace (e.g. from InfraProvider.GetExternalNamespace()) used for CreateOrganization labels; may be empty. If client is nil, it will be created from the default kubeconfig.

func (*RBACProvider) AddUserToOrg

func (p *RBACProvider) AddUserToOrg(ctx context.Context, orgName, userName string) error

AddUserToOrg grants the user access to the organization by binding them to the built-in view ClusterRole in that namespace.

func (*RBACProvider) CreateClusterRole

func (p *RBACProvider) CreateClusterRole(ctx context.Context, spec *infra.RoleSpec) error

CreateClusterRole creates a ClusterRole.

func (*RBACProvider) CreateClusterRoleBinding

func (p *RBACProvider) CreateClusterRoleBinding(ctx context.Context, spec *infra.RoleBindingSpec) error

CreateClusterRoleBinding creates a ClusterRoleBinding.

func (*RBACProvider) CreateOrganization

func (p *RBACProvider) CreateOrganization(ctx context.Context, name string) error

CreateOrganization creates a namespace with the release label so the API treats it as an organization.

func (*RBACProvider) CreateRole

func (p *RBACProvider) CreateRole(ctx context.Context, spec *infra.RoleSpec) error

CreateRole creates a Role in the specified namespace.

func (*RBACProvider) CreateRoleBinding

func (p *RBACProvider) CreateRoleBinding(ctx context.Context, spec *infra.RoleBindingSpec) error

CreateRoleBinding creates a RoleBinding in the specified namespace.

func (*RBACProvider) DeleteClusterRole

func (p *RBACProvider) DeleteClusterRole(ctx context.Context, name string) error

DeleteClusterRole deletes a ClusterRole.

func (*RBACProvider) DeleteClusterRoleBinding

func (p *RBACProvider) DeleteClusterRoleBinding(ctx context.Context, name string) error

DeleteClusterRoleBinding deletes a ClusterRoleBinding.

func (*RBACProvider) DeleteOrganization

func (p *RBACProvider) DeleteOrganization(ctx context.Context, name string) error

DeleteOrganization deletes the namespace (organization).

func (*RBACProvider) DeleteRole

func (p *RBACProvider) DeleteRole(ctx context.Context, namespace, name string) error

DeleteRole deletes a Role from the specified namespace.

func (*RBACProvider) DeleteRoleBinding

func (p *RBACProvider) DeleteRoleBinding(ctx context.Context, namespace, name string) error

DeleteRoleBinding deletes a RoleBinding from the specified namespace.

func (*RBACProvider) GetClient

func (p *RBACProvider) GetClient() kubernetes.Interface

GetClient returns the underlying Kubernetes client. This is useful for tests that need direct access.

func (*RBACProvider) UpdateClusterRole

func (p *RBACProvider) UpdateClusterRole(ctx context.Context, spec *infra.RoleSpec) error

UpdateClusterRole updates a ClusterRole.

func (*RBACProvider) UpdateRole

func (p *RBACProvider) UpdateRole(ctx context.Context, spec *infra.RoleSpec) error

UpdateRole updates a Role in the specified namespace.

type SecretsProvider

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

SecretsProvider implements infra.SecretsProvider for Kubernetes environments.

func (*SecretsProvider) CreateSecret

func (p *SecretsProvider) CreateSecret(ctx context.Context, namespace, name string, stringData map[string]string) error

CreateSecret creates a Secret with the given namespace, name, and string data. Idempotent: if the secret already exists, it is updated to match stringData.

func (*SecretsProvider) GetSecretData

func (p *SecretsProvider) GetSecretData(ctx context.Context, namespace, secretName, key string) ([]byte, error)

GetSecretData returns the value of a key in a Kubernetes Secret. K8s API returns Secret.Data as decoded bytes.

func (*SecretsProvider) GetSecretDataForService

func (p *SecretsProvider) GetSecretDataForService(ctx context.Context, service infra.ServiceName, secretName, key string) ([]byte, error)

GetSecretDataForService returns the value of a key in a secret for the given service. Namespace is resolved from the service (e.g. Redis/flightctl-kv uses internal namespace, same as Helm). For Redis use secretName "flightctl-kv-secret" and key "password" (Helm default).

type ServiceLifecycleProvider

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

ServiceLifecycleProvider implements infra.ServiceLifecycleProvider for Kubernetes environments. All service and namespace resolution is delegated to InfraProvider.

func NewServiceLifecycleProviderWithConfig

func NewServiceLifecycleProviderWithConfig(client kubernetes.Interface, infraP *InfraProvider) *ServiceLifecycleProvider

NewServiceLifecycleProviderWithConfig creates a new K8s ServiceLifecycleProvider. infraP is required; all service/namespace resolution comes from it.

func (*ServiceLifecycleProvider) AreServicesHealthy

func (p *ServiceLifecycleProvider) AreServicesHealthy() (bool, error)

AreServicesHealthy checks if all flightctl services are healthy.

func (*ServiceLifecycleProvider) IsRunning

func (p *ServiceLifecycleProvider) IsRunning(service infra.ServiceName) (bool, error)

IsRunning checks if a service is currently running.

func (*ServiceLifecycleProvider) RemoveDeploymentEnv

func (p *ServiceLifecycleProvider) RemoveDeploymentEnv(service infra.ServiceName, envName string) error

RemoveDeploymentEnv removes an environment variable from a service's deployment and waits for rollout.

func (*ServiceLifecycleProvider) Restart

func (p *ServiceLifecycleProvider) Restart(service infra.ServiceName) error

Restart restarts a service by deleting its pod and waiting for termination.

func (*ServiceLifecycleProvider) SetDeploymentEnv

func (p *ServiceLifecycleProvider) SetDeploymentEnv(service infra.ServiceName, envName, envValue string) error

SetDeploymentEnv sets an environment variable on a service's deployment and waits for rollout.

func (*ServiceLifecycleProvider) Start

func (p *ServiceLifecycleProvider) Start(service infra.ServiceName) error

Start starts a stopped service by scaling the deployment to 1 replica.

func (*ServiceLifecycleProvider) Stop

Stop stops a running service by scaling the deployment to 0 replicas.

func (*ServiceLifecycleProvider) WaitForReady

func (p *ServiceLifecycleProvider) WaitForReady(service infra.ServiceName, timeout time.Duration) error

WaitForReady waits for a service to be ready: pod Running and Ready (K8s readiness).

type TPMProvider

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

TPMProvider implements infra.TPMProvider for Kubernetes environments.

func NewTPMProvider

func NewTPMProvider(client kubernetes.Interface, infraP *InfraProvider, lifecycle *ServiceLifecycleProvider) *TPMProvider

NewTPMProvider creates a new K8s TPMProvider.

func (*TPMProvider) CleanupCerts

func (p *TPMProvider) CleanupCerts(ctx context.Context) error

CleanupCerts removes TPM CA certificates from the API server configuration.

func (*TPMProvider) InjectCerts

func (p *TPMProvider) InjectCerts(ctx context.Context, certs map[string][]byte) error

InjectCerts configures TPM CA certificates for the API server. It skips the deployment restart if all certs, config, and volume/mount are already in place.

Jump to

Keyboard shortcuts

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