github.com/lkingland/gridd@v0.0.0-20230313082622-f3ae21fe9d22/hack/configure.sh (about) 1 #!/usr/bin/env bash 2 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # https://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # 16 # Configures the current cluster for use with Functions 17 # 18 19 set -o errexit 20 set -o nounset 21 set -o pipefail 22 23 DEFAULT_NAMESPACE=func 24 25 show_help() { 26 cat << EOF 27 Configure a local cluster for use with Functions. 28 29 Usage: $(basename "$0") <options> 30 31 -h, --help Display help 32 -n, --namespace The namespace to use for Functions (default: $DEFAULT_NAMESPACE) 33 EOF 34 35 } 36 37 main() { 38 local namespace="$DEFAULT_NAMESPACE" 39 40 local em=$(tput bold)$(tput setaf 2) 41 local me=$(tput sgr0) 42 43 parse_command_line "$@" 44 45 echo "${em}Configuring...${me}" 46 47 namespace 48 network 49 kourier_nodeport 50 default_domain 51 52 sleep 10 53 kubectl --namespace kourier-system get service kourier 54 55 echo "${em}DONE${me}" 56 } 57 58 parse_command_line() { 59 while :; do 60 case "${1:-}" in 61 -h|--help) 62 show_help 63 exit 64 ;; 65 -n|--namespace) 66 if [[ -n "${2:-}" ]]; then 67 namespace="$2" 68 shift 69 else 70 echo "ERROR: '-n|--namespace' cannot be empty." >&2 71 show_help 72 exit 1 73 fi 74 ;; 75 *) 76 break 77 ;; 78 esac 79 done 80 } 81 82 namespace() { 83 echo "${em}① Namespace${me}" 84 kubectl create namespace "$namespace" 85 kubectl label namespace "$namespace" knative-eventing-injection=enabled 86 } 87 88 network() { 89 echo "${em}② Network${me}" 90 echo "Registering Kourier as ingress" 91 echo "Enabling subdomains" 92 cat <<EOF | kubectl apply -f - 93 apiVersion: v1 94 kind: ConfigMap 95 metadata: 96 name: config-network 97 namespace: knative-serving 98 data: 99 # Use Kourier for the networking layer 100 ingress.class: kourier.ingress.networking.knative.dev 101 102 # If there exists an annotation 'func.subdomain' on the service, use it 103 # instead of the default name.namespace 104 domainTemplate: |- 105 {{if index .Annotations "func.subdomain" -}} 106 {{- index .Annotations "func.subdomain" -}} 107 {{else -}} 108 {{- .Name}}.{{.Namespace -}} 109 {{end -}} 110 .{{.Domain}} 111 112 EOF 113 } 114 115 kourier_nodeport() { 116 echo "${em}③ Nodeport${me}" 117 echo 'Setting Kourier service to type NodePort' 118 # Patch for changing kourier to a NodePort for installations where a 119 # LoadBalancer is not available (for example local Kind clusters) 120 # kubectl patch -n kourier-system services/kourier -p "$(cat configure-kourier-nodeport.yaml)" 121 kubectl patch services/kourier \ 122 --namespace kourier-system \ 123 --type merge \ 124 --patch '{ 125 "spec": { 126 "ports": [ 127 { 128 "name": "http2", 129 "nodePort": 30080, 130 "port": 80, 131 "protocol": "TCP", 132 "targetPort": 8080 133 }, 134 { 135 "name": "https", 136 "nodePort": 30443, 137 "port": 443, 138 "protocol": "TCP", 139 "targetPort": 8443 140 } 141 ], 142 "type": "NodePort" 143 } 144 }' 145 } 146 147 default_domain() { 148 echo "${em}④ Default Domains${me}" 149 cat <<EOF | kubectl apply -f - 150 apiVersion: v1 151 kind: ConfigMap 152 metadata: 153 name: config-domain 154 namespace: knative-serving 155 data: 156 example.com: | 157 selector: 158 func.domain: "example.com" 159 example.org: | 160 selector: 161 func.domain: "example.org" 162 # Default is local only. 163 svc.cluster.local: "" 164 EOF 165 } 166 167 main "$@"