Testing

    To run all tests:

    The integration tests takes a cluster spec and builds cloudformation/terraform templates. For new functionality, consider adding it to the complex.example.com cluster unless it conflicts with existing functionality in that cluster. To add a new integration test, create a new directory in tests/integration/update_cluster/ and put the cluster spec in in-v1alpha2.yaml. Use a unique cluster name.

    Then edit ./cmd/kops/integration_test.go and add the test function with the cluster name and directory from above.

    Lastly run ./hack/update-expected.sh to generate the expected output.

    Kubernetes e2e testing

    Kubetest2 is the framework for launching and running end-to-end tests on Kubernetes, and the best approach to test your kOps cluster is to use the same Go modules to perform the e2e testing.

    Before running kubetest2 you will need to install the core, and all deployers and testers Go modules.

    1. make test-e2e-install

    See to gain a further understanding of the Kubernetes e2e test framework.

    Following the examples below, kubetest2 will download test artifacts to ./_artifacts.

    You can run something like the following to have kubetest2 re-use an existing cluster.

    This assumes you have already built the kOps binary from source. The exact path to the kops binary used in the --kops-binary-path flag may differ.

    The environment variable KOPS_ROOT is the full path to your local GitHub kOps working directory.

    It’s also possible to run the Kubernetes Conformance test suite by replacing the --skip-regex flag with --focus-regex='\[Conformance\]'.

    By adding the --up flag, kubetest2 will spin up a new cluster. Flags can be passed to the kops create cluster command via the --create-args flag. In most cases, you also need to add a few additional flags. See kubetest2 kops --help for the full list.

    1. kubetest2 kops \
    2. --up \
    3. --cloud-provider=aws \
    4. --cluster-name=my.testcluster.com \
    5. --create-args="--networking calico" \
    6. --kops-binary-path=${KOPS_ROOT}/.bazel-bin/cmd/kops/linux-amd64/kops \
    7. --test=kops \
    8. --
    9. -- \
    10. --test-package-version=v1.20.2 \
    11. --parallel 25 \
    12. --skip-regex="\[Slow\]|\[Serial\]|\[Disruptive\]|\[Flaky\]|\[Feature:.+\]|\[HPA\]|Dashboard|RuntimeClass|RuntimeHandler"

    If you don’t specify any additional flags, the kOps deployer Go module will create a kubernetes cluster using the following defaults.

    For the --zones flag, the kOps deployer will select a random zone based on the --cloud-provider flag, for aws the full list of AWS zones can be found here and for gce the full list of GCE zones can be found .

    Althernatively, you can generate a kOps cluster spec YAML manifest based on your own requirments using kops create cluster my.testcluster.com ... --dry-run -oyaml > my.testcluster.com.yaml and then run the kubetest2 e2e tests using the --template-path flag to specify the full path to the YAML manifest.

    1. kubetest2 kops \
    2. -v 2 \
    3. --cloud-provider=aws \
    4. --cluster-name=my.testcluster.com \
    5. --kops-binary-path=${KOPS_ROOT}/.bazel-bin/cmd/kops/linux-amd64/kops \
    6. --kubernetes-version=v1.20.2 \
    7. --template-path=my.testcluster.com.yaml \
    8. -- \
    9. --test-package-version=v1.20.2 \
    10. --parallel 25 \
    11. --skip-regex="\[Slow\]|\[Serial\]|\[Disruptive\]|\[Flaky\]|\[Feature:.+\]|\[HPA\]|Dashboard|RuntimeClass|RuntimeHandler"

    If you encounter the following error, you will need to add your SSH public key to the kOps cluster spec YAML manifest.

    1. ---
    2. apiVersion: kops.k8s.io/v1alpha2
    3. kind: SSHCredential
    4. metadata:
    5. name: admin
    6. labels:
    7. kops.k8s.io/cluster: my.testcluster.com
    8. spec:
    9. publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC..."

    If you want to run the tests against your development version of kOps, you need to upload the binaries and set the environment variables as described in Adding a new feature.