From 54743a10ea9f6da312911e666afb4eff97b8f229 Mon Sep 17 00:00:00 2001 From: smalltown Date: Wed, 27 Mar 2019 14:10:43 +0800 Subject: [PATCH 1/5] change the folder for terratest --- .gitignore | 2 + aws/kube-etcd/ami.tf | 36 ----- aws/kube-master/master.tf | 76 ---------- aws/kube-worker-general/variables.tf | 136 ------------------ aws/kube-worker-general/worker.tf | 86 ----------- aws/kube-worker-mixed/ignition.tf | 88 ------------ aws/kube-worker-mixed/main.tf | 20 --- aws/kube-worker-mixed/role.tf | 70 --------- .../ign-aws-iam-authenticator.tf | 2 +- examples/aws-iam-authenticator/k8s/nginx.yml | 33 +++++ examples/aws-iam-authenticator/main.tf | 45 +++--- examples/aws-iam-authenticator/variables.tf | 10 ++ examples/{eks_cluster => eks-cluster}/main.tf | 4 +- .../{eks_cluster => eks-cluster}/outputs.tf | 0 .../{eks_cluster => eks-cluster}/variables.tf | 0 examples/{eks_worker => eks-worker}/main.tf | 8 +- .../patch-aws-auth-cm.yaml.tpl | 0 .../{eks_worker => eks-worker}/variables.tf | 0 examples/elastikube-cluster/k8s/nginx.yml | 33 +++++ .../main.tf | 72 +++++----- examples/elastikube-cluster/outputs.tf | 7 + examples/elastikube-cluster/variables.tf | 45 ++++++ examples/elastikube_cluster/variables.tf | 23 --- examples/self-signed-etcd-certs/main.tf | 8 +- {aws => modules/aws}/container_linux/main.tf | 0 .../aws}/container_linux/outputs.tf | 0 .../aws}/container_linux/variables.tf | 0 {aws => modules/aws}/eks/ignition/assets.tf | 0 {aws => modules/aws}/eks/ignition/outputs.tf | 0 .../10-always-update-ca-certificates.conf | 0 .../resources/dropins/10-dockeropts.conf | 0 .../resources/dropins/10-timesyncd.conf | 0 .../ignition/resources/kubernetes/kubeconfig | 0 .../ignition/resources/kubernetes/kubelet.env | 0 .../services/heptio-authenticator-aws.service | 0 .../resources/services/kubelet.service | 0 .../resources/sysctl.d/max-user-watches.conf | 0 .../aws}/eks/ignition/variables.tf | 0 .../aws}/eks/master/aws-auth-cm.tf | 0 {aws => modules/aws}/eks/master/cluster.tf | 0 {aws => modules/aws}/eks/master/main.tf | 0 {aws => modules/aws}/eks/master/outputs.tf | 0 .../eks/master/resources/aws-auth-cm.yaml.tpl | 0 .../aws}/eks/master/resources/kubeconfig | 0 {aws => modules/aws}/eks/master/role-eks.tf | 0 {aws => modules/aws}/eks/master/role-spot.tf | 0 .../aws}/eks/master/s3-kubeconfig.tf | 0 .../aws}/eks/master/security-group-eks.tf | 0 .../aws}/eks/master/security-group-worker.tf | 0 {aws => modules/aws}/eks/master/variables.tf | 0 {aws => modules/aws}/eks/worker-asg/asg.tf | 0 {aws => modules/aws}/eks/worker-asg/common.tf | 0 {aws => modules/aws}/eks/worker-asg/main.tf | 0 .../aws}/eks/worker-asg/outputs.tf | 0 .../aws}/eks/worker-asg/variables.tf | 0 {aws => modules/aws}/eks/worker-common/ami.tf | 0 .../aws}/eks/worker-common/ignition.tf | 0 .../aws}/eks/worker-common/ignition_s3.tf | 0 .../aws}/eks/worker-common/outputs.tf | 0 .../aws}/eks/worker-common/role.tf | 0 .../aws}/eks/worker-common/variables.tf | 0 .../aws}/eks/worker-spot/common.tf | 0 {aws => modules/aws}/eks/worker-spot/main.tf | 0 .../aws}/eks/worker-spot/outputs.tf | 0 {aws => modules/aws}/eks/worker-spot/spot.tf | 0 .../aws}/eks/worker-spot/variables.tf | 0 {aws => modules/aws}/elastikube/etcd.tf | 2 +- .../aws}/elastikube/ign-essential.tf | 0 {aws => modules/aws}/elastikube/main.tf | 2 +- {aws => modules/aws}/elastikube/master.tf | 6 +- {aws => modules/aws}/elastikube/outputs.tf | 0 {aws => modules/aws}/elastikube/s3.tf | 0 {aws => modules/aws}/elastikube/variables.tf | 30 +++- {aws => modules/aws}/elastikube/worker-sg.tf | 0 {aws => modules/aws}/elastikube/zone.tf | 6 +- .../aws/kube-etcd}/ami.tf | 3 + {aws => modules/aws}/kube-etcd/certs.tf | 0 {aws => modules/aws}/kube-etcd/dns.tf | 0 {aws => modules/aws}/kube-etcd/etcd.tf | 0 .../aws}/kube-etcd/ign-node-exporter.tf | 0 {aws => modules/aws}/kube-etcd/ignition.tf | 0 {aws => modules/aws}/kube-etcd/main.tf | 2 +- {aws => modules/aws}/kube-etcd/outputs.tf | 0 {aws => modules/aws}/kube-etcd/role.tf | 0 {aws => modules/aws}/kube-etcd/sg.tf | 0 {aws => modules/aws}/kube-etcd/variables.tf | 0 {aws => modules/aws}/kube-master/ami.tf | 3 + {aws => modules/aws}/kube-master/certs.tf | 0 .../aws}/kube-master/ign-control-plane.tf | 0 .../aws}/kube-master/ign-kubelet.tf | 0 {aws => modules/aws}/kube-master/ignition.tf | 0 {aws => modules/aws}/kube-master/lb.tf | 6 +- {aws => modules/aws}/kube-master/main.tf | 2 +- modules/aws/kube-master/master.tf | 103 +++++++++++++ {aws => modules/aws}/kube-master/outputs.tf | 0 {aws => modules/aws}/kube-master/role.tf | 0 {aws => modules/aws}/kube-master/s3.tf | 0 {aws => modules/aws}/kube-master/sg.tf | 0 {aws => modules/aws}/kube-master/variables.tf | 29 +++- .../aws/kube-worker-hybird}/ami.tf | 3 + .../aws/kube-worker-hybird}/ignition.tf | 0 .../aws/kube-worker-hybird}/main.tf | 2 +- .../aws/kube-worker-hybird}/role.tf | 0 .../aws/kube-worker-hybird}/variables.tf | 5 +- .../aws/kube-worker-hybird}/worker.tf | 0 {aws => modules/aws}/network/bastion.tf | 5 + {aws => modules/aws}/network/main.tf | 6 +- {aws => modules/aws}/network/outputs.tf | 2 +- modules/aws/network/resources/user_data | 13 ++ {aws => modules/aws}/network/variables.tf | 0 {aws => modules/aws}/network/vpc-private.tf | 0 {aws => modules/aws}/network/vpc-public.tf | 0 {aws => modules/aws}/network/vpc.tf | 0 {aws => modules/aws}/network/zone.tf | 0 .../aws-iam-authenticator/manifests.tf | 0 .../aws-iam-authenticator/outputs.tf | 0 .../aws-iam-authenticator/provision.tf | 0 .../resources/kubernetes/webhook/kubeconfig | 0 .../resources/services/provision.service | 0 .../aws-iam-authenticator/variables.tf | 0 .../webhook-kubeconfig.tf | 0 .../ignitions}/docker/assets.tf | 0 .../ignitions}/docker/outputs.tf | 0 .../resources/dropins/10-dockeropts.conf | 0 .../ignitions}/docker/variables.tf | 0 .../ignitions}/etcd/assets.tf | 0 .../ignitions}/etcd/certs.tf | 0 .../ignitions}/etcd/outputs.tf | 0 .../resources/dropins/40-etcd-cluster.conf | 0 .../ignitions}/etcd/variables.tf | 0 .../ignitions}/iscsi/assets.tf | 0 .../ignitions}/iscsi/outputs.tf | 0 .../ignitions}/iscsi/variables.tf | 0 .../ignitions}/kube-addon-dns/coredns-yaml.tf | 0 .../ignitions}/kube-addon-dns/manifests.tf | 0 .../ignitions}/kube-addon-dns/outputs.tf | 0 .../kubernetes/manifests/coredns.yaml | 0 .../ignitions}/kube-addon-dns/variables.tf | 0 .../kube-flannel-yaml.tf | 0 .../kube-addon-flannel-vxlan/manifests.tf | 0 .../kube-addon-flannel-vxlan/outputs.tf | 0 .../resources/addon/kube-flannel.yaml | 0 .../kube-addon-flannel-vxlan/variables.tf | 0 .../kube-addon-manager/kube-addon.tf | 0 .../ignitions}/kube-addon-manager/outputs.tf | 0 .../services/kube-addon-manager.service | 0 .../kube-addon-manager/variables.tf | 2 +- .../kube-addon-proxy/kube-proxy-yaml.tf | 0 .../ignitions}/kube-addon-proxy/outputs.tf | 0 .../kubernetes/addon/kube-proxy.yaml | 0 .../ignitions}/kube-addon-proxy/variables.tf | 2 +- .../ignitions}/kube-audit/manifests.tf | 0 .../ignitions}/kube-audit/outputs.tf | 0 .../ignitions}/kube-audit/policy-yaml.tf | 0 .../resources/kubernetes/policy.yaml | 0 .../ignitions}/kube-audit/variables.tf | 0 .../ignitions}/kube-config/kubeconfig.tf | 0 .../ignitions}/kube-config/outputs.tf | 0 .../resources/kubernetes/kubeconfig | 0 .../ignitions}/kube-config/variables.tf | 0 .../kube-control-plane/kube-apiserver-yaml.tf | 0 .../kube-controller-manager-yaml.tf | 0 .../kube-control-plane/kube-scheduler-yaml.tf | 0 .../kube-system-rbac-role-binding.tf | 0 .../kube-control-plane/manifests.tf | 0 .../ignitions}/kube-control-plane/outputs.tf | 0 .../addon/kube-system-rbac-role-binding.yaml | 0 .../kubernetes/manifests/kube-apiserver.yaml | 0 .../manifests/kube-controller-manager.yaml | 0 .../kubernetes/manifests/kube-scheduler.yaml | 0 .../ignitions}/kube-control-plane/secrets.tf | 0 .../kube-control-plane/variables.tf | 2 +- .../ignitions}/kubelet/kubelet-env.tf | 0 .../ignitions}/kubelet/kubelet.tf | 0 .../ignitions}/kubelet/outputs.tf | 0 .../kubelet/resources/kubernetes/kubelet.env | 0 .../resources/services/kubelet.service | 0 .../ignitions}/kubelet/variables.tf | 2 +- .../ignitions}/locksmithd/assets.tf | 0 .../ignitions}/locksmithd/outputs.tf | 0 .../ignitions}/locksmithd/variables.tf | 0 .../ignitions}/max-user-watches/assets.tf | 0 .../ignitions}/max-user-watches/outputs.tf | 0 .../resources/sysctl.d/max-user-watches.conf | 0 .../ignitions}/max-user-watches/variables.tf | 0 .../node-exporter/node-exporter-fetcher.tf | 0 .../ignitions}/node-exporter/node-exporter.tf | 0 .../ignitions}/node-exporter/outputs.tf | 0 .../services/node-exporter-fetcher.service | 0 .../resources/services/node-exporter.service | 0 .../ignitions}/node-exporter/variables.tf | 0 .../ignitions}/ntp/assets.tf | 0 .../ignitions}/ntp/outputs.tf | 0 .../timesyncd.conf.d/10-timesyncd.conf | 0 .../ignitions}/ntp/variables.tf | 0 .../ignitions}/pod-checkpointer/manifests.tf | 0 .../ignitions}/pod-checkpointer/outputs.tf | 0 .../pod-checkpointer/pod-checkpointer-yaml.tf | 0 .../kubernetes/addon/pod-checkpointer.yaml | 0 .../ignitions}/pod-checkpointer/variables.tf | 0 .../ignitions}/tx-off/assets.tf | 0 .../ignitions}/tx-off/outputs.tf | 0 .../tx-off/resources/services/tx-off.service | 0 .../update-ca-certificates/assets.tf | 0 .../update-ca-certificates/outputs.tf | 0 .../10-always-update-ca-certificates.conf | 0 .../update-ca-certificates/variables.tf | 0 .../tls}/certificate-authority/ca.tf | 0 .../tls}/certificate-authority/main.tf | 0 .../tls}/certificate-authority/outputs.tf | 0 .../tls}/certificate-authority/variables.tf | 0 {tls => modules/tls}/certificate/cert.tf | 0 {tls => modules/tls}/certificate/main.tf | 0 {tls => modules/tls}/certificate/outputs.tf | 0 {tls => modules/tls}/certificate/variables.tf | 0 modules/tls/private-key/main.tf | 3 + modules/tls/private-key/outputs.tf | 12 ++ modules/tls/private-key/ssh_key.tf | 4 + modules/tls/private-key/variables.tf | 0 219 files changed, 432 insertions(+), 629 deletions(-) delete mode 100644 aws/kube-etcd/ami.tf delete mode 100644 aws/kube-master/master.tf delete mode 100644 aws/kube-worker-general/variables.tf delete mode 100644 aws/kube-worker-general/worker.tf delete mode 100644 aws/kube-worker-mixed/ignition.tf delete mode 100644 aws/kube-worker-mixed/main.tf delete mode 100644 aws/kube-worker-mixed/role.tf create mode 100644 examples/aws-iam-authenticator/k8s/nginx.yml rename examples/{eks_cluster => eks-cluster}/main.tf (76%) rename examples/{eks_cluster => eks-cluster}/outputs.tf (100%) rename examples/{eks_cluster => eks-cluster}/variables.tf (100%) rename examples/{eks_worker => eks-worker}/main.tf (96%) rename examples/{eks_worker => eks-worker}/patch-aws-auth-cm.yaml.tpl (100%) rename examples/{eks_worker => eks-worker}/variables.tf (100%) create mode 100644 examples/elastikube-cluster/k8s/nginx.yml rename examples/{elastikube_cluster => elastikube-cluster}/main.tf (69%) create mode 100644 examples/elastikube-cluster/outputs.tf create mode 100644 examples/elastikube-cluster/variables.tf delete mode 100644 examples/elastikube_cluster/variables.tf rename {aws => modules/aws}/container_linux/main.tf (100%) rename {aws => modules/aws}/container_linux/outputs.tf (100%) rename {aws => modules/aws}/container_linux/variables.tf (100%) rename {aws => modules/aws}/eks/ignition/assets.tf (100%) rename {aws => modules/aws}/eks/ignition/outputs.tf (100%) rename {aws => modules/aws}/eks/ignition/resources/dropins/10-always-update-ca-certificates.conf (100%) rename {aws => modules/aws}/eks/ignition/resources/dropins/10-dockeropts.conf (100%) rename {aws => modules/aws}/eks/ignition/resources/dropins/10-timesyncd.conf (100%) rename {aws => modules/aws}/eks/ignition/resources/kubernetes/kubeconfig (100%) rename {aws => modules/aws}/eks/ignition/resources/kubernetes/kubelet.env (100%) rename {aws => modules/aws}/eks/ignition/resources/services/heptio-authenticator-aws.service (100%) rename {aws => modules/aws}/eks/ignition/resources/services/kubelet.service (100%) rename {aws => modules/aws}/eks/ignition/resources/sysctl.d/max-user-watches.conf (100%) rename {aws => modules/aws}/eks/ignition/variables.tf (100%) rename {aws => modules/aws}/eks/master/aws-auth-cm.tf (100%) rename {aws => modules/aws}/eks/master/cluster.tf (100%) rename {aws => modules/aws}/eks/master/main.tf (100%) rename {aws => modules/aws}/eks/master/outputs.tf (100%) rename {aws => modules/aws}/eks/master/resources/aws-auth-cm.yaml.tpl (100%) rename {aws => modules/aws}/eks/master/resources/kubeconfig (100%) rename {aws => modules/aws}/eks/master/role-eks.tf (100%) rename {aws => modules/aws}/eks/master/role-spot.tf (100%) rename {aws => modules/aws}/eks/master/s3-kubeconfig.tf (100%) rename {aws => modules/aws}/eks/master/security-group-eks.tf (100%) rename {aws => modules/aws}/eks/master/security-group-worker.tf (100%) rename {aws => modules/aws}/eks/master/variables.tf (100%) rename {aws => modules/aws}/eks/worker-asg/asg.tf (100%) rename {aws => modules/aws}/eks/worker-asg/common.tf (100%) rename {aws => modules/aws}/eks/worker-asg/main.tf (100%) rename {aws => modules/aws}/eks/worker-asg/outputs.tf (100%) rename {aws => modules/aws}/eks/worker-asg/variables.tf (100%) rename {aws => modules/aws}/eks/worker-common/ami.tf (100%) rename {aws => modules/aws}/eks/worker-common/ignition.tf (100%) rename {aws => modules/aws}/eks/worker-common/ignition_s3.tf (100%) rename {aws => modules/aws}/eks/worker-common/outputs.tf (100%) rename {aws => modules/aws}/eks/worker-common/role.tf (100%) rename {aws => modules/aws}/eks/worker-common/variables.tf (100%) rename {aws => modules/aws}/eks/worker-spot/common.tf (100%) rename {aws => modules/aws}/eks/worker-spot/main.tf (100%) rename {aws => modules/aws}/eks/worker-spot/outputs.tf (100%) rename {aws => modules/aws}/eks/worker-spot/spot.tf (100%) rename {aws => modules/aws}/eks/worker-spot/variables.tf (100%) rename {aws => modules/aws}/elastikube/etcd.tf (91%) rename {aws => modules/aws}/elastikube/ign-essential.tf (100%) rename {aws => modules/aws}/elastikube/main.tf (90%) rename {aws => modules/aws}/elastikube/master.tf (89%) rename {aws => modules/aws}/elastikube/outputs.tf (100%) rename {aws => modules/aws}/elastikube/s3.tf (100%) rename {aws => modules/aws}/elastikube/variables.tf (86%) rename {aws => modules/aws}/elastikube/worker-sg.tf (100%) rename {aws => modules/aws}/elastikube/zone.tf (83%) rename {aws/kube-worker-general => modules/aws/kube-etcd}/ami.tf (95%) rename {aws => modules/aws}/kube-etcd/certs.tf (100%) rename {aws => modules/aws}/kube-etcd/dns.tf (100%) rename {aws => modules/aws}/kube-etcd/etcd.tf (100%) rename {aws => modules/aws}/kube-etcd/ign-node-exporter.tf (100%) rename {aws => modules/aws}/kube-etcd/ignition.tf (100%) rename {aws => modules/aws}/kube-etcd/main.tf (94%) rename {aws => modules/aws}/kube-etcd/outputs.tf (100%) rename {aws => modules/aws}/kube-etcd/role.tf (100%) rename {aws => modules/aws}/kube-etcd/sg.tf (100%) rename {aws => modules/aws}/kube-etcd/variables.tf (100%) rename {aws => modules/aws}/kube-master/ami.tf (95%) rename {aws => modules/aws}/kube-master/certs.tf (100%) rename {aws => modules/aws}/kube-master/ign-control-plane.tf (100%) rename {aws => modules/aws}/kube-master/ign-kubelet.tf (100%) rename {aws => modules/aws}/kube-master/ignition.tf (100%) rename {aws => modules/aws}/kube-master/lb.tf (82%) rename {aws => modules/aws}/kube-master/main.tf (95%) create mode 100644 modules/aws/kube-master/master.tf rename {aws => modules/aws}/kube-master/outputs.tf (100%) rename {aws => modules/aws}/kube-master/role.tf (100%) rename {aws => modules/aws}/kube-master/s3.tf (100%) rename {aws => modules/aws}/kube-master/sg.tf (100%) rename {aws => modules/aws}/kube-master/variables.tf (85%) rename {aws/kube-worker-mixed => modules/aws/kube-worker-hybird}/ami.tf (95%) rename {aws/kube-worker-general => modules/aws/kube-worker-hybird}/ignition.tf (100%) rename {aws/kube-worker-general => modules/aws/kube-worker-hybird}/main.tf (95%) rename {aws/kube-worker-general => modules/aws/kube-worker-hybird}/role.tf (100%) rename {aws/kube-worker-mixed => modules/aws/kube-worker-hybird}/variables.tf (97%) rename {aws/kube-worker-mixed => modules/aws/kube-worker-hybird}/worker.tf (100%) rename {aws => modules/aws}/network/bastion.tf (91%) rename {aws => modules/aws}/network/main.tf (80%) rename {aws => modules/aws}/network/outputs.tf (92%) create mode 100644 modules/aws/network/resources/user_data rename {aws => modules/aws}/network/variables.tf (100%) rename {aws => modules/aws}/network/vpc-private.tf (100%) rename {aws => modules/aws}/network/vpc-public.tf (100%) rename {aws => modules/aws}/network/vpc.tf (100%) rename {aws => modules/aws}/network/zone.tf (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/manifests.tf (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/outputs.tf (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/provision.tf (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/resources/kubernetes/webhook/kubeconfig (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/resources/services/provision.service (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/variables.tf (100%) rename {ignitions => modules/ignitions}/aws-iam-authenticator/webhook-kubeconfig.tf (100%) rename {ignitions => modules/ignitions}/docker/assets.tf (100%) rename {ignitions => modules/ignitions}/docker/outputs.tf (100%) rename {ignitions => modules/ignitions}/docker/resources/dropins/10-dockeropts.conf (100%) rename {ignitions => modules/ignitions}/docker/variables.tf (100%) rename {ignitions => modules/ignitions}/etcd/assets.tf (100%) rename {ignitions => modules/ignitions}/etcd/certs.tf (100%) rename {ignitions => modules/ignitions}/etcd/outputs.tf (100%) rename {ignitions => modules/ignitions}/etcd/resources/dropins/40-etcd-cluster.conf (100%) rename {ignitions => modules/ignitions}/etcd/variables.tf (100%) rename {ignitions => modules/ignitions}/iscsi/assets.tf (100%) rename {ignitions => modules/ignitions}/iscsi/outputs.tf (100%) rename {ignitions => modules/ignitions}/iscsi/variables.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-dns/coredns-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-dns/manifests.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-dns/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-dns/resources/kubernetes/manifests/coredns.yaml (100%) rename {ignitions => modules/ignitions}/kube-addon-dns/variables.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-flannel-vxlan/kube-flannel-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-flannel-vxlan/manifests.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-flannel-vxlan/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-flannel-vxlan/resources/addon/kube-flannel.yaml (100%) rename {ignitions => modules/ignitions}/kube-addon-flannel-vxlan/variables.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-manager/kube-addon.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-manager/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-manager/resources/services/kube-addon-manager.service (100%) rename {ignitions => modules/ignitions}/kube-addon-manager/variables.tf (93%) rename {ignitions => modules/ignitions}/kube-addon-proxy/kube-proxy-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-proxy/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-addon-proxy/resources/kubernetes/addon/kube-proxy.yaml (100%) rename {ignitions => modules/ignitions}/kube-addon-proxy/variables.tf (94%) rename {ignitions => modules/ignitions}/kube-audit/manifests.tf (100%) rename {ignitions => modules/ignitions}/kube-audit/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-audit/policy-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-audit/resources/kubernetes/policy.yaml (100%) rename {ignitions => modules/ignitions}/kube-audit/variables.tf (100%) rename {ignitions => modules/ignitions}/kube-config/kubeconfig.tf (100%) rename {ignitions => modules/ignitions}/kube-config/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-config/resources/kubernetes/kubeconfig (100%) rename {ignitions => modules/ignitions}/kube-config/variables.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/kube-apiserver-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/kube-controller-manager-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/kube-scheduler-yaml.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/kube-system-rbac-role-binding.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/manifests.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/outputs.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/resources/kubernetes/addon/kube-system-rbac-role-binding.yaml (100%) rename {ignitions => modules/ignitions}/kube-control-plane/resources/kubernetes/manifests/kube-apiserver.yaml (100%) rename {ignitions => modules/ignitions}/kube-control-plane/resources/kubernetes/manifests/kube-controller-manager.yaml (100%) rename {ignitions => modules/ignitions}/kube-control-plane/resources/kubernetes/manifests/kube-scheduler.yaml (100%) rename {ignitions => modules/ignitions}/kube-control-plane/secrets.tf (100%) rename {ignitions => modules/ignitions}/kube-control-plane/variables.tf (98%) rename {ignitions => modules/ignitions}/kubelet/kubelet-env.tf (100%) rename {ignitions => modules/ignitions}/kubelet/kubelet.tf (100%) rename {ignitions => modules/ignitions}/kubelet/outputs.tf (100%) rename {ignitions => modules/ignitions}/kubelet/resources/kubernetes/kubelet.env (100%) rename {ignitions => modules/ignitions}/kubelet/resources/services/kubelet.service (100%) rename {ignitions => modules/ignitions}/kubelet/variables.tf (98%) rename {ignitions => modules/ignitions}/locksmithd/assets.tf (100%) rename {ignitions => modules/ignitions}/locksmithd/outputs.tf (100%) rename {ignitions => modules/ignitions}/locksmithd/variables.tf (100%) rename {ignitions => modules/ignitions}/max-user-watches/assets.tf (100%) rename {ignitions => modules/ignitions}/max-user-watches/outputs.tf (100%) rename {ignitions => modules/ignitions}/max-user-watches/resources/sysctl.d/max-user-watches.conf (100%) rename {ignitions => modules/ignitions}/max-user-watches/variables.tf (100%) rename {ignitions => modules/ignitions}/node-exporter/node-exporter-fetcher.tf (100%) rename {ignitions => modules/ignitions}/node-exporter/node-exporter.tf (100%) rename {ignitions => modules/ignitions}/node-exporter/outputs.tf (100%) rename {ignitions => modules/ignitions}/node-exporter/resources/services/node-exporter-fetcher.service (100%) rename {ignitions => modules/ignitions}/node-exporter/resources/services/node-exporter.service (100%) rename {ignitions => modules/ignitions}/node-exporter/variables.tf (100%) rename {ignitions => modules/ignitions}/ntp/assets.tf (100%) rename {ignitions => modules/ignitions}/ntp/outputs.tf (100%) rename {ignitions => modules/ignitions}/ntp/resources/systemd/timesyncd.conf.d/10-timesyncd.conf (100%) rename {ignitions => modules/ignitions}/ntp/variables.tf (100%) rename {ignitions => modules/ignitions}/pod-checkpointer/manifests.tf (100%) rename {ignitions => modules/ignitions}/pod-checkpointer/outputs.tf (100%) rename {ignitions => modules/ignitions}/pod-checkpointer/pod-checkpointer-yaml.tf (100%) rename {ignitions => modules/ignitions}/pod-checkpointer/resources/kubernetes/addon/pod-checkpointer.yaml (100%) rename {ignitions => modules/ignitions}/pod-checkpointer/variables.tf (100%) rename {ignitions => modules/ignitions}/tx-off/assets.tf (100%) rename {ignitions => modules/ignitions}/tx-off/outputs.tf (100%) rename {ignitions => modules/ignitions}/tx-off/resources/services/tx-off.service (100%) rename {ignitions => modules/ignitions}/update-ca-certificates/assets.tf (100%) rename {ignitions => modules/ignitions}/update-ca-certificates/outputs.tf (100%) rename {ignitions => modules/ignitions}/update-ca-certificates/resources/dropins/10-always-update-ca-certificates.conf (100%) rename {ignitions => modules/ignitions}/update-ca-certificates/variables.tf (100%) rename {tls => modules/tls}/certificate-authority/ca.tf (100%) rename {tls => modules/tls}/certificate-authority/main.tf (100%) rename {tls => modules/tls}/certificate-authority/outputs.tf (100%) rename {tls => modules/tls}/certificate-authority/variables.tf (100%) rename {tls => modules/tls}/certificate/cert.tf (100%) rename {tls => modules/tls}/certificate/main.tf (100%) rename {tls => modules/tls}/certificate/outputs.tf (100%) rename {tls => modules/tls}/certificate/variables.tf (100%) create mode 100644 modules/tls/private-key/main.tf create mode 100644 modules/tls/private-key/outputs.tf create mode 100644 modules/tls/private-key/ssh_key.tf create mode 100644 modules/tls/private-key/variables.tf diff --git a/.gitignore b/.gitignore index b92faf39..7c4d4b23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.tfvars *.tfstate* .terraform/ +.terratest/ +vendor/ diff --git a/aws/kube-etcd/ami.tf b/aws/kube-etcd/ami.tf deleted file mode 100644 index 15f0495a..00000000 --- a/aws/kube-etcd/ami.tf +++ /dev/null @@ -1,36 +0,0 @@ -locals { - ami_owner = "595879546273" - arn = "aws" - - container_linux_channel = "stable" - container_linux_version = "latest" -} - -module "container_linux" { - source = "../container_linux" - - release_channel = "${local.container_linux_channel}" - release_version = "${local.container_linux_version}" -} - -data "aws_ami" "coreos_ami" { - filter { - name = "name" - values = ["CoreOS-${local.container_linux_channel}-${module.container_linux.version}-*"] - } - - filter { - name = "architecture" - values = ["x86_64"] - } - - filter { - name = "virtualization-type" - values = ["hvm"] - } - - filter { - name = "owner-id" - values = ["${local.ami_owner}"] - } -} diff --git a/aws/kube-master/master.tf b/aws/kube-master/master.tf deleted file mode 100644 index 5c022200..00000000 --- a/aws/kube-master/master.tf +++ /dev/null @@ -1,76 +0,0 @@ -data "aws_subnet" "subnet" { - id = "${var.subnet_ids[0]}" -} - -locals { - vpc_id = "${data.aws_subnet.subnet.vpc_id}" - - extra_tags_keys = "${keys(var.extra_tags)}" - extra_tags_values = "${values(var.extra_tags)}" -} - -data "null_data_source" "tags" { - count = "${length(keys(var.extra_tags))}" - - inputs = { - key = "${local.extra_tags_keys[count.index]}" - value = "${local.extra_tags_values[count.index]}" - propagate_at_launch = true - } -} - -resource "aws_autoscaling_group" "master" { - name = "${var.name}-master" - desired_capacity = "${var.master_config["instance_count"]}" - max_size = "${var.master_config["instance_count"] * 3}" - min_size = "${var.master_config["instance_count"]}" - launch_configuration = "${aws_launch_configuration.master.id}" - vpc_zone_identifier = ["${var.subnet_ids}"] - load_balancers = ["${aws_elb.master_internal.id}"] - - tags = [ - { - key = "Name" - value = "${var.name}-master" - propagate_at_launch = true - }, - { - key = "kubernetes.io/cluster/${var.name}" - value = "owned" - propagate_at_launch = true - }, - ] - - tags = ["${data.null_data_source.tags.*.outputs}"] -} - -resource "aws_launch_configuration" "master" { - instance_type = "${var.master_config["ec2_type"]}" - image_id = "${data.aws_ami.coreos_ami.image_id}" - name_prefix = "${var.name}-master-" - - security_groups = [ - "${var.security_group_ids}", - "${local.master_sg_id}", - ] - - iam_instance_profile = "${aws_iam_instance_profile.master.id}" - key_name = "${var.ssh_key}" - - user_data = "${data.ignition_config.s3.rendered}" - - lifecycle { - create_before_destroy = true - - # Ignore changes in the AMI which force recreation of the resource. This - # avoids accidental deletion of nodes whenever a new CoreOS Release comes - # out. - ignore_changes = ["image_id"] - } - - root_block_device { - volume_type = "${var.master_config["root_volume_type"]}" - volume_size = "${var.master_config["root_volume_size"]}" - iops = "${var.master_config["root_volume_type"] == "io1" ? var.master_config["root_volume_iops"] : var.master_config["root_volume_type"] == "gp2" ? 0 : min(10000, max(100, 3 * var.master_config["root_volume_size"]))}" - } -} diff --git a/aws/kube-worker-general/variables.tf b/aws/kube-worker-general/variables.tf deleted file mode 100644 index 22952a70..00000000 --- a/aws/kube-worker-general/variables.tf +++ /dev/null @@ -1,136 +0,0 @@ -variable "aws_region" { - type = "string" - default = "us-east-1" - description = "(Optional) The AWS region" -} - -variable "name" { - type = "string" - description = " (Required) Name of the cluster." -} - -variable "role_name" { - type = "string" - default = "" - description = "(Optional) The Amazon Resource Name of the IAM role that provides permissions for the Kubernetes control plane to make calls to AWS API operations on your behalf." -} - -variable "security_group_ids" { - type = "list" - default = [] - - description = <=:"). -EOF -} - -variable "s3_bucket" { - type = "string" - default = "" - - description = < Date: Wed, 27 Mar 2019 14:11:07 +0800 Subject: [PATCH 2/5] add test for elastikube cluster by terratest --- test/Gopkg.lock | 665 ++++++++++++++++++++++++++++++++ test/Gopkg.toml | 30 ++ test/elastikube_cluster_test.go | 256 ++++++++++++ 3 files changed, 951 insertions(+) create mode 100644 test/Gopkg.lock create mode 100644 test/Gopkg.toml create mode 100644 test/elastikube_cluster_test.go diff --git a/test/Gopkg.lock b/test/Gopkg.lock new file mode 100644 index 00000000..44c6f0fa --- /dev/null +++ b/test/Gopkg.lock @@ -0,0 +1,665 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:4d6f036ea3fe636bcb2e89850bcdc62a771354e157cd51b8b22a2de8562bf663" + name = "cloud.google.com/go" + packages = ["compute/metadata"] + pruneopts = "UT" + revision = "2fa99f4c25c422525316dcb1fd3d5b94e1944cfd" + version = "v0.37.1" + +[[projects]] + digest = "1:1f414f1fb85ab62476b6ecbde51957e3a80f315517839ff50d17d07a6d0af0c7" + name = "github.com/aws/aws-sdk-go" + packages = [ + "aws", + "aws/awserr", + "aws/awsutil", + "aws/client", + "aws/client/metadata", + "aws/corehandlers", + "aws/credentials", + "aws/credentials/ec2rolecreds", + "aws/credentials/endpointcreds", + "aws/credentials/processcreds", + "aws/credentials/stscreds", + "aws/csm", + "aws/defaults", + "aws/ec2metadata", + "aws/endpoints", + "aws/request", + "aws/session", + "aws/signer/v4", + "internal/ini", + "internal/s3err", + "internal/sdkio", + "internal/sdkrand", + "internal/sdkuri", + "internal/shareddefaults", + "private/protocol", + "private/protocol/ec2query", + "private/protocol/eventstream", + "private/protocol/eventstream/eventstreamapi", + "private/protocol/json/jsonutil", + "private/protocol/jsonrpc", + "private/protocol/query", + "private/protocol/query/queryutil", + "private/protocol/rest", + "private/protocol/restxml", + "private/protocol/xml/xmlutil", + "service/acm", + "service/autoscaling", + "service/cloudwatchlogs", + "service/ec2", + "service/iam", + "service/kms", + "service/rds", + "service/s3", + "service/s3/s3iface", + "service/s3/s3manager", + "service/sns", + "service/sqs", + "service/sts", + ] + pruneopts = "UT" + revision = "f778816ebd8f4a83264c207c77e6bcd0a5a76603" + version = "v1.19.1" + +[[projects]] + digest = "1:7b94d37d65c0445053c6f3e73090e3966c1c29127035492c349e14f25c440359" + name = "github.com/boombuler/barcode" + packages = [ + ".", + "qr", + "utils", + ] + pruneopts = "UT" + revision = "3cfea5ab600ae37946be2b763b8ec2c1cf2d272d" + version = "v1.0.0" + +[[projects]] + digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "UT" + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + +[[projects]] + branch = "master" + digest = "1:ecdc8e0fe3bc7d549af1c9c36acf3820523b707d6c071b6d0c3860882c6f7b42" + name = "github.com/docker/spdystream" + packages = [ + ".", + "spdy", + ] + pruneopts = "UT" + revision = "6480d4af844c189cf5dd913db24ddd339d3a4f85" + +[[projects]] + digest = "1:2cd7915ab26ede7d95b8749e6b1f933f1c6d5398030684e6505940a10f31cfda" + name = "github.com/ghodss/yaml" + packages = ["."] + pruneopts = "UT" + revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:d0557c61d3acd22f04f7b6b675b847381034b229b7dce10b1d31bfa0d7f30017" + name = "github.com/go-errors/errors" + packages = ["."] + pruneopts = "UT" + revision = "d98b870cc4e05f1545532a80e9909be8216095b6" + +[[projects]] + digest = "1:ec6f9bf5e274c833c911923c9193867f3f18788c461f76f05f62bb1510e0ae65" + name = "github.com/go-sql-driver/mysql" + packages = ["."] + pruneopts = "UT" + revision = "72cd26f257d44c1114970e19afddcd812016007e" + version = "v1.4.1" + +[[projects]] + digest = "1:4d02824a56d268f74a6b6fdd944b20b58a77c3d70e81008b3ee0c4f1a6777340" + name = "github.com/gogo/protobuf" + packages = [ + "proto", + "sortkeys", + ] + pruneopts = "UT" + revision = "ba06b47c162d49f2af050fb4c75bcbc86a159d5c" + version = "v1.2.1" + +[[projects]] + branch = "master" + digest = "1:1ba1d79f2810270045c328ae5d674321db34e3aae468eb4233883b473c5c0467" + name = "github.com/golang/glog" + packages = ["."] + pruneopts = "UT" + revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" + +[[projects]] + digest = "1:239c4c7fd2159585454003d9be7207167970194216193a8a210b8d29576f19c9" + name = "github.com/golang/protobuf" + packages = [ + "proto", + "ptypes", + "ptypes/any", + "ptypes/duration", + "ptypes/timestamp", + ] + pruneopts = "UT" + revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30" + version = "v1.3.1" + +[[projects]] + digest = "1:0bfbe13936953a98ae3cfe8ed6670d396ad81edf069a806d2f6515d7bb6950df" + name = "github.com/google/btree" + packages = ["."] + pruneopts = "UT" + revision = "4030bb1f1f0c35b30ca7009e9ebd06849dd45306" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:3ee90c0d94da31b442dde97c99635aaafec68d0b8a3c12ee2075c6bdabeec6bb" + name = "github.com/google/gofuzz" + packages = ["."] + pruneopts = "UT" + revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" + +[[projects]] + digest = "1:8f8811f9be822914c3a25c6a071e93beb4c805d7b026cbf298bc577bc1cc945b" + name = "github.com/google/uuid" + packages = ["."] + pruneopts = "UT" + revision = "064e2069ce9c359c118179501254f67d7d37ba24" + version = "0.2" + +[[projects]] + digest = "1:65c4414eeb350c47b8de71110150d0ea8a281835b1f386eacaa3ad7325929c21" + name = "github.com/googleapis/gnostic" + packages = [ + "OpenAPIv2", + "compiler", + "extensions", + ] + pruneopts = "UT" + revision = "7c663266750e7d82587642f65e60bc4083f1f84e" + version = "v0.2.0" + +[[projects]] + branch = "master" + digest = "1:b4395b2a4566c24459af3d04009b39cc21762fc77ec7bf7a1aa905c91e8f018d" + name = "github.com/gregjones/httpcache" + packages = [ + ".", + "diskcache", + ] + pruneopts = "UT" + revision = "3befbb6ad0cc97d4c25d851e9528915809e1a22f" + +[[projects]] + digest = "1:b17934d012a71aa0367870f2a0d0a7b117cb823768295b0e9e1b6e39fab6ebbd" + name = "github.com/gruntwork-io/gruntwork-cli" + packages = ["errors"] + pruneopts = "UT" + revision = "6a2163138f3d10377f313428e7e367b0a6c0c1c9" + version = "v0.4.2" + +[[projects]] + digest = "1:cd16a97919f1064364853ba3955ccf758b99675525db918be06bde9b40e1d3b4" + name = "github.com/gruntwork-io/terratest" + packages = [ + "modules/aws", + "modules/collections", + "modules/customerrors", + "modules/environment", + "modules/files", + "modules/http-helper", + "modules/k8s", + "modules/logger", + "modules/packer", + "modules/random", + "modules/retry", + "modules/shell", + "modules/ssh", + "modules/terraform", + "modules/test-structure", + ] + pruneopts = "UT" + revision = "14a766db13787cf19cab4703d9415481930854b1" + version = "v0.14.2" + +[[projects]] + digest = "1:a0cefd27d12712af4b5018dc7046f245e1e3b5760e2e848c30b171b570708f9b" + name = "github.com/imdario/mergo" + packages = ["."] + pruneopts = "UT" + revision = "7c29201646fa3de8506f701213473dd407f19646" + version = "v0.3.7" + +[[projects]] + digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + pruneopts = "UT" + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" + +[[projects]] + digest = "1:bb81097a5b62634f3e9fec1014657855610c82d19b9a40c17612e32651e35dca" + name = "github.com/jmespath/go-jmespath" + packages = ["."] + pruneopts = "UT" + revision = "c2b33e84" + +[[projects]] + digest = "1:f5a2051c55d05548d2d4fd23d244027b59fbd943217df8aa3b5e170ac2fd6e1b" + name = "github.com/json-iterator/go" + packages = ["."] + pruneopts = "UT" + revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29" + version = "v1.1.6" + +[[projects]] + digest = "1:5d231480e1c64a726869bc4142d270184c419749d34f167646baa21008eb0a79" + name = "github.com/mitchellh/go-homedir" + packages = ["."] + pruneopts = "UT" + revision = "af06845cf3004701891bf4fdb884bfe4920b3727" + version = "v1.1.0" + +[[projects]] + digest = "1:33422d238f147d247752996a26574ac48dcf472976eda7f5134015f06bf16563" + name = "github.com/modern-go/concurrent" + packages = ["."] + pruneopts = "UT" + revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" + version = "1.0.3" + +[[projects]] + digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855" + name = "github.com/modern-go/reflect2" + packages = ["."] + pruneopts = "UT" + revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" + version = "1.0.1" + +[[projects]] + branch = "master" + digest = "1:3bf17a6e6eaa6ad24152148a631d18662f7212e21637c2699bff3369b7f00fa2" + name = "github.com/petar/GoLLRB" + packages = ["llrb"] + pruneopts = "UT" + revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" + +[[projects]] + digest = "1:0e7775ebbcf00d8dd28ac663614af924411c868dca3d5aa762af0fae3808d852" + name = "github.com/peterbourgon/diskv" + packages = ["."] + pruneopts = "UT" + revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" + version = "v2.0.1" + +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + digest = "1:dc56e7178a82f8e84960ed9efa7d4ebd0a6d7864894bfc46f8a35ee5eae7153a" + name = "github.com/pquerna/otp" + packages = [ + ".", + "hotp", + "totp", + ] + pruneopts = "UT" + revision = "be78767b3e392ce45ea73444451022a6fc32ad0d" + version = "v1.1.0" + +[[projects]] + digest = "1:645cabccbb4fa8aab25a956cbcbdf6a6845ca736b2c64e197ca7cbb9d210b939" + name = "github.com/spf13/cobra" + packages = ["."] + pruneopts = "UT" + revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" + version = "v0.0.3" + +[[projects]] + digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2" + name = "github.com/spf13/pflag" + packages = ["."] + pruneopts = "UT" + revision = "298182f68c66c05229eb03ac171abe6e309ee79a" + version = "v1.0.3" + +[[projects]] + digest = "1:5da8ce674952566deae4dbc23d07c85caafc6cfa815b0b3e03e41979cedb8750" + name = "github.com/stretchr/testify" + packages = [ + "assert", + "require", + ] + pruneopts = "UT" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + +[[projects]] + digest = "1:b24d38b282bacf9791408a080f606370efa3d364e4b5fd9ba0f7b87786d3b679" + name = "github.com/urfave/cli" + packages = ["."] + pruneopts = "UT" + revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" + version = "v1.20.0" + +[[projects]] + branch = "master" + digest = "1:4366613f4f14249bd7d1cf56e5c3be9a99e4dd69d8b873655bbd3af0740f674f" + name = "golang.org/x/crypto" + packages = [ + "curve25519", + "ed25519", + "ed25519/internal/edwards25519", + "internal/chacha20", + "internal/subtle", + "poly1305", + "ssh", + "ssh/agent", + "ssh/terminal", + ] + pruneopts = "UT" + revision = "b7391e95e576cacdcdd422573063bc057239113d" + +[[projects]] + branch = "master" + digest = "1:1607f934bc1fe218372d78f9e0bda5a5e656fafe8d4bb3ef075a31c2dab5d9b8" + name = "golang.org/x/net" + packages = [ + "context", + "context/ctxhttp", + "http/httpguts", + "http2", + "http2/hpack", + "idna", + ] + pruneopts = "UT" + revision = "addf6b3196f61cd44ce5a76657913698c73479d0" + +[[projects]] + branch = "master" + digest = "1:399cbecda4e8ab20451d68a1db3812c99791ed95c53c6e9d64f3594a7e608f51" + name = "golang.org/x/oauth2" + packages = [ + ".", + "google", + "internal", + "jws", + "jwt", + ] + pruneopts = "UT" + revision = "c85d3e98c914e3a33234ad863dcbff5dbc425bb8" + +[[projects]] + branch = "master" + digest = "1:78ed3d0c6d5b4996ef2867e280f39ea7b44438558c6331721740ab9061db532c" + name = "golang.org/x/sys" + packages = [ + "cpu", + "unix", + "windows", + ] + pruneopts = "UT" + revision = "f49334f85ddcf0f08d7fb6dd7363e9e6d6b777eb" + +[[projects]] + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" + name = "golang.org/x/text" + packages = [ + "collate", + "collate/build", + "internal/colltab", + "internal/gen", + "internal/tag", + "internal/triegen", + "internal/ucd", + "language", + "secure/bidirule", + "transform", + "unicode/bidi", + "unicode/cldr", + "unicode/norm", + "unicode/rangetable", + ] + pruneopts = "UT" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + branch = "master" + digest = "1:9fdc2b55e8e0fafe4b41884091e51e77344f7dc511c5acedcfd98200003bff90" + name = "golang.org/x/time" + packages = ["rate"] + pruneopts = "UT" + revision = "9d24e82272b4f38b78bc8cff74fa936d31ccd8ef" + +[[projects]] + digest = "1:b08971e2f39ffd6a0b627e7ef1918f178bfcf1ca00d70fc35fb8f4812682afb6" + name = "google.golang.org/appengine" + packages = [ + ".", + "cloudsql", + "internal", + "internal/app_identity", + "internal/base", + "internal/datastore", + "internal/log", + "internal/modules", + "internal/remote_api", + "internal/urlfetch", + "urlfetch", + ] + pruneopts = "UT" + revision = "54a98f90d1c46b7731eb8fb305d2a321c30ef610" + version = "v1.5.0" + +[[projects]] + digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" + name = "gopkg.in/inf.v0" + packages = ["."] + pruneopts = "UT" + revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" + version = "v0.9.1" + +[[projects]] + digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "UT" + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" + +[[projects]] + branch = "release-1.12" + digest = "1:faf52d216e0d651ee48a5ee8fb43f818a6c36bf4246282a5e30b8985da5581ff" + name = "k8s.io/api" + packages = [ + "admissionregistration/v1alpha1", + "admissionregistration/v1beta1", + "apps/v1", + "apps/v1beta1", + "apps/v1beta2", + "authentication/v1", + "authentication/v1beta1", + "authorization/v1", + "authorization/v1beta1", + "autoscaling/v1", + "autoscaling/v2beta1", + "autoscaling/v2beta2", + "batch/v1", + "batch/v1beta1", + "batch/v2alpha1", + "certificates/v1beta1", + "coordination/v1beta1", + "core/v1", + "events/v1beta1", + "extensions/v1beta1", + "networking/v1", + "policy/v1beta1", + "rbac/v1", + "rbac/v1alpha1", + "rbac/v1beta1", + "scheduling/v1alpha1", + "scheduling/v1beta1", + "settings/v1alpha1", + "storage/v1", + "storage/v1alpha1", + "storage/v1beta1", + ] + pruneopts = "UT" + revision = "6db15a15d2d3874a6c3ddb2140ac9f3bc7058428" + +[[projects]] + branch = "release-1.12" + digest = "1:efacf240bb0225324e22fc0c20da3fc166b8d42778f667e1e32835556aa146df" + name = "k8s.io/apimachinery" + packages = [ + "pkg/api/errors", + "pkg/api/meta", + "pkg/api/resource", + "pkg/apis/meta/v1", + "pkg/apis/meta/v1/unstructured", + "pkg/apis/meta/v1beta1", + "pkg/conversion", + "pkg/conversion/queryparams", + "pkg/fields", + "pkg/labels", + "pkg/runtime", + "pkg/runtime/schema", + "pkg/runtime/serializer", + "pkg/runtime/serializer/json", + "pkg/runtime/serializer/protobuf", + "pkg/runtime/serializer/recognizer", + "pkg/runtime/serializer/streaming", + "pkg/runtime/serializer/versioning", + "pkg/selection", + "pkg/types", + "pkg/util/clock", + "pkg/util/errors", + "pkg/util/framer", + "pkg/util/httpstream", + "pkg/util/httpstream/spdy", + "pkg/util/intstr", + "pkg/util/json", + "pkg/util/naming", + "pkg/util/net", + "pkg/util/runtime", + "pkg/util/sets", + "pkg/util/validation", + "pkg/util/validation/field", + "pkg/util/yaml", + "pkg/version", + "pkg/watch", + "third_party/forked/golang/netutil", + "third_party/forked/golang/reflect", + ] + pruneopts = "UT" + revision = "01f179d85dbce0f2e0e4351a92394b38694b7cae" + +[[projects]] + branch = "release-9.0" + digest = "1:a92af87ab3cdd5289ba3b0b44c3e62051ba532ebb5b4ee3f6da7adf9e1a64169" + name = "k8s.io/client-go" + packages = [ + "discovery", + "kubernetes", + "kubernetes/scheme", + "kubernetes/typed/admissionregistration/v1alpha1", + "kubernetes/typed/admissionregistration/v1beta1", + "kubernetes/typed/apps/v1", + "kubernetes/typed/apps/v1beta1", + "kubernetes/typed/apps/v1beta2", + "kubernetes/typed/authentication/v1", + "kubernetes/typed/authentication/v1beta1", + "kubernetes/typed/authorization/v1", + "kubernetes/typed/authorization/v1beta1", + "kubernetes/typed/autoscaling/v1", + "kubernetes/typed/autoscaling/v2beta1", + "kubernetes/typed/autoscaling/v2beta2", + "kubernetes/typed/batch/v1", + "kubernetes/typed/batch/v1beta1", + "kubernetes/typed/batch/v2alpha1", + "kubernetes/typed/certificates/v1beta1", + "kubernetes/typed/coordination/v1beta1", + "kubernetes/typed/core/v1", + "kubernetes/typed/events/v1beta1", + "kubernetes/typed/extensions/v1beta1", + "kubernetes/typed/networking/v1", + "kubernetes/typed/policy/v1beta1", + "kubernetes/typed/rbac/v1", + "kubernetes/typed/rbac/v1alpha1", + "kubernetes/typed/rbac/v1beta1", + "kubernetes/typed/scheduling/v1alpha1", + "kubernetes/typed/scheduling/v1beta1", + "kubernetes/typed/settings/v1alpha1", + "kubernetes/typed/storage/v1", + "kubernetes/typed/storage/v1alpha1", + "kubernetes/typed/storage/v1beta1", + "pkg/apis/clientauthentication", + "pkg/apis/clientauthentication/v1alpha1", + "pkg/apis/clientauthentication/v1beta1", + "pkg/version", + "plugin/pkg/client/auth/exec", + "plugin/pkg/client/auth/gcp", + "rest", + "rest/watch", + "third_party/forked/golang/template", + "tools/auth", + "tools/clientcmd", + "tools/clientcmd/api", + "tools/clientcmd/api/latest", + "tools/clientcmd/api/v1", + "tools/metrics", + "tools/portforward", + "tools/reference", + "transport", + "transport/spdy", + "util/cert", + "util/connrotation", + "util/flowcontrol", + "util/homedir", + "util/integer", + "util/jsonpath", + ] + pruneopts = "UT" + revision = "77e032213d34c856222b4d4647c1c175ba8d22b9" + +[[projects]] + digest = "1:51314886250b22f73377febaadd972084684122e2e1d3004f388dff60754ba05" + name = "k8s.io/kubernetes" + packages = ["pkg/kubectl/generate"] + pruneopts = "UT" + revision = "c27b913fddd1a6c480c229191a087698aa92f0b1" + version = "v1.13.4" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/gruntwork-io/terratest/modules/aws", + "github.com/gruntwork-io/terratest/modules/http-helper", + "github.com/gruntwork-io/terratest/modules/k8s", + "github.com/gruntwork-io/terratest/modules/random", + "github.com/gruntwork-io/terratest/modules/retry", + "github.com/gruntwork-io/terratest/modules/ssh", + "github.com/gruntwork-io/terratest/modules/terraform", + "github.com/gruntwork-io/terratest/modules/test-structure", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/test/Gopkg.toml b/test/Gopkg.toml new file mode 100644 index 00000000..d7072c22 --- /dev/null +++ b/test/Gopkg.toml @@ -0,0 +1,30 @@ +# Gopkg.toml example +# +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[prune] + go-tests = true + unused-packages = true diff --git a/test/elastikube_cluster_test.go b/test/elastikube_cluster_test.go new file mode 100644 index 00000000..fe130c33 --- /dev/null +++ b/test/elastikube_cluster_test.go @@ -0,0 +1,256 @@ +package test + +import ( + "fmt" + "os" + "strings" + "testing" + "time" + + "github.com/gruntwork-io/terratest/modules/aws" + http_helper "github.com/gruntwork-io/terratest/modules/http-helper" + "github.com/gruntwork-io/terratest/modules/k8s" + "github.com/gruntwork-io/terratest/modules/random" + "github.com/gruntwork-io/terratest/modules/retry" + "github.com/gruntwork-io/terratest/modules/ssh" + "github.com/gruntwork-io/terratest/modules/terraform" + test_structure "github.com/gruntwork-io/terratest/modules/test-structure" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestElastikubeCluster(t *testing.T) { + + t.Parallel() + + exampleFolder := test_structure.CopyTerraformFolderToTemp(t, "../", "examples/elastikube-cluster") + + // A unique ID we can use to namespace resources so we don't clash with anything already in the AWS account or + // tests running in parallel + // uniqueID := "rn2ws0" + uniqueID := strings.ToLower(random.UniqueId()) + awsRegion := "us-west-2" + + // Preapre all terraform options + terraformOptionsNetwork := configureTerraformOptions(t, exampleFolder, "module.network", uniqueID, awsRegion) + terraformOptionsKubernetes := configureTerraformOptions(t, exampleFolder, "module.kubernetes", uniqueID, awsRegion) + terraformOptionsWorkerSpot := configureTerraformOptions(t, exampleFolder, "module.worker_spot", uniqueID, awsRegion) + terraformOptionsWorkerOnDemand := configureTerraformOptions(t, exampleFolder, "module.worker_on_demand", uniqueID, awsRegion) + terraformOptionsAll := configureTerraformOptions(t, exampleFolder, "", uniqueID, awsRegion) + test_structure.SaveTerraformOptions(t, exampleFolder, terraformOptionsAll) + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer test_structure.RunTestStage(t, "teardown", func() { + terraform.Destroy(t, terraformOptionsWorkerOnDemand) + terraform.Destroy(t, terraformOptionsWorkerSpot) + terraform.Destroy(t, terraformOptionsKubernetes) + terraform.Destroy(t, terraformOptionsNetwork) + + keyPair := test_structure.LoadEc2KeyPair(t, exampleFolder) + aws.DeleteEC2KeyPair(t, keyPair) + test_structure.CleanupTestData(t, exampleFolder) + }) + + // Deploy the example + test_structure.RunTestStage(t, "setup", func() { + + // Create an EC2 KeyPair that we can use for SSH access + //keyPair := test_structure.LoadEc2KeyPair(t, exampleFolder) + keyPairName := fmt.Sprintf("test-k8s-%s", uniqueID) + keyPair := aws.CreateAndImportEC2KeyPair(t, awsRegion, keyPairName) + test_structure.SaveEc2KeyPair(t, exampleFolder, keyPair) + + // Create network module first + terraform.InitAndApply(t, terraformOptionsNetwork) + + // Create kubernetes master compoment + terraform.InitAndApply(t, terraformOptionsKubernetes) + + // Create kubernetes worker (both on_demand and spot) + terraform.InitAndApply(t, terraformOptionsAll) + + // Prepare kubectl options + ignitionS3Bucket := terraform.Output(t, terraformOptionsAll, "ignition_s3_bucket") + kubeconfig := aws.GetS3ObjectContents(t, awsRegion, ignitionS3Bucket, "kubeconfig") + kubeconfigPath, _ := createKubeconfig(t, exampleFolder, kubeconfig) + kubeconfigContext := "default" + kubectlOptions := k8s.NewKubectlOptions(kubeconfigContext, kubeconfigPath) + test_structure.SaveKubectlOptions(t, exampleFolder, kubectlOptions) + }) + + test_structure.RunTestStage(t, "validate", func() { + keyPair := test_structure.LoadEc2KeyPair(t, exampleFolder) + terraformOptions := test_structure.LoadTerraformOptions(t, exampleFolder) + kubectlOptions := test_structure.LoadKubectlOptions(t, exampleFolder) + + testBastionHost(t, terraformOptions, keyPair) + testKubernetes(t, kubectlOptions, exampleFolder) + }) +} + +func configureTerraformOptions(t *testing.T, exampleFolder string, target string, uniqueID string, awsRegion string) (ret *terraform.Options) { + + phase := "test" + project := fmt.Sprintf("k8s-%s", uniqueID) + keyPairName := fmt.Sprintf("test-k8s-%s", uniqueID) + + ret = &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: exampleFolder, + + // Variables to pass to our Terraform code using -var options + Vars: map[string]interface{}{ + "aws_region": awsRegion, + "phase": phase, + "project": project, + "key_pair_name": keyPairName, + "endpoint_public_access": "true", + }, + } + + if target != "" { + ret.Targets = []string{target} + } + + return +} + +func createKubeconfig(t *testing.T, source string, kubeconfig string) (string, error) { + kubeconfigPath := fmt.Sprintf("%s/.test-data/kubeconfig", source) + + f, err := os.Create(kubeconfigPath) + if err != nil { + return "", err + } + l, err := f.WriteString(kubeconfig) + if err != nil { + f.Close() + return "", err + } + fmt.Println(l, "bytes written successfully") + err = f.Close() + if err != nil { + return "", err + } + + return kubeconfigPath, nil +} + +func testBastionHost(t *testing.T, terraformOptions *terraform.Options, keyPair *aws.Ec2Keypair) { + + bastionPublicIP := terraform.Output(t, terraformOptions, "bastion_public_ip") + + // start the ssh agent + sshAgent := ssh.SshAgentWithKeyPair(t, keyPair.KeyPair) + defer sshAgent.Stop() + + // We're going to try to SSH to the instance IP, using the Key Pair we created earlier. Instead of + // directly using the SSH key in the SSH connection, we're going to rely on an existing SSH agent that we + // programatically emulate within this test. We're going to use the user "ubuntu" as we know the Instance + // is running an Ubuntu AMI that has such a user + bastionHost := &ssh.Host{ + Hostname: bastionPublicIP, + SshUserName: "ubuntu", + OverrideSshAgent: sshAgent, + } + + // It can take a minute or so for the Instance to boot up, so retry a few times + maxRetries := 30 + timeBetweenRetries := 5 * time.Second + description := fmt.Sprintf("SSH with Agent to bastion host %s", bastionPublicIP) + + // Run a simple echo command on the server + expectedText := "Hello, World" + command := fmt.Sprintf("echo -n '%s'", expectedText) + + // Verify that we can SSH to the Instance and run commands + retry.DoWithRetry(t, description, maxRetries, timeBetweenRetries, func() (string, error) { + + actualText, err := ssh.CheckSshCommandE(t, *bastionHost, command) + + if err != nil { + return "", err + } + + if strings.TrimSpace(actualText) != expectedText { + return "", fmt.Errorf("Expected SSH command to return '%s' but got '%s'", expectedText, actualText) + } + + return "", nil + }) +} + +func testKubernetes(t *testing.T, kubectlOptions *k8s.KubectlOptions, exampleFolder string) { + + // It can take several minutes for the Kubernetes cluster to boot up, so retry a few times + maxRetries := 30 + timeBetweenRetries := 30 * time.Second + description := fmt.Sprint("Access Kubernetes cluster") + + // Verify that we can access Kubernetes cluster by kubectl + retry.DoWithRetry(t, description, maxRetries, timeBetweenRetries, func() (string, error) { + + nodesReady, err := k8s.AreAllNodesReadyE(t, kubectlOptions) + + if err != nil { + return "", err + } + + if !nodesReady { + return "", fmt.Errorf("Cannot check all the Kubernetes nodes ready or not: %s", err) + } + return "", nil + }) + + // Path to the Kubernetes resource config we will test + + kubeResourcePath := fmt.Sprintf("%s/k8s/nginx.yml", exampleFolder) + + // To ensure we can reuse the resource config on the same cluster to test different scenarios, we setup a unique + // namespace for the resources for this test. + // Note that namespaces must be lowercase. + namespaceName := strings.ToLower(random.UniqueId()) + testResourceName := "nginx" + testServiceName := fmt.Sprintf("%s-service", testResourceName) + testServiceLocal := random.Random(9000, 9999) + testServiceRemote := 80 + + k8s.CreateNamespace(t, kubectlOptions, namespaceName) + // Make sure we set the namespace on the options + kubectlOptions.Namespace = namespaceName + // ... and make sure to delete the namespace at the end of the test + defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName) + + // This will run `kubectl apply -f RESOURCE_CONFIG` and fail the test if there are any errors + k8s.KubectlApply(t, kubectlOptions, kubeResourcePath) + + // This will wait up to 10 seconds for the service to become available, to ensure that we can access it. + k8s.WaitUntilServiceAvailable(t, kubectlOptions, testServiceName, 10, 1*time.Second) + + // Get pod and wait for it to be avaialable + // To get the pod, we need to filter it using the labels that the helm chart creates + filters := metav1.ListOptions{ + LabelSelector: fmt.Sprintf("app=%s", testResourceName), + } + k8s.WaitUntilNumPodsCreated(t, kubectlOptions, filters, 1, 30, 10*time.Second) + pods := k8s.ListPods(t, kubectlOptions, filters) + for _, pod := range pods { + k8s.WaitUntilPodAvailable(t, kubectlOptions, pod.Name, 30, 10*time.Second) + } + + // Now we verify that the service will successfully boot and start serving requests + kubeTunnel := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypeService, testServiceName, testServiceLocal, testServiceRemote) + kubeTunnel.ForwardPort(t) + defer kubeTunnel.Close() + + // Test the endpoint for up to 5 minutes. This will only fail if we timeout waiting for the service to return a 200 + // response. + http_helper.HttpGetWithRetryWithCustomValidation( + t, + fmt.Sprintf("http://%s", kubeTunnel.Endpoint()), + 30, + 10*time.Second, + func(statusCode int, body string) bool { + return statusCode == 200 + }, + ) +} From b1a305604ff71be71623ef2e033ae4ea7079f911 Mon Sep 17 00:00:00 2001 From: smalltown Date: Wed, 27 Mar 2019 18:31:02 +0800 Subject: [PATCH 3/5] fix test bug, add document --- examples/elastikube-cluster/README.md | 76 ++++++++++++++++++++++++ examples/elastikube-cluster/variables.tf | 2 +- test/elastikube_cluster_test.go | 3 +- 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 examples/elastikube-cluster/README.md diff --git a/examples/elastikube-cluster/README.md b/examples/elastikube-cluster/README.md new file mode 100644 index 00000000..2281357c --- /dev/null +++ b/examples/elastikube-cluster/README.md @@ -0,0 +1,76 @@ +# Elastikube Cluster Example + +This folder contains a simple Terraform module that deploys resources in [AWS](https://aws.amazon.com/) to demonstrate +how you can use Terratest to write automated tests for your AWS Terraform code. This module deploys AWS VPC with bastion hot, self-hosted Kubernetes with two worker group (spot and on demand instance) [EC2 +Instances](https://aws.amazon.com/ec2/) in the AWS region specified in +the `aws_region` variable. + +Check out [test/elastikube_cluster_test.go](/test/elastikube_cluster_test.go) to see how you can write +automated tests for this module. + +**WARNING**: This module and the automated tests for it deploy real resources into your AWS account which can cost you +money. + + + + + +## Running this module manually + +1. Sign up for [AWS](https://aws.amazon.com/). +2. Configure your AWS credentials using one of the [supported methods for AWS CLI + tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the + `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True". +3. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. + +4. Execute below command to setup + ``` + # initial for sync terraform module and install provider plugins + + ~$ terraform init + + # create the network infrastructure + + ~$ terraform apply -target=module.network + + # create the kubernetes master compoment + + ~$ terraform apply -target=module.kubernetes + + # create the general and spot k8s worker group + ~$ terraform apply + ``` + +5. When you're done, execute below command to destroy + + ``` + $ terraform destroy -target=module.worker_spot + $ terraform destroy -target=module.worker_general + $ terraform destroy -target=module.kubernetes + $ terraform destroy -target=module.network + ``` + + + + +## Running automated tests against this module + +0. Perform the testing in the AWS EC2, instead of desktop, due to this module create many AWS resource, it takes time to destroy. Executing in the AWS EC2 decrease the risk to fail to teardown +1. Sign up for [AWS](https://aws.amazon.com/). +2. Configure your AWS credentials using one of the [supported methods for AWS CLI + tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the + `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. If you're using the `~/.aws/config` file for profiles then export `AWS_SDK_LOAD_CONFIG` as "True". +3. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. +4. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. +5. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) and make sure it's on your `PATH`. +6. `cd test` +7. `dep ensure` +8. `go test -timeout 60m -v -run TestElastikubeCluster` +9. if execution without error, the output like below + ``` + ... + agent.go:114: Generating SSH Agent with given KeyPair(s) + agent.go:68: could not serve ssh agent read unix /tmp/ssh-agent-589722746/ssh_auth.sock->@: use of closed network connection + PASS + ok github.com/vishwakarma/test 1223.186s + ``` \ No newline at end of file diff --git a/examples/elastikube-cluster/variables.tf b/examples/elastikube-cluster/variables.tf index dd17893a..20a568c1 100644 --- a/examples/elastikube-cluster/variables.tf +++ b/examples/elastikube-cluster/variables.tf @@ -1,6 +1,6 @@ variable "aws_region" { type = "string" - default = "us-east-1" + default = "us-west-2" description = "(Optional) The AWS region" } diff --git a/test/elastikube_cluster_test.go b/test/elastikube_cluster_test.go index fe130c33..d9e5393f 100644 --- a/test/elastikube_cluster_test.go +++ b/test/elastikube_cluster_test.go @@ -47,7 +47,8 @@ func TestElastikubeCluster(t *testing.T) { keyPair := test_structure.LoadEc2KeyPair(t, exampleFolder) aws.DeleteEC2KeyPair(t, keyPair) - test_structure.CleanupTestData(t, exampleFolder) + testData := fmt.Sprintf("%s/.test-data", exampleFolder) + os.Remove(testData) }) // Deploy the example From f9c1a998b94914554a69760b2b90932e769acf00 Mon Sep 17 00:00:00 2001 From: smalltown Date: Thu, 28 Mar 2019 11:45:38 +0800 Subject: [PATCH 4/5] fix from code review --- test/elastikube_cluster_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/elastikube_cluster_test.go b/test/elastikube_cluster_test.go index d9e5393f..56d8b6a1 100644 --- a/test/elastikube_cluster_test.go +++ b/test/elastikube_cluster_test.go @@ -18,6 +18,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +const ( + MaxRetries = 30 + TimeBetweenRetries = 5 * time.Second +) + func TestElastikubeCluster(t *testing.T) { t.Parallel() @@ -155,8 +160,6 @@ func testBastionHost(t *testing.T, terraformOptions *terraform.Options, keyPair } // It can take a minute or so for the Instance to boot up, so retry a few times - maxRetries := 30 - timeBetweenRetries := 5 * time.Second description := fmt.Sprintf("SSH with Agent to bastion host %s", bastionPublicIP) // Run a simple echo command on the server @@ -183,8 +186,6 @@ func testBastionHost(t *testing.T, terraformOptions *terraform.Options, keyPair func testKubernetes(t *testing.T, kubectlOptions *k8s.KubectlOptions, exampleFolder string) { // It can take several minutes for the Kubernetes cluster to boot up, so retry a few times - maxRetries := 30 - timeBetweenRetries := 30 * time.Second description := fmt.Sprint("Access Kubernetes cluster") // Verify that we can access Kubernetes cluster by kubectl @@ -248,8 +249,8 @@ func testKubernetes(t *testing.T, kubectlOptions *k8s.KubectlOptions, exampleFol http_helper.HttpGetWithRetryWithCustomValidation( t, fmt.Sprintf("http://%s", kubeTunnel.Endpoint()), - 30, - 10*time.Second, + MaxRetries, + TimeBetweenRetries, func(statusCode int, body string) bool { return statusCode == 200 }, From 11e4794e7e777653190b5970889dbb04bdee9f69 Mon Sep 17 00:00:00 2001 From: smalltown Date: Thu, 28 Mar 2019 17:00:30 +0800 Subject: [PATCH 5/5] change for the review --- examples/elastikube-cluster/variables.tf | 2 +- test/elastikube_cluster_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/elastikube-cluster/variables.tf b/examples/elastikube-cluster/variables.tf index 20a568c1..15cc0420 100644 --- a/examples/elastikube-cluster/variables.tf +++ b/examples/elastikube-cluster/variables.tf @@ -29,7 +29,7 @@ variable "project" { variable "phase" { type = "string" - default = "phase" + default = "test" description = "(Optional) phase name, used to compose the resource name" } diff --git a/test/elastikube_cluster_test.go b/test/elastikube_cluster_test.go index 56d8b6a1..c29b26fe 100644 --- a/test/elastikube_cluster_test.go +++ b/test/elastikube_cluster_test.go @@ -129,7 +129,7 @@ func createKubeconfig(t *testing.T, source string, kubeconfig string) (string, e } l, err := f.WriteString(kubeconfig) if err != nil { - f.Close() + defer f.Close() return "", err } fmt.Println(l, "bytes written successfully") @@ -167,7 +167,7 @@ func testBastionHost(t *testing.T, terraformOptions *terraform.Options, keyPair command := fmt.Sprintf("echo -n '%s'", expectedText) // Verify that we can SSH to the Instance and run commands - retry.DoWithRetry(t, description, maxRetries, timeBetweenRetries, func() (string, error) { + retry.DoWithRetry(t, description, MaxRetries, TimeBetweenRetries, func() (string, error) { actualText, err := ssh.CheckSshCommandE(t, *bastionHost, command) @@ -186,10 +186,10 @@ func testBastionHost(t *testing.T, terraformOptions *terraform.Options, keyPair func testKubernetes(t *testing.T, kubectlOptions *k8s.KubectlOptions, exampleFolder string) { // It can take several minutes for the Kubernetes cluster to boot up, so retry a few times - description := fmt.Sprint("Access Kubernetes cluster") + description := "Access Kubernetes cluster" // Verify that we can access Kubernetes cluster by kubectl - retry.DoWithRetry(t, description, maxRetries, timeBetweenRetries, func() (string, error) { + retry.DoWithRetry(t, description, MaxRetries, TimeBetweenRetries, func() (string, error) { nodesReady, err := k8s.AreAllNodesReadyE(t, kubectlOptions)