Skip to content

Commit

Permalink
Initial attempt to replace Github hosted runners
Browse files Browse the repository at this point in the history
  • Loading branch information
electrocucaracha committed Nov 12, 2024
1 parent 1dddb8e commit 2660ccc
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
23 changes: 22 additions & 1 deletion _chart_installers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions helm/arc/kubevirt-values.yml
Original file line number Diff line number Diff line change
@@ -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
85 changes: 85 additions & 0 deletions resources/kubevirt-runner.yml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 2660ccc

Please sign in to comment.