From 49fa452864746759b46aaa0acba358f4d4f881d4 Mon Sep 17 00:00:00 2001 From: Josh Kneubuhl Date: Tue, 3 May 2022 11:00:16 -0400 Subject: [PATCH] Address review feedback - better prereq checks Signed-off-by: Josh Kneubuhl --- test-network-k8s/README.md | 29 +++++++++++++++-------- test-network-k8s/network | 2 +- test-network-k8s/scripts/fabric_config.sh | 7 ++---- test-network-k8s/scripts/prereqs.sh | 16 +++++++++---- test-network-k8s/scripts/test_network.sh | 13 ++++++++++ 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/test-network-k8s/README.md b/test-network-k8s/README.md index d65e4a28..130985d5 100644 --- a/test-network-k8s/README.md +++ b/test-network-k8s/README.md @@ -17,10 +17,11 @@ _Fabric, Ahoy!_ ## Prerequisites -- [Docker](https://www.docker.com) - [kubectl](https://kubernetes.io/docs/tasks/tools/) -- K8s: [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) or [k3s](https://rancherdesktop.io) +- [Docker](https://www.docker.com) +- K8s: [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) or [Rancher / k3s](https://rancherdesktop.io) - [jq](https://stedolan.github.io/jq/) +- [envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) (`brew install gettext` on OSX) ## Quickstart @@ -29,13 +30,28 @@ Create a KIND Kubernetes: ```shell ./network kind ``` -Or for environments running [Rancher k3s](docs/KUBERNETES.md#rancher-desktop-and-k3s): +For environments running [Rancher k3s](docs/KUBERNETES.md#rancher-desktop-and-k3s): ```shell export TEST_NETWORK_CLUSTER_RUNTIME=k3s ./network cluster-init ``` +Fabric services are exposed by Kubernetes Ingress at the fictitious DNS domain `*.local.fabric`. Add the +following aliases to your /etc/hosts file: +``` +127.0.0.1 org0-ca.local.fabric +127.0.0.1 org1-ca.local.fabric +127.0.0.1 org2-ca.local.fabric +127.0.0.1 org0-orderer1.local.fabric +127.0.0.1 org0-orderer2.local.fabric +127.0.0.1 org0-orderer3.local.fabric +127.0.0.1 org1-peer1.local.fabric +127.0.0.1 org1-peer2.local.fabric +127.0.0.1 org2-peer1.local.fabric +127.0.0.1 org2-peer2.local.fabric +``` + Launch the network, create a channel, and deploy the [basic-asset-transfer](../asset-transfer-basic) smart contract: ```shell ./network up @@ -75,10 +91,3 @@ Tear down the cluster: - [Working with Chaincode](docs/CHAINCODE.md) - [Working with Applications](docs/APPLICATIONS.md) - -## Areas for Improvement / TODOs - -- [ ] Test the recipe with OCP, AWS, gcp, Azure, etc. (These should ONLY differ w.r.t. pvc and ingress) -- [ ] Address any of the 20+ todo: notes in network.sh -- [ ] Implement mutual TLS across peers, orderers, and clients. -- [ ] Caliper? diff --git a/test-network-k8s/network b/test-network-k8s/network index d4db63d3..481a6438 100755 --- a/test-network-k8s/network +++ b/test-network-k8s/network @@ -27,7 +27,7 @@ export FABRIC_PEER_IMAGE=${TEST_NETWORK_FABRIC_PEER_IMAGE:-${FABRIC_CONTAINER_RE export NETWORK_NAME=${TEST_NETWORK_NAME:-test-network} export CLUSTER_NAME=${TEST_NETWORK_KIND_CLUSTER_NAME:-kind} export NS=${TEST_NETWORK_KUBE_NAMESPACE:-${NETWORK_NAME}} -export DOMAIN=${TEST_NETWORK_DOMAIN:-vcap.me} +export DOMAIN=${TEST_NETWORK_DOMAIN:-local.fabric} export CHANNEL_NAME=${TEST_NETWORK_CHANNEL_NAME:-mychannel} export TEMP_DIR=${PWD}/build diff --git a/test-network-k8s/scripts/fabric_config.sh b/test-network-k8s/scripts/fabric_config.sh index ac5e1eb2..5b663c08 100755 --- a/test-network-k8s/scripts/fabric_config.sh +++ b/test-network-k8s/scripts/fabric_config.sh @@ -16,11 +16,8 @@ function init_namespace() { function init_storage_volumes() { push_fn "Provisioning volume storage" - # odd. - # KIND runs the rancher local-path provider, installing as the storageclass 'standard' - # Rancher runs the local-path provider, installing as the storageclass 'local-path' - # - # When installing to KIND, use the 'standard' storage class. + # Both KIND and k3s use the Rancher local-path provider. In KIND, this is installed + # as the 'standard' storage class, and in Rancher as the 'local-path' storage class. if [ "${CLUSTER_RUNTIME}" == "kind" ]; then export STORAGE_CLASS="standard" diff --git a/test-network-k8s/scripts/prereqs.sh b/test-network-k8s/scripts/prereqs.sh index 7fa00262..032179a6 100755 --- a/test-network-k8s/scripts/prereqs.sh +++ b/test-network-k8s/scripts/prereqs.sh @@ -16,10 +16,12 @@ function check_prereqs() { exit 1 fi - kind version > /dev/null - if [[ $? -ne 0 ]]; then - echo "No 'kind' binary available? (https://kind.sigs.k8s.io/docs/user/quick-start/#installation)" - exit 1 + if [ "${CLUSTER_RUNTIME}" == "kind" ]; then + kind version > /dev/null + if [[ $? -ne 0 ]]; then + echo "No 'kind' binary available? (https://kind.sigs.k8s.io/docs/user/quick-start/#installation)" + exit 1 + fi fi kubectl > /dev/null @@ -34,6 +36,12 @@ function check_prereqs() { exit 1 fi + echo | envsubst > /dev/null + if [[ $? -ne 0 ]]; then + echo "No 'envsubst' binary (gettext package) available? (https://www.gnu.org/software/gettext/)" + exit 1 + fi + # Use the local fabric binaries if available. If not, go get them. bin/peer version &> /dev/null if [[ $? -ne 0 ]]; then diff --git a/test-network-k8s/scripts/test_network.sh b/test-network-k8s/scripts/test_network.sh index c8965db8..28fba2eb 100755 --- a/test-network-k8s/scripts/test_network.sh +++ b/test-network-k8s/scripts/test_network.sh @@ -210,8 +210,21 @@ function scrub_org_volumes() { } function network_down() { + + set +e + + kubectl get namespace $NS > /dev/null + if [[ $? -ne 0 ]]; then + echo "No namespace $NS found - nothing to do." + return + fi + + set -e + stop_services scrub_org_volumes + kubectl delete namespace $NS + rm -rf $PWD/build }