From e4c7fbd9ed40deba763dc78a924e05a2f39a6b99 Mon Sep 17 00:00:00 2001 From: Karel Suta Date: Wed, 29 Nov 2023 13:57:51 +0100 Subject: [PATCH] Create dedicated KinD composite action --- README.md | 18 +++++++ github-actions/kind/action.yml | 74 ++++++++++++++++++++++++++ github-actions/kind/resouces/kind.yaml | 31 +++++++++++ 3 files changed, 123 insertions(+) create mode 100644 github-actions/kind/action.yml create mode 100644 github-actions/kind/resouces/kind.yaml diff --git a/README.md b/README.md index 9df204c..3a328bb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # codeflare-common Common packages for use with CodeFlare Distributed Workload stack. + +## GitHub actions collection +Folder github-actions contains collection of GitHub composite actions which can be reused in other repositories. +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. + +Usage: +- Clone CodeFlare common repository +- Refer to the action file using `uses` step parameter pointing to the local folder path with action.yml + +### KinD GitHub action +GitHub action which spins up KinD cluster with Ingress and local registry available in the cluster. + +Action creates environment variables: +- `TEMP_DIR` - helper env variable, pointing to local temporary directory +- `REGISTRY_ADDRESS` - hostname of the locally available insecure registry +- `KIND_CONFIG_FILE` - helper env variable, pointing to the KinD config file +- `CLUSTER_TYPE` - type of cluster, hardcoded to `KIND` +- `CLUSTER_HOSTNAME` - hostname of the KinD cluster diff --git a/github-actions/kind/action.yml b/github-actions/kind/action.yml new file mode 100644 index 0000000..ea32bbf --- /dev/null +++ b/github-actions/kind/action.yml @@ -0,0 +1,74 @@ +name: "Set up KinD" +description: "Step to start and configure KinD cluster" + +inputs: + kind-node-hostname: + description: "Hostname of the main kind node" + required: false + default: kind + +runs: + using: "composite" + steps: + - name: Init directories + shell: bash + run: | + TEMP_DIR="$(pwd)/tmp" + mkdir -p "${TEMP_DIR}" + echo "TEMP_DIR=${TEMP_DIR}" >> $GITHUB_ENV + + mkdir -p "$(pwd)/bin" + echo "$(pwd)/bin" >> $GITHUB_PATH + + - name: Container image registry + shell: bash + run: | + podman run -d -p 5000:5000 --name registry registry:2.8.1 + + export REGISTRY_ADDRESS=$(hostname -i):5000 + echo "REGISTRY_ADDRESS=${REGISTRY_ADDRESS}" >> $GITHUB_ENV + echo "Container image registry started at ${REGISTRY_ADDRESS}" + + KIND_CONFIG_FILE=${{ env.TEMP_DIR }}/kind.yaml + echo "KIND_CONFIG_FILE=${KIND_CONFIG_FILE}" >> $GITHUB_ENV + envsubst < ${GITHUB_ACTION_PATH}/resouces/kind.yaml > ${KIND_CONFIG_FILE} + + sudo --preserve-env=REGISTRY_ADDRESS sh -c 'cat > /etc/containers/registries.conf.d/local.conf <> $GITHUB_ENV + echo "CLUSTER_HOSTNAME=${{ inputs.kind-node-hostname }}" >> $GITHUB_ENV diff --git a/github-actions/kind/resouces/kind.yaml b/github-actions/kind/resouces/kind.yaml new file mode 100644 index 0000000..4546589 --- /dev/null +++ b/github-actions/kind/resouces/kind.yaml @@ -0,0 +1,31 @@ +# --------------------------------------------------------------------------- +# Copyright 2023. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# --------------------------------------------------------------------------- + +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + image: kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1 + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" +containerdConfigPatches: + - |- + [plugins."io.containerd.grpc.v1.cri".registry.mirrors."${REGISTRY_ADDRESS}"] + endpoint = ["http://${REGISTRY_ADDRESS}"]