Documentation ¶
Index ¶
- Constants
- func DataFromRunner(props *Props) func(root cdk8s.Chart) ConnectedChart
- func DefaultJobLogFunction(e *Environment, message string)
- func MkdirIfNotExists(dirName string) error
- func NewRunner(props *Props) func(root cdk8s.Chart) ConnectedChart
- type Artifacts
- type Chart
- type Config
- type ConnectedChart
- type CoverageProfileParams
- type Environment
- func (m *Environment) AddChart(f func(root cdk8s.Chart) ConnectedChart) *Environment
- func (m *Environment) AddHelm(chart ConnectedChart) *Environment
- func (m *Environment) AddHelmCharts(charts []ConnectedChart) *Environment
- func (m *Environment) ClearCharts() error
- func (m *Environment) ClearCoverage() error
- func (m *Environment) CopyFromPod(selector, containerName, srcPath, destPath string) error
- func (m *Environment) CopyToPod(selector, containerName, srcPath, destPath string) error
- func (m *Environment) Deploy() error
- func (m *Environment) DeployCustomReadyConditions(customCheck *client.ReadyCheckData, customPodCount int) error
- func (m *Environment) DumpLogs(path string) error
- func (m *Environment) Manifest() string
- func (m *Environment) PrintExportData() error
- func (m *Environment) PullOCIChart(chart ConnectedChart) (string, error)
- func (m *Environment) ReplaceHelm(name string, chart ConnectedChart) (*Environment, error)
- func (m *Environment) ResourcesSummary(selector string) (map[string]map[string]string, error)
- func (m *Environment) RolloutRestartBySelector(resource string, selector string) error
- func (m *Environment) RolloutStatefulSets() error
- func (m *Environment) Run() error
- func (m *Environment) RunCustomReadyConditions(customCheck *client.ReadyCheckData, podCount int) error
- func (m *Environment) RunUpdated(podCount int) error
- func (m *Environment) SaveCoverage() error
- func (m *Environment) Shutdown() error
- func (m *Environment) UpdateHelm(name string, values map[string]any) (*Environment, error)
- func (m *Environment) UpdateManifest()
- func (m *Environment) WillUseRemoteRunner() bool
- type PluginNodeDetail
- type Props
Constants ¶
const ( COVERAGE_DIR string = "cover" FAILED_FUND_RETURN string = "FAILED_FUND_RETURN" TEST_FAILED string = "TEST_FAILED" )
const ( ErrInvalidOCI string = "OCI chart url should be in format oci://$ECR_URL/$ECR_REGISTRY_NAME/$CHART_NAME:[?$CHART_VERSION], was %s" ErrOCIPull string = "failed to pull OCI repo: %s" )
const REMOTE_RUNNER_NAME = "remote-test-runner"
Variables ¶
This section is empty.
Functions ¶
func DataFromRunner ¶
func DataFromRunner(props *Props) func(root cdk8s.Chart) ConnectedChart
DataFromRunner - we create this pod to share same persistent volume as remote-runner-node container. This container keeps on running and stays alive after the remote-runner-node gets completed, so that the calling test can access all files generated by remote runner.
func DefaultJobLogFunction ¶
func DefaultJobLogFunction(e *Environment, message string)
func MkdirIfNotExists ¶
func NewRunner ¶
func NewRunner(props *Props) func(root cdk8s.Chart) ConnectedChart
Types ¶
type Artifacts ¶
type Artifacts struct { Namespace string DBName string Client *client.K8sClient // contains filtered or unexported fields }
Artifacts is an artifacts dumping structure that copies logs and database dumps for all deployed pods
func NewArtifacts ¶
NewArtifacts create new artifacts instance for provided environment
type Chart ¶
type Chart struct {
Props *Props
}
func (Chart) ExportData ¶
func (m Chart) ExportData(e *Environment) error
func (Chart) GetVersion ¶
func (Chart) IsDeploymentNeeded ¶
type Config ¶
type Config struct { // TTL is time to live for the environment, used with kyverno TTL time.Duration // NamespacePrefix is a static namespace prefix NamespacePrefix string // Namespace is full namespace name Namespace string // Labels is a set of labels applied to the namespace in a format of "key=value" Labels []string // PodLabels is a set of labels applied to every pod in the namespace PodLabels map[string]string // PreventPodEviction if true sets a k8s annotation safe-to-evict=false to prevent pods from being evicted // Note: This should only be used if your test is completely incapable of handling things like K8s rebalances without failing. // If that is the case, it's worth the effort to make your test fault-tolerant soon. The alternative is expensive and infuriating. PreventPodEviction bool // Allow deployment to nodes with these tolerances Tolerations []map[string]string // Restrict deployment to only nodes matching a particular node role NodeSelector map[string]string // ReadyCheckData is settings for readiness probes checks for all deployment components // checking that all pods are ready by default with 8 minutes timeout // &client.ReadyCheckData{ // ReadinessProbeCheckSelector: "", // Timeout: 15 * time.Minute, // } ReadyCheckData *client.ReadyCheckData // DryRun if true, app will just generate a manifest in local dir DryRun bool // InsideK8s used for long-running soak tests where you connect to env from the inside InsideK8s bool // SkipManifestUpdate will skip updating the manifest upon connecting to the environment. Should be true if you wish to update the manifest (e.g. upgrade pods) SkipManifestUpdate bool // KeepConnection keeps connection until interrupted with a signal, useful when prototyping and debugging a new env KeepConnection bool // RemoveOnInterrupt automatically removes an environment on interrupt RemoveOnInterrupt bool // UpdateWaitInterval an interval to wait for deployment update started UpdateWaitInterval time.Duration // Remote Runner Specific Variables // // JobImage an image to run environment as a job inside k8s JobImage string // Specify only if you want remote-runner to start with a specific name RunnerName string // Specify only if you want to mount reports from test run in remote runner ReportPath string // JobLogFunction a function that will be run on each log JobLogFunction func(*Environment, string) // Test the testing library current Test struct Test *testing.T // contains filtered or unexported fields }
Config is an environment common configuration, labels, annotations, connection types, readiness check, etc.
type ConnectedChart ¶
type ConnectedChart interface { // IsDeploymentNeeded // true - we deploy/connect and expose environment data // false - we are using external environment, but still exposing data IsDeploymentNeeded() bool // GetName name of the deployed part GetName() string // GetPath get Helm chart path, repo or local path GetPath() string // GetVersion gets the chart's version, empty string if none is specified GetVersion() string // GetProps get code props if it's typed environment GetProps() any // GetValues get values.yml props as map, if it's Helm GetValues() *map[string]any // ExportData export deployment part data in the env ExportData(e *Environment) error }
ConnectedChart interface to interact both with cdk8s apps and helm charts
type CoverageProfileParams ¶
type Environment ¶
type Environment struct { App cdk8s.App CurrentManifest string Charts []ConnectedChart // All connected charts in the Cfg *Config // The environment specific config Client *client.K8sClient // Client connecting to the K8s cluster Fwd *client.Forwarder // Used to forward ports from local machine to the K8s cluster Artifacts *Artifacts Chaos *client.Chaos URLs map[string][]string // General URLs of launched resources. Uses '_local' to delineate forwarded ports PluginNodeDetails []*PluginNodeDetail // PluginNodeDetails has convenient details for connecting to plugin deployments // contains filtered or unexported fields }
Environment describes a launched test environment
func (*Environment) AddChart ¶
func (m *Environment) AddChart(f func(root cdk8s.Chart) ConnectedChart) *Environment
AddChart adds a chart to the deployment
func (*Environment) AddHelm ¶
func (m *Environment) AddHelm(chart ConnectedChart) *Environment
AddHelm adds a helm chart to the testing environment
func (*Environment) AddHelmCharts ¶
func (m *Environment) AddHelmCharts(charts []ConnectedChart) *Environment
AddHelmCharts adds multiple helm charts to the testing environment
func (*Environment) ClearCharts ¶
func (m *Environment) ClearCharts() error
ClearCharts recreates cdk8s app
func (*Environment) ClearCoverage ¶
func (m *Environment) ClearCoverage() error
func (*Environment) CopyFromPod ¶
func (m *Environment) CopyFromPod(selector, containerName, srcPath, destPath string) error
CopyFromPod lists pods with given selector, it copies files from local to destPath at pods filtered by given selector
func (*Environment) CopyToPod ¶
func (m *Environment) CopyToPod(selector, containerName, srcPath, destPath string) error
CopyToPod lists pods with given selector, it copies files from srcPath at pods filtered by given selector to local destPath
func (*Environment) Deploy ¶
func (m *Environment) Deploy() error
Deploy deploy current manifest and check logs for readiness
func (*Environment) DeployCustomReadyConditions ¶
func (m *Environment) DeployCustomReadyConditions(customCheck *client.ReadyCheckData, customPodCount int) error
DeployCustomReadyConditions deploy current manifest with added custom readiness checks
func (*Environment) DumpLogs ¶
func (m *Environment) DumpLogs(path string) error
DumpLogs dumps all logs into a file
func (*Environment) Manifest ¶
func (m *Environment) Manifest() string
func (*Environment) PrintExportData ¶
func (m *Environment) PrintExportData() error
PrintExportData prints export data
func (*Environment) PullOCIChart ¶
func (m *Environment) PullOCIChart(chart ConnectedChart) (string, error)
PullOCIChart handles working with OCI format repositories https://helm.sh/docs/topics/registries/ API is not compatible between helm repos and OCI repos, so we download and untar the chart
func (*Environment) ReplaceHelm ¶
func (m *Environment) ReplaceHelm(name string, chart ConnectedChart) (*Environment, error)
ReplaceHelm entirely replaces an existing helm chart with a new one Note: you need to call Run() after this to apply the changes. If you're modifying ConfigMap values, you'll probably need to use RollOutStatefulSets to apply the changes to the pods. https://stackoverflow.com/questions/57356521/rollingupdate-for-stateful-set-doesnt-restart-pods-and-changes-from-updated-con
func (*Environment) ResourcesSummary ¶
ResourcesSummary returns resources summary for selected pods as a map, used in reports
func (*Environment) RolloutRestartBySelector ¶
func (m *Environment) RolloutRestartBySelector(resource string, selector string) error
RolloutRestartBySelector applies "rollout restart" to the selected resources
func (*Environment) RolloutStatefulSets ¶
func (m *Environment) RolloutStatefulSets() error
RolloutStatefulSets applies "rollout statefulset" to all existing statefulsets in our namespace
func (*Environment) Run ¶
func (m *Environment) Run() error
Run deploys or connects to already created environment
func (*Environment) RunCustomReadyConditions ¶
func (m *Environment) RunCustomReadyConditions(customCheck *client.ReadyCheckData, podCount int) error
RunCustomReadyConditions Runs the environment with custom ready conditions for a supplied pod count
func (*Environment) RunUpdated ¶
func (m *Environment) RunUpdated(podCount int) error
RunUpdated runs the environment and checks for pods with `updated=true` label
func (*Environment) SaveCoverage ¶
func (m *Environment) SaveCoverage() error
func (*Environment) Shutdown ¶
func (m *Environment) Shutdown() error
Shutdown environment, remove namespace
func (*Environment) UpdateHelm ¶
func (m *Environment) UpdateHelm(name string, values map[string]any) (*Environment, error)
UpdateHelm update a helm chart with new values. The pod will launch with an `updated=true` label if it's a Plugin node. Note: If you're modifying ConfigMap values, you'll probably need to use RollOutStatefulSets to apply the changes to the pods. https://stackoverflow.com/questions/57356521/rollingupdate-for-stateful-set-doesnt-restart-pods-and-changes-from-updated-con
func (*Environment) UpdateManifest ¶
func (m *Environment) UpdateManifest()
Update current manifest based on the cdk8s app state
func (*Environment) WillUseRemoteRunner ¶
func (m *Environment) WillUseRemoteRunner() bool
WillUseRemoteRunner determines if we need to start the remote runner
type PluginNodeDetail ¶
type PluginNodeDetail struct { // ChartName details the name of the Helm chart this node uses, handy for modifying deployment values // Note: if you are using replicas of the same chart, this will be the same for all nodes // Use NewDeployment function for Plugin nodes to make use of this ChartName string // PodName is the name of the pod running the plugin node PodName string // LocalIP is the URL to connect to the node from the local machine LocalIP string // InternalIP is the URL to connect to the node from inside the K8s cluster InternalIP string // DBLocalIP is the URL to connect to the node's database from the local machine DBLocalIP string }
PluginNodeDetail contains details about a plugin node deployment