Skip to content

Commit

Permalink
ci: move to inbuilt cluster config (#419)
Browse files Browse the repository at this point in the history
Restructures repository cluster setup and configuration scripts
to be used both for local testing as well as in CI.  Adds a
CI-specific ci.sh script for the differences.  Additionally:
- Upgrades to knative v0.23.0
- Upgrades eventing from v1beta1 API to v1
- Adds binary installation script (linux)
- Serializes Build, Int Test, e2e test steps
- Installs Broker and Channel to support Knative Quickstart tutorial.
- Runs a test echo server during installation
- Adds event-based waits in place of most blind time-based waits
- Adds explicit Kubernetes version for KinD
- Replaces a NodePort patched Koourier with an explicit ingress
- Adds retries while activator webhook becomes available
- Merges allocate and configure
  • Loading branch information
lkingland committed Jul 15, 2021
1 parent 894f4fe commit b1d840a
Show file tree
Hide file tree
Showing 11 changed files with 868 additions and 505 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/pull_requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,26 @@ jobs:
run: make check

integration-test:
needs: build
runs-on: 'ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
- name: Provision Cluster
uses: container-tools/kind-action@v1 # use ./hack/allocate.sh locally
with:
version: v0.11.1
kubectl_version: v1.21.2
knative_serving: v0.23.0
knative_kourier: v0.23.0
knative_eventing: v0.23.0
config: testdata/cluster.yaml
- name: Configure Cluster
run: ./hack/configure.sh
- name: Install Binaries
run: ./hack/binaries.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Local Registry Routing
run: ./hack/ci.sh
- name: Verify Configuration
run: ./hack/test.sh
- name: Integration Test
run: make test-integration

e2e-test:
needs: integration-test
runs-on: 'ubuntu-latest'
steps:
- name: Checkout
Expand Down Expand Up @@ -124,20 +123,14 @@ jobs:
run: make build
env:
PKGER: "./pkger"
- name: Provision Cluster
uses: container-tools/kind-action@v1 # use ./hack/allocate.sh locally
with:
version: v0.10.0
kubectl_version: v1.20.0
knative_serving: v0.22.0
knative_kourier: v0.22.0
knative_eventing: v0.22.0
config: testdata/cluster.yaml
- name: Configure Cluster
run: ./hack/configure.sh
- name: Patch Network Cluster
run: ./test/patch_network.sh

- name: Install Binaries
run: ./hack/binaries.sh
- name: Allocate Cluster
run: ./hack/allocate.sh
- name: Local Registry an Routes (CI)
run: ./hack/ci.sh
- name: Verify Configuration
run: ./hack/test.sh
- name: E2E Test
run: ./test/run_e2e_test.sh # by default runs e2e + 'node' specific tests
#- name: E2E Test Go
Expand Down
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ module github.com/boson-project/func
go 1.15

require (
github.com/AlecAivazis/survey/v2 v2.2.12
github.com/buildpacks/pack v0.18.0
github.com/cloudevents/sdk-go/v2 v2.2.0
github.com/containers/image/v5 v5.10.5
github.com/docker/docker v20.10.2+incompatible
github.com/docker/docker-credential-helpers v0.6.3
github.com/AlecAivazis/survey/v2 v2.2.14
github.com/buildpacks/pack v0.19.0
github.com/cloudevents/sdk-go/v2 v2.4.1
github.com/containers/image/v5 v5.13.2
github.com/docker/docker v20.10.7+incompatible
github.com/docker/docker-credential-helpers v0.6.4
github.com/docker/go-connections v0.4.0
github.com/google/go-cmp v0.5.5
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.2.0
github.com/markbates/pkger v0.17.1
github.com/mitchellh/go-homedir v1.1.0
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
github.com/ory/viper v1.7.4
github.com/ory/viper v1.7.5
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.19.7
k8s.io/apimachinery v0.19.7
k8s.io/client-go v0.19.7
knative.dev/client v0.22.0
knative.dev/eventing v0.22.0
knative.dev/pkg v0.0.0-20210331065221-952fdd90dbb0
knative.dev/serving v0.22.0
k8s.io/api v0.20.7
k8s.io/apimachinery v0.20.7
k8s.io/client-go v0.20.7
knative.dev/client v0.24.0
knative.dev/eventing v0.24.0
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80
knative.dev/serving v0.24.0
)

// knative.dev/serving@v0.21.0 and knative.dev/pkg@v0.0.0-20210331065221-952fdd90dbb0 require different versions of go-openapi/spec
Expand Down
761 changes: 502 additions & 259 deletions go.sum

Large diffs are not rendered by default.

189 changes: 160 additions & 29 deletions hack/allocate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,39 @@ set -o errexit
set -o nounset
set -o pipefail

export TERM="${TERM:-dumb}"

main() {

local serving_version=v0.22.0
local eventing_version=v0.22.0
local kourier_version=v0.22.0
local kubernetes_version=v1.21.1
local knative_version=v0.23.0
local kourier_version=v0.23.0

local em=$(tput bold)$(tput setaf 2)
local me=$(tput sgr0)

echo "${em}Allocating...${me}"

cluster
kubernetes
serving
dns
eventing
networking
registry
configure
next_steps

echo "${em}DONE${me}"
}

cluster() {
echo "${em}Cluster${me}"
kubernetes() {
echo "${em}Kubernetes${me}"
cat <<EOF | kind create cluster --wait=60s --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
image: kindest/node:${kubernetes_version}
extraPortMappings:
- containerPort: 30080
hostPort: 80
Expand All @@ -61,41 +65,123 @@ containerdConfigPatches:
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
endpoint = ["http://kind-registry:5000"]
EOF
sleep 10
kubectl wait pod --for=condition=Ready -l '!job-name' -n kube-system --timeout=5m

}

serving() {
echo "${em}② Knative Serving${me}"
kubectl apply --filename https://github.com/knative/serving/releases/download/$serving_version/serving-crds.yaml
sleep 2
curl -L -s https://github.com/knative/serving/releases/download/$serving_version/serving-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -

kubectl apply --filename https://github.com/knative/serving/releases/download/$knative_version/serving-crds.yaml

sleep 5
kubectl wait --for=condition=Established --all crd --timeout=5m

curl -L -s https://github.com/knative/serving/releases/download/$knative_version/serving-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -


sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-serving --timeout=5m

kubectl get pod -A
}

eventing() {
echo "${em}③ Knative Eventing${me}"
kubectl apply --filename https://github.com/knative/eventing/releases/download/$eventing_version/eventing-crds.yaml
sleep 2
curl -L -s https://github.com/knative/eventing/releases/download/$eventing_version/eventing-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -
curl -L -s https://github.com/knative/eventing/releases/download/$eventing_version/in-memory-channel.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -
curl -L -s https://github.com/knative/eventing/releases/download/$eventing_version/mt-channel-broker.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -
dns() {
echo "${em}③ DNS${me}"

i=0; n=3
while :; do
kubectl patch configmap/config-domain \
--namespace knative-serving \
--type merge \
--patch '{"data":{"127.0.0.1.sslip.io":""}}' && break

(( i+=1 ))
if (( i>=n )); then
echo "Unable to set knative domain"
exit 1
fi
echo 'Retrying...'
sleep 2
done
}

networking() {
echo "${em}④ Kourier Networking${me}"
kubectl apply --filename https://github.com/knative-sandbox/net-kourier/releases/download/$kourier_version/kourier.yaml

# Install Eourier
kubectl apply --filename https://github.com/knative/net-kourier/releases/download/$kourier_version/kourier.yaml
sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n kourier-system --timeout=5m
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-serving --timeout=5m

# Configure Knative to use Kourier
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'

# Create NodePort ingress for kourier
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: kourier-ingress
namespace: kourier-system
labels:
networking.knative.dev/ingress-provider: kourier
spec:
type: NodePort
selector:
app: 3scale-kourier-gateway
ports:
- name: http2
nodePort: 30080
port: 80
targetPort: 8080
- name: https
nodePort: 30443
port: 443
targetPort: 8443
EOF

kubectl wait pod --for=condition=Ready -l '!job-name' -n kourier-system --timeout=5m
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-serving --timeout=5m
}

eventing() {
echo "${em}⑤ Knative Eventing${me}"

# CRDs
kubectl apply -f https://github.com/knative/eventing/releases/download/$knative_version/eventing-crds.yaml
sleep 5
kubectl wait --for=condition=Established --all crd --timeout=5m

# Core
curl -L -s https://github.com/knative/eventing/releases/download/$knative_version/eventing-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -
sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-eventing --timeout=5m

# Channel
curl -L -s https://github.com/knative/eventing/releases/download/$knative_version/in-memory-channel.yaml | kubectl apply -f -
sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-eventing --timeout=5m

# Broker
curl -L -s https://github.com/knative/eventing/releases/download/$knative_version/mt-channel-broker.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' -y | yq 'del(.metadata.annotations."knative.dev/example-checksum")' -y | kubectl apply -f -
sleep 5
kubectl wait pod --for=condition=Ready -l '!job-name' -n knative-eventing --timeout=5m

}

registry() {
# see https://kind.sigs.k8s.io/docs/user/local-registry/

echo "${em}⑤ Container Registry${me}"
echo "${em} Registry${me}"
docker run -d --restart=always -p "5000:5000" --name "kind-registry" registry:2
docker network connect "kind" "kind-registry"
cat <<EOF | kubectl apply -f -
kubectl apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -108,18 +194,63 @@ data:
EOF
}

next_steps() {
local red=$(tput bold)$(tput setaf 1)
configure() {
echo "${em}⑦ Configure Namespace${me}"

# Create Namespace
kubectl create namespace "func"

# Default Broker
kubectl apply -f - <<EOF
apiVersion: eventing.knative.dev/v1
kind: broker
metadata:
name: func-broker
namespace: func
EOF

# Default Channel
kubectl apply -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: imc-channel
namespace: knative-eventing
data:
channelTemplateSpec: |
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
EOF

echo "${em}⑥ Configure Registry${me}"
echo "Please ${red}manually add 'kind-registry' to your local hosts${me} file:"
echo " echo \"127.0.0.1 kind-registry\" | sudo tee --append /etc/hosts"
# Connect Default Broker->Channel
kubectl apply -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: config-br-defaults
namespace: knative-eventing
data:
default-br-config: |
# This is the cluster-wide default broker channel.
clusterDefault:
brokerClass: MTChannelBasedBroker
apiVersion: v1
kind: ConfigMap
name: imc-channel
namespace: knative-eventing
EOF

}

echo "Please ${red}manually set registry as insecure${me} in the docker daemon config (/etc/docker/daemon.json on linux or ~/.docker/daemon.json on OSX):
{
\"insecure-registries\": [ \"kind-registry:5000\" ],
}"
next_steps() {
local red=$(tput bold)$(tput setaf 1)

echo "${em}Configure Registry${me}"
echo "If not in CI (running ci.sh):
echo " ${red}add 'kind-registry' "to your local hosts${me} file:"
echo " echo \"127.0.0.1 kind-registry\" | sudo tee --append /etc/hosts"
echo " ${red}set registry as insecure${me} in the docker daemon config (/etc/docker/daemon.json on linux or ~/.docker/daemon.json on OSX):
{ \"insecure-registries\": [ \"kind-registry:5000\" ] }"
}

main "$@"

0 comments on commit b1d840a

Please sign in to comment.