diff --git a/doc/user-guides/secure-protect-connect.md b/doc/user-guides/secure-protect-connect.md index 40172cfc2..19372228c 100644 --- a/doc/user-guides/secure-protect-connect.md +++ b/doc/user-guides/secure-protect-connect.md @@ -102,7 +102,7 @@ spec: name: kuadrant-operator-glbc-ca EOF -kubectl wait tlspolicy api-gateway-tls -n kuadrant-system --for=condition=ready +kubectl wait tlspolicy api-gateway-tls -n kuadrant-system --for=condition=accepted ``` Now, if you look at the status of the gateway, you will see the error is gone, and the status of the policy will report the listener as now secured with a TLS certificate and the gateway as affected by the TLS policy. @@ -181,7 +181,7 @@ spec: unit: second EOF -kubectl wait ratelimitpolicy infra-ratelimit -n kuadrant-system --for=condition=available +kubectl wait ratelimitpolicy infra-ratelimit -n kuadrant-system --for=condition=accepted ``` > **Note:** It may take a couple of minutes for the RateLimitPolicy to be applied depending on your cluster. @@ -256,7 +256,7 @@ spec: kind: Gateway EOF -kubectl wait dnspolicy simple-dnspolicy -n kuadrant-system --for=condition=ready +kubectl wait dnspolicy simple-dnspolicy -n kuadrant-system --for=condition=enforced ``` If you want to see the DNSRecord created by the this policy, execute the following command: diff --git a/hack/quickstart-setup.sh b/hack/quickstart-setup.sh index 315d6ebb6..e2a28a3e8 100755 --- a/hack/quickstart-setup.sh +++ b/hack/quickstart-setup.sh @@ -16,6 +16,39 @@ # limitations under the License. # +set -e pipefail + +containerRuntime() { + local container_runtime="" + if command -v docker &>/dev/null; then + container_runtime="docker" + elif command -v podman &>/dev/null; then + container_runtime="podman" + else + echo "Neither Docker nor Podman is installed. Exiting..." + exit 1 + fi + echo "$container_runtime" +} + +dockerBinCmd() { + local network="" + if [ ! -z "${KIND_CLUSTER_DOCKER_NETWORK}" ]; then + network=" --network ${KIND_CLUSTER_DOCKER_NETWORK}" + fi + + echo "$CONTAINER_RUNTIME_BIN run --rm -u $UID -v ${TMP_DIR}:${TMP_DIR}${network} -e KUBECONFIG=${TMP_DIR}/kubeconfig --entrypoint=$1 $TOOLS_IMAGE" +} + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +BOLD='\033[1m' +INFO="${BOLD}${YELLOW}INFO:${NC}" +SUCCESS="${GREEN}✓${NC}" +FAILURE="${RED}✗${NC}" + if [ -z $KUADRANT_ORG ]; then KUADRANT_ORG=${KUADRANT_ORG:="kuadrant"} fi @@ -30,33 +63,25 @@ if [ -z $ISTIO_INSTALL_SAIL ]; then ISTIO_INSTALL_SAIL=${ISTIO_INSTALL_SAIL:=false} fi -echo "Loading quickstart scripts from GitHub" -source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/${KUADRANT_ORG}/multicluster-gateway-controller/${MGC_REF}/hack/.quickstartEnv)" -source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/${KUADRANT_ORG}/multicluster-gateway-controller/${MGC_REF}/hack/.deployUtils)" +export TOOLS_IMAGE=quay.io/kuadrant/mgc-tools:latest +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +export TMP_DIR=$SCRIPT_DIR/tmp/mgc +export CONTAINER_RUNTIME_BIN=$(containerRuntime) +export KIND_BIN=kind +export HELM_BIN=helm +export KUSTOMIZE_BIN=$(dockerBinCmd "kustomize") YQ_BIN=$(dockerBinCmd "yq") KUADRANT_REPO="github.com/${KUADRANT_ORG}/kuadrant-operator.git" -MGC_REPO="github.com/${KUADRANT_ORG}/multicluster-gateway-controller.git" KUADRANT_REPO_RAW="https://raw.githubusercontent.com/${KUADRANT_ORG}/kuadrant-operator/${KUADRANT_REF}" -KUADRANT_DEPLOY_KUSTOMIZATION="${KUADRANT_REPO}/config/deploy" -KUADRANT_GATEWAY_API_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/gateway-api" -KUADRANT_ISTIO_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/istio/sail" -MGC_ISTIO_KUSTOMIZATION="${MGC_REPO}/config/istio" -KUADRANT_CERT_MANAGER_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/cert-manager" -KUADRANT_METALLB_KUSTOMIZATION="${KUADRANT_REPO}/config/metallb" - -set -e pipefail - -if [[ "${KUADRANT_REF}" != "main" ]]; then - echo "setting KUADRANT_REPO to use branch ${KUADRANT_REF}" - KUADRANT_DEPLOY_KUSTOMIZATION=${KUADRANT_DEPLOY_KUSTOMIZATION}?ref=${KUADRANT_REF} - KUADRANT_GATEWAY_API_KUSTOMIZATION=${KUADRANT_GATEWAY_API_KUSTOMIZATION}?ref=${KUADRANT_REF} - KUADRANT_ISTIO_KUSTOMIZATION=${KUADRANT_ISTIO_KUSTOMIZATION}?ref=${KUADRANT_REF} - KUADRANT_CERT_MANAGER_KUSTOMIZATION=${KUADRANT_CERT_MANAGER_KUSTOMIZATION}?ref=${KUADRANT_REF} - KUADRANT_METALLB_KUSTOMIZATION=${KUADRANT_METALLB_KUSTOMIZATION}?ref=${KUADRANT_REF} - MGC_ISTIO_KUSTOMIZATION=${MGC_ISTIO_KUSTOMIZATION}?ref=${MGC_REF} -fi +KUADRANT_DEPLOY_KUSTOMIZATION="${KUADRANT_REPO}/config/deploy?ref=${KUADRANT_REF}" +KUADRANT_GATEWAY_API_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/gateway-api?ref=${KUADRANT_REF}" +KUADRANT_ISTIO_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/istio/sail?ref=${KUADRANT_REF}" +KUADRANT_CERT_MANAGER_KUSTOMIZATION="${KUADRANT_REPO}/config/dependencies/cert-manager?ref=${KUADRANT_REF}" +KUADRANT_METALLB_KUSTOMIZATION="${KUADRANT_REPO}/config/metallb?ref=${KUADRANT_REF}" +MGC_REPO="github.com/${KUADRANT_ORG}/multicluster-gateway-controller.git" +MGC_ISTIO_KUSTOMIZATION="${MGC_REPO}/config/istio?ref=${MGC_REF}" # Make temporary directory mkdir -p ${TMP_DIR} @@ -64,64 +89,399 @@ mkdir -p ${TMP_DIR} KUADRANT_CLUSTER_NAME=kuadrant-local KUADRANT_NAMESPACE=kuadrant-system -echo "Do you want to set up a DNS provider? (y/N)" -read SETUP_PROVIDER /dev/null && ! command -v podman &>/dev/null; then + error "Neither docker nor podman could be found. Please install Docker or Podman." + exit 1 + fi + + # Check for other dependencies + for cmd in kind kubectl; do + if ! command -v $cmd &>/dev/null; then + error "Error: $cmd could not be found. Please install $cmd." + exit 1 + fi + done + + success "All dependencies are installed." +} + +# Generate MetalLB IpAddressPool for a given network +generate_ip_address_pool() { + local network_name="$1" + local script_path="${SCRIPT_DIR}/../utils/docker-network-ipaddresspool.sh" + + # interactively or piped + if [ -t 0 ]; then + # interactively + if [ -f "$script_path" ]; then + bash "$script_path" "$network_name" + else + echo "Script file not found at $script_path" >&2 + return 1 + fi + else + # piped + curl -s "${KUADRANT_REPO_RAW}/utils/docker-network-ipaddresspool.sh" | bash -s -- "$network_name" + fi +} + +requiredENV() { + info "Configuring DNS provider environment variables... 🛰️" + info "You have chosen to set up a DNS provider, which is required for using Kuadrant's DNSPolicy API." + info "Supported DNS providers are AWS Route 53 and Google Cloud DNS." + + # Read directly from the terminal, ensuring it can handle piped script execution + read -r -p "Please enter 'aws' for AWS Route 53, or 'gcp' for Google Cloud DNS: " DNS_PROVIDER /dev/null 2>&1; then + echo "Credentials provided is not in JSON format" + exit 1 + fi + + if [[ -z "${PROJECT_ID}" ]]; then + echo "Enter the project id for your GCP Cloud DNS:" + read -r PROJECT_ID ${TMP_DIR}/doctmp + info "Generating Istio configuration... 🛠️" + kubectl kustomize ${MGC_ISTIO_KUSTOMIZATION} >${TMP_DIR}/doctmp + success "Istio configuration generated." ${YQ_BIN} 'select(.kind == "CustomResourceDefinition")' ${TMP_DIR}/doctmp | kubectl apply -f - kubectl -n istio-system wait --for=condition=established crd/istiooperators.install.istio.io --timeout=60s cat ${TMP_DIR}/doctmp | kubectl apply -f - kubectl -n istio-operator wait --for=condition=Available deployment istio-operator --timeout=300s fi +success "Istio installed successfully." # Install cert-manager -echo "Installing cert-manager in ${KUADRANT_CLUSTER_NAME}" -${KUSTOMIZE_BIN} build ${KUADRANT_CERT_MANAGER_KUSTOMIZATION} | kubectl apply -f - -echo "Waiting for cert-manager deployments to be ready" +info "Installing cert-manager... 🛡️" +kubectl apply -k ${KUADRANT_CERT_MANAGER_KUSTOMIZATION} +info "Waiting for cert-manager deployments to be ready" kubectl -n cert-manager wait --for=condition=Available deployments --all --timeout=300s +setupClusterIssuer +success "cert-manager installed successfully." # Install metallb -echo "Installing metallb in ${KUADRANT_CLUSTER_NAME}" -${KUSTOMIZE_BIN} build ${KUADRANT_METALLB_KUSTOMIZATION} | kubectl apply -f - -echo "Waiting for metallb-system deployments to be ready" +info "Installing MetalLB... 🏗️" +{ + kubectl apply -k ${KUADRANT_METALLB_KUSTOMIZATION} 2>&1 +} | grep -v "Warning: .* deprecated" || true kubectl -n metallb-system wait --for=condition=Available deployments controller --timeout=300s kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=60s -kubectl apply -n metallb-system -f - <<< "$(curl -s ${KUADRANT_REPO_RAW}/utils/docker-network-ipaddresspool.sh | bash -s -- kind)" +info "Generating IP address pool for MetalLB..." +generate_ip_address_pool "kind" | kubectl apply -n metallb-system -f - +success "MetalLB installed and IP address pool generated successfully." # Install kuadrant -echo "Installing Kuadrant in ${KUADRANT_CLUSTER_NAME}" -${KUSTOMIZE_BIN} build ${KUADRANT_DEPLOY_KUSTOMIZATION} | kubectl apply -f - +info "Installing Kuadrant in ${KUADRANT_CLUSTER_NAME}..." +{ + kubectl apply -k ${KUADRANT_DEPLOY_KUSTOMIZATION} --server-side --validate=false 2>&1 +} | grep -v "Warning: .* deprecated" || true -# Configure managedzone +info "Kuadrant installation applied, configuring ManagedZone if DNS provider is set..." if [ ! -z "$DNS_PROVIDER" ]; then - configureController ${KUADRANT_CLUSTER_NAME} ${KUADRANT_NAMESPACE} + postSetup ${KUADRANT_CLUSTER_NAME} ${KUADRANT_NAMESPACE} fi # Deploy kuadrant +info "Deploying Kuadrant sample configuration..." kubectl -n ${KUADRANT_NAMESPACE} apply -f ${KUADRANT_REPO_RAW}/config/samples/kuadrant_v1beta1_kuadrant.yaml -echo "You are now set up to follow the quick start guide at https://docs.kuadrant.io/kuadrant-operator/doc/user-guides/secure-protect-connect/" +success "Kuadrant sample configuration deployed." + +info "✨🌟 Setup Complete! Your Kuadrant Quick Start environment has been successfully created. 🌟✨" + +info "Here's what has been configured:" +info " - Kubernetes cluster with name '${KUADRANT_CLUSTER_NAME}'" +info " - a Kuadrant namespace 'kuadrant-system'" +info " - Gateway API" +info " - Istio installed $([ "$ISTIO_INSTALL_SAIL" = true ] && echo "via Sail" || echo "without Sail") as a Gateway API provider" +info " - cert-manager" +info " - MetalLB with configured IP address pool" +info " - Kuadrant components and a sample configuration" +if [ ! -z "$DNS_PROVIDER" ]; then + info " - DNS provider set to '${DNS_PROVIDER}'" +fi + +info "Next steps:" +info " - Explore your new Kuadrant environment using 'kubectl get all -n kuadrant-system'." +info " - Head over to the Kuadrant quick start guide for further instructions on how to use Kuadrant with this environment:" +info " 🔗 https://docs.kuadrant.io/kuadrant-operator/doc/user-guides/secure-protect-connect/" + +echo "" +info "Thank you for using Kuadrant! If you have any questions or feedback, please reach out to our community." +info "🔗 https://github.com/Kuadrant/" diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index d69909d88..4d77da7e6 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -14,12 +14,11 @@ YQ="${2:-yq}" ## Parse kind network subnet ## Take only IPv4 subnets, exclude IPv6 SUBNET="" - # Try podman version of cmd first. docker alias may be used for podman, so network # command will be different set +e -if command -v podman &> /dev/null; then - SUBNET=`podman network inspect -f '{{range .Subnets}}{{if eq (len .Subnet.IP) 4}}{{.Subnet}}{{end}}{{end}}' $networkName` +if command -v podman &>/dev/null; then + SUBNET=$(podman network inspect -f '{{range .Subnets}}{{if eq (len .Subnet.IP) 4}}{{.Subnet}}{{end}}{{end}}' $networkName) if [[ -z "$SUBNET" ]]; then echo "Failed to obtain subnet using podman. Trying docker instead..." >&2 fi @@ -30,13 +29,12 @@ set -e # Fallback to docker version of cmd if [[ -z "$SUBNET" ]]; then - SUBNET=`docker network inspect $networkName -f '{{ (index .IPAM.Config 0).Subnet }}'` + SUBNET=$(docker network inspect $networkName -f '{{ (index .IPAM.Config 0).Subnet }}') fi - # Neither worked, error out if [[ -z "$SUBNET" ]]; then - echo "Error: parsing IPv4 network address for '$networkName' docker network" - exit 1 + echo "Error: parsing IPv4 network address for '$networkName' docker network" + exit 1 fi # shellcheck disable=SC2206