actions-runner-controller icon indicating copy to clipboard operation
actions-runner-controller copied to clipboard

Scaleset listener fails: could not patch ephemeral runner set

Open robertsa1-els opened this issue 3 years ago • 8 comments

Checks

  • [X] I've already read https://github.com/actions/actions-runner-controller/blob/master/TROUBLESHOOTING.md and I'm sure my issue is not covered in the troubleshooting guide.
  • [X] I'm not using a custom entrypoint in my runner image

Controller Version

0.4.0

Helm Chart Version

0.4.0

CertManager Version

NA

Deployment Method

Helm

cert-manager installation

NA

Checks

  • [X] This isn't a question or user support case (For Q&A and community support, go to Discussions. It might also be a good idea to contract with any of contributors and maintainers if your business is so critical and therefore you need priority support
  • [X] I've read releasenotes before submitting this issue and I'm sure it's not due to any recently-introduced backward-incompatible changes
  • [X] My actions-runner-controller version (v0.x.y) does support the feature
  • [X] I've already upgraded ARC (including the CRDs, see charts/actions-runner-controller/docs/UPGRADING.md for details) to the latest and it didn't fix the issue
  • [X] I've migrated to the workflow job webhook event (if you using webhook driven scaling)

Resource Definitions

Using ScaleSets

To Reproduce

1. Helm install the scaleset controller `helm install -n gha-controller gha-runner-scale-set-controller oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller`

2. Install a scale set in another namespace

helm install "${INSTALLATION_NAME}" \
    --namespace "${NAMESPACE}" \
    --set githubConfigUrl="${GITHUB_CONFIG_URL}" \
    --set githubConfigSecret.github_token="${GITHUB_PAT}" \
    --set minRunners=1 \
    --set runnerGroup="${INSTALLATION_NAME}" \
    --set containerMode.type="dind" \
    oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set
  1. The Listener goes into an Error loop with the error message
2023-05-30T15:07:22Z	ERROR	Run error	{"error": "failed to start message queue listener: could not get and process message. fail to process initial message. could not scale ephemeral runner set (gha-runners/test-scaleset-44xvv). could not patch ephemeral runner set , patch JSON: {\"spec\":{\"replicas\":1}}, error: ephemeralrunnersets.actions.github.com \"test-scaleset-44xvv\" is forbidden: User \"system:serviceaccount:gha-controller:test-scaleset-67fdb58c-listener\" cannot patch resource \"ephemeralrunnersets\" in API group \"actions.github.com\" in the namespace \"gha-runners\""}

Describe the bug

It looks like the listener only has a namespaced scoped role to the namespace where the controller lives. This role doesn't appear to have any permissions over ephemeralrunnersets even if it was a cluster role

❯ k get -o yaml roles gha-runner-scale-set-controller-manager-listener-role -n gha-controller
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  annotations:
    meta.helm.sh/release-name: gha-runner-scale-set-controller
    meta.helm.sh/release-namespace: gha-controller
  creationTimestamp: "2023-05-30T14:44:13Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: gha-runner-scale-set-controller-manager-listener-role
  namespace: gha-controller
  resourceVersion: "74506"
  uid: 7154a61f-fc71-4539-9733-9b26e9650ff1
rules:
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - create
  - delete
  - get
- apiGroups:
  - ""
  resources:
  - pods/status
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - create
  - delete
  - get
  - patch
  - update
- apiGroups:
  - ""
  resources:
  - serviceaccounts
  verbs:
  - create
  - delete
  - get
  - patch
  - update

Describe the expected behavior

According to the docs here https://github.com/actions/actions-runner-controller/tree/master/docs/preview/gha-runner-scale-set-controller This approach should work and controller and listener can manage runner in another NS

Whole Controller Logs

Cannot give this as working for a company. There are no errors in this logs.

Whole Runner Pod Logs

There is no runner log as cannot get listener to spin them up

Additional Context

No response

robertsa1-els avatar May 30 '23 15:05 robertsa1-els

Hello! Thank you for filing an issue.

The maintainers will triage your issue shortly.

In the meantime, please take a look at the troubleshooting guide for bug reports.

If this is a feature request, please review our contribution guidelines.

github-actions[bot] avatar May 30 '23 15:05 github-actions[bot]

Attaching the Controller ClusterRole (which does have permissions over ephemeralrunnersets) to the listener allows this to work. So it is certainly a permissions bug.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {SNIP}
  creationTimestamp: "2023-05-30T16:23:22Z"
  name: test-listener-binding
  resourceVersion: "128950"
  uid: 01763f80-d907-490a-805e-3fd19c82b40d
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: gha-runner-scale-set-controller-manager-cluster-role
subjects:
- kind: ServiceAccount
  name: test-scaleset-67fdb58c-listener
  namespace: gha-controller

robertsa1-els avatar May 31 '23 08:05 robertsa1-els

Have re-created the listener role as a cluster role and needed to add some further scopes to allow editing of ephemeralscalesets and this also worked.
However just adding the ephemeralscalesets scopes to the namespaced listener role did NOT work as it could not patch in a different namespace.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: gha-runner-scale-set-listener-cluster-role
rules:
  - apiGroups:
      - actions.github.com
    resources:
      - ephemeralrunnersets
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - actions.github.com
    resources:
      - ephemeralrunners/finalizers
    verbs:
      - patch
      - update
  - apiGroups:
      - actions.github.com
    resources:
      - ephemeralrunners/status
    verbs:
      - get
      - patch
      - update
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - create
      - delete
      - get
  - apiGroups:
      - ""
    resources:
      - pods/status
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
      - delete
      - get
      - patch
      - update
  - apiGroups:
      - ""
    resources:
      - serviceaccounts
    verbs:
      - create
      - delete
      - get
      - patch
      - update

robertsa1-els avatar May 31 '23 09:05 robertsa1-els

Closing this. It looks like when we deployed the controller and the scaleset in the same NS we then cleared down (or so we thought) and deployed to separate Namespaces, however there were some leftover roles in the which had delete protection finalizers which were not cleaned up and it appears that these were causing our issues.

Once we removed these hangover roles (deleted the Namespaces), and installed again from scratch the solution worked as expected.

robertsa1-els avatar May 31 '23 11:05 robertsa1-els

hi, i have similar issue: 2023-10-02T17:47:43.539027802+02:00 2023-10-02T15:47:43Z ERROR Error encountered {"error": "failed to start message queue listener: could not get and process message. fail to process initial message. could not scale ephemeral runner set (arc-runners/arc-runner-set-62s99). could not patch ephemeral runner set , patch JSON: {"spec":{"replicas":null}}, error: Patch "https://10.43.0.1:443/apis/actions.github.com/v1alpha1/namespaces/arc-runners/ephemeralrunnersets/arc-runner-set-62s99": Forbidden"}

im running controller in arc-systems and runner set in arc-runners namespaces any help would be appreciated

dmitrijrub avatar Oct 02 '23 15:10 dmitrijrub

solved, issue was that cluster cider was not add to no_proxy

dmitrijrub avatar Oct 04 '23 22:10 dmitrijrub

Just came across this. Can someone explain to me what is going on here with adding the cluster cidr to noProxy. 🙏🏿

scottmelhop avatar Oct 28 '24 09:10 scottmelhop

It happened to me too.

Fix attempt

helm uninstall -n arc-runners <ARC_NAME>
sleep 5  # drain the remaining ARC pods

# Check the left over resources
kubectl get roles,rolebindings,ephemeralrunnersets -n arc-runners
kubectl get AutoscalingListener -n arc-systems

Remove the leftovers resources that contain the same name as your <ARC_NAME> Helm release name, e.g.:

kubectl delete AutoscalingListener -n arc-systems <ARC_NAME>-b7f57cf4-listener

ℹ️ Optionally (normally not required), you can delete the pod arc-gha-rs-controller-*** in the namespace arc-systems to make sure that it cannot remember anything from the removed ARC runner:

kubectl delete pod arc-gha-rs-controller-*** -n arc-systems

Install the ARC runner Helm chart, as you did before (see Configuring a runner scale set), e.g. something like this:

INSTALLATION_NAME="arc-runner-set"
NAMESPACE="arc-runners"
GITHUB_CONFIG_URL="https://github.com/<your_enterprise/org/repo>"
GITHUB_PAT="<PAT>"
helm install "${INSTALLATION_NAME}" \
    --namespace "${NAMESPACE}" \
    --create-namespace \
    --set githubConfigUrl="${GITHUB_CONFIG_URL}" \
    --set githubConfigSecret.github_token="${GITHUB_PAT}" \
    oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set

Hope it helps,

samuel-phan avatar Apr 01 '26 15:04 samuel-phan