Tests a given CFCR K8s cluster can be backed up and restored using bbr
.
The acceptance test suite provides hooks around bbr director backup
and bbr director restore
.
IMPORTANT: This suite backs up and restores the universe of K8s. If it is run in parallel with other tests that create and then validate objects, there can be a race condition wherein those objects are removed before their subsequent restoration, causing unreliable, "flake", false-positive, failed results.
- Install Golang
- Install
ginkgo
CLI - Install
kubectl
CLI - Download
bbr
CLI and add it thePATH
We encourage you to use our set-kubconfig
and run-k-drats
CI tasks to run k-DRATS in your Concourse pipeline.
Please refer to our k-drats pipeline definition for a working example.
- Spin up a CFCR deployment
- kubo-deployment is supported. Make sure you apply the enable-bbr opsfile at deploy time to ensure the backup and restore scripts are enabled.
- Clone this repo
$ go get github.com/cloudfoundry-incubator/kubo-disaster-recovery-acceptance-tests $ cd $GOPATH/src/github.com/cloudfoundry-incubator/kubo-disaster-recovery-acceptance-tests
- Create an
config.json
file, for example:{ "run_test_case_deployment": true, "run_test_case_etcd_cluster": true, "timeout_in_minutes": 5 }
- Export
CONFIG_PATH
to be path toconfig.json
file you just created. - Export the following BOSH environment variables
BOSH_ENVIRONMENT
- URL of BOSH Director which has deployed the CFCR clusterBOSH_CLIENT
- BOSH Director usernameBOSH_CLIENT_SECRET
- BOSH Director passwordBOSH_CA_CERT
- BOSH Director's CA cert contentBOSH_ALL_PROXY
- optional, set the proxy to be used in case the BOSH director is behind a jumpboxBOSH_DEPLOYMENT
- name of the CFCR deployment to backup and restore
- Configure
kubectl
with a cluster and admin credentials, for example:$ kubectl config set-cluster CLUSTER_NAME --server=https://API_IP:8443 --certificate-authority=PATH/TO/CA_CERT --embed-certs=true $ kubectl config set-credentials ADMIN_USERNAME --token=ADMIN_PASSWORD $ kubectl config set-context NAME --cluster=CLUSTER_NAME --user=ADMIN_USERNAME $ kubectl config use-context NAME
- Export
KUBECONFIG
to the path to thekubectl
config, for example~/.kube/config
. - Run acceptance tests
$ ./scripts/_run_acceptance_tests.sh
timeout_in_minutes
- ginkgoEventually
timeout in minutes, default5
run_test_case_<test-case-name>
- flag for whether to run a given test case, if omitted defaults tofalse
k-DRATS runs a collection of test cases against a CFCR cluster.
Test cases should be used for checking that K8s data has been backed up and restored correctly. For example, if two workflows are deployed before bbr director backup
, and the workflows are removed after taking the backup. Then after a successful bbr director restore
, workflows will be restored back to their original state.
To add extra test cases, create a new test case that implements the TestCase
interface.
The methods that need to be implemented are:
Name() string
- should return name of the test case.BeforeBackup(Config)
- runs before the backup is taken, and should create state in the K8s cluster to be backed up.AfterBackup(Config)
- runs after the backup is complete but before the restore is started.AfterRestore(Config)
- runs after the restore is complete, and should assert that the state in the restored K8s cluster matches that created inBeforeBackup(Config)
.Cleanup(Config)
- should clean up the state created in the K8s cluster through the test.
Config
contains the config for accessing the target K8s. Note: the use of this config is optional, kubectl
is already configured to access the target K8s cluster when a test case runs.
- Create a new test case in the testcases package.
- Add the newly created test case to the list of
availableTestCases
inacceptance_suite_test.go
.