Skip to content

Commit 10834f8

Browse files
sutaakaropenshift-merge-bot[bot]
authored andcommitted
Create dedicated KinD composite action
1 parent 22be6af commit 10834f8

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# codeflare-common
22
Common packages for use with CodeFlare Distributed Workload stack.
3+
4+
## GitHub actions collection
5+
Folder github-actions contains collection of GitHub composite actions which can be reused in other repositories.
6+
This approach is used to keep all the usable actions on one place, unlike from default usage when every action is located in dedicated repository.
7+
8+
Usage:
9+
- Clone CodeFlare common repository
10+
- Refer to the action file using `uses` step parameter pointing to the local folder path with action.yml
11+
12+
### KinD GitHub action
13+
GitHub action which spins up KinD cluster with Ingress and local registry available in the cluster.
14+
15+
Action creates environment variables:
16+
- `TEMP_DIR` - helper env variable, pointing to local temporary directory
17+
- `REGISTRY_ADDRESS` - hostname of the locally available insecure registry
18+
- `KIND_CONFIG_FILE` - helper env variable, pointing to the KinD config file
19+
- `CLUSTER_TYPE` - type of cluster, hardcoded to `KIND`
20+
- `CLUSTER_HOSTNAME` - hostname of the KinD cluster

Diff for: github-actions/kind/action.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "Set up KinD"
2+
description: "Step to start and configure KinD cluster"
3+
4+
inputs:
5+
kind-node-hostname:
6+
description: "Hostname of the main kind node"
7+
required: false
8+
default: kind
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Init directories
14+
shell: bash
15+
run: |
16+
TEMP_DIR="$(pwd)/tmp"
17+
mkdir -p "${TEMP_DIR}"
18+
echo "TEMP_DIR=${TEMP_DIR}" >> $GITHUB_ENV
19+
20+
mkdir -p "$(pwd)/bin"
21+
echo "$(pwd)/bin" >> $GITHUB_PATH
22+
23+
- name: Container image registry
24+
shell: bash
25+
run: |
26+
podman run -d -p 5000:5000 --name registry registry:2.8.1
27+
28+
export REGISTRY_ADDRESS=$(hostname -i):5000
29+
echo "REGISTRY_ADDRESS=${REGISTRY_ADDRESS}" >> $GITHUB_ENV
30+
echo "Container image registry started at ${REGISTRY_ADDRESS}"
31+
32+
KIND_CONFIG_FILE=${{ env.TEMP_DIR }}/kind.yaml
33+
echo "KIND_CONFIG_FILE=${KIND_CONFIG_FILE}" >> $GITHUB_ENV
34+
envsubst < ${GITHUB_ACTION_PATH}/resouces/kind.yaml > ${KIND_CONFIG_FILE}
35+
36+
sudo --preserve-env=REGISTRY_ADDRESS sh -c 'cat > /etc/containers/registries.conf.d/local.conf <<EOF
37+
[[registry]]
38+
prefix = "$REGISTRY_ADDRESS"
39+
insecure = true
40+
location = "$REGISTRY_ADDRESS"
41+
EOF'
42+
43+
- name: Setup KinD cluster
44+
uses: helm/[email protected]
45+
with:
46+
cluster_name: cluster
47+
version: v0.17.0
48+
config: ${{ env.KIND_CONFIG_FILE }}
49+
50+
- name: Print cluster info
51+
shell: bash
52+
run: |
53+
echo "KinD cluster:"
54+
kubectl cluster-info
55+
kubectl describe nodes
56+
57+
- name: Install Ingress controller
58+
shell: bash
59+
run: |
60+
VERSION=controller-v1.6.4
61+
echo "Deploying Ingress controller into KinD cluster"
62+
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/"${VERSION}"/deploy/static/provider/kind/deploy.yaml | sed "s/--publish-status-address=localhost/--report-node-internal-ip-address\\n - --status-update-interval=10/g" | kubectl apply -f -
63+
kubectl annotate ingressclass nginx "ingressclass.kubernetes.io/is-default-class=true"
64+
kubectl -n ingress-nginx wait --timeout=300s --for=condition=Available deployments --all
65+
66+
- name: Add ${{ inputs.kind-node-hostname }} host to machine hosts
67+
shell: bash
68+
run: echo "127.0.0.1 ${{ inputs.kind-node-hostname }}" | sudo tee -a /etc/hosts
69+
70+
- name: Set env variables for tests to properly leverage KinD cluster
71+
shell: bash
72+
run: |
73+
echo "CLUSTER_TYPE=KIND" >> $GITHUB_ENV
74+
echo "CLUSTER_HOSTNAME=${{ inputs.kind-node-hostname }}" >> $GITHUB_ENV

Diff for: github-actions/kind/resouces/kind.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ---------------------------------------------------------------------------
2+
# Copyright 2023.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ---------------------------------------------------------------------------
16+
17+
kind: Cluster
18+
apiVersion: kind.x-k8s.io/v1alpha4
19+
nodes:
20+
- role: control-plane
21+
image: kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
22+
kubeadmConfigPatches:
23+
- |
24+
kind: InitConfiguration
25+
nodeRegistration:
26+
kubeletExtraArgs:
27+
node-labels: "ingress-ready=true"
28+
containerdConfigPatches:
29+
- |-
30+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${REGISTRY_ADDRESS}"]
31+
endpoint = ["http://${REGISTRY_ADDRESS}"]

0 commit comments

Comments
 (0)