diff --git a/_chart_installers.sh b/_chart_installers.sh index 61e61c66..e0ea3ed2 100755 --- a/_chart_installers.sh +++ b/_chart_installers.sh @@ -85,6 +85,7 @@ function _install_chart { local name="$1" local chart="$2" local namespace="${3:-"$name-system"}" + local wait="${4:-"true"}" install_helm helm_installed_version=$(helm version --short --client | awk '{sub(/+.*/,X,$0);sub(/Client: /,X,$0);print}') @@ -104,7 +105,7 @@ function _install_chart { eval "$cmd" "$name" "$chart" fi - wait_for_pods "$namespace" + [[ $wait == "true" ]] && wait_for_pods "$namespace" } function _add_helm_repo { @@ -269,3 +270,23 @@ function _install_chart_k8sgpt-operator { _add_helm_repo k8sgpt https://charts.k8sgpt.ai/ _install_chart k8sgpt-operator k8sgpt/k8sgpt-operator } + +function _install_arc_controller { + _install_chart arc oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller +} + +# install_arc() - Install Actions Runner +function install_chart_arc { + ! kubectl get crds autoscalinglisteners.actions.github.com >/dev/null && _install_arc_controller + + namespace="${KRD_ARC_GITHUB_URL##*/}-runners" + KRD_CHART_VALUES="githubConfigUrl=$KRD_ARC_GITHUB_URL,githubConfigSecret=gh-runners-token" + ! kubectl get namespaces "${namespace}" && kubectl create namespace "${namespace}" + ! kubectl get secrets -n "${namespace}" gh-runners-token && kubectl -n "${namespace}" create secret generic gh-runners-token --from-literal=github_token="$KRD_ARC_TOKEN" + ! helm get metadata arc-runner-set -n "${namespace}" >/dev/null && _install_chart arc-runner-set oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set "$namespace" "false" + if kubectl get crds virtualmachines.kubevirt.io >/dev/null; then + kubectl apply -f resources/kubevirt-runner.yml -n "$namespace" + kubectl create rolebinding kubevirt-actions-runner -n "$namespace" --serviceaccount "${namespace}:kubevirt-actions-runner" --role=kubevirt-actions-runner || : + KRD_CHART_FILE="helm/arc/kubevirt-values.yml" _install_chart kubevirt-runner-set oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set "$namespace" "false" + fi +} diff --git a/helm/arc/kubevirt-values.yml b/helm/arc/kubevirt-values.yml new file mode 100644 index 00000000..4ca453d1 --- /dev/null +++ b/helm/arc/kubevirt-values.yml @@ -0,0 +1,19 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2024 +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +template: + spec: + serviceAccountName: kubevirt-actions-runner + containers: + - name: runner + image: ghcr.io/zhaofengli/kubevirt-actions-runner:latest + command: [] + env: + - name: KUBEVIRT_VM_TEMPLATE + value: vm-template diff --git a/resources/kubevirt-runner.yml b/resources/kubevirt-runner.yml new file mode 100644 index 00000000..812c4115 --- /dev/null +++ b/resources/kubevirt-runner.yml @@ -0,0 +1,85 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2024 +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +apiVersion: kubevirt.io/v1 +kind: VirtualMachine +metadata: + name: vm-template +spec: + runStrategy: Manual + template: + metadata: + name: runner + spec: + architecture: amd64 + terminationGracePeriodSeconds: 30 + domain: + devices: + filesystems: + - name: runner-info + virtiofs: {} + disks: + - name: containerdisk + disk: + bus: virtio + - name: cloudinitdisk + disk: + bus: virtio + interfaces: + - name: default + masquerade: {} + cpu: + cores: 3 + resources: + requests: + memory: 14Gi + networks: + - name: default + pod: {} + volumes: + - name: containerdisk + containerDisk: + image: quay.io/containerdisks/fedora:latest + - name: cloudinitdisk + cloudInitNoCloud: + userData: |- + #cloud-config + users: + - name: runner + homedir: /home/runner + sudo: ["ALL=(ALL) NOPASSWD:ALL"] + mounts: + - [ runner-info, /runner-info/, virtiofs, "rw,relatime,user=fedora" ] + packages: + - jq + bootcmd: + - "sudo mkdir /opt/runner" + - "curl -sL https://github.com/actions/runner/releases/download/v2.320.0/actions-runner-linux-x64-2.320.0.tar.gz | sudo tar -xz -C /opt/runner" + - "sudo /opt/runner/bin/installdependencies.sh" + runcmd: + - "sudo chown -R runner: /opt/runner" + - "sudo runuser -l runner -c '/opt/runner/run.sh --jitconfig $(jq -r '.jitconfig' /runner-info/runner-info.json)'" + - "sudo shutdown -h +1" +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kubevirt-actions-runner +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: kubevirt-actions-runner +rules: + - apiGroups: ["kubevirt.io"] + resources: ["virtualmachines"] + verbs: ["get", "watch", "list"] + - apiGroups: ["kubevirt.io"] + resources: ["virtualmachineinstances"] + verbs: ["get", "watch", "list", "create", "delete"]