From 8c5b776807a7264f88890666ca2be13ce080fe69 Mon Sep 17 00:00:00 2001 From: Reinier Timmer Date: Fri, 24 Apr 2020 11:29:52 +0200 Subject: [PATCH] support runner labels --- api/v1alpha1/runner_types.go | 5 +++++ api/v1alpha1/zz_generated.deepcopy.go | 10 ++++++++++ .../actions.summerwind.dev_runnerdeployments.yaml | 4 ++++ .../actions.summerwind.dev_runnerreplicasets.yaml | 4 ++++ config/crd/bases/actions.summerwind.dev_runners.yaml | 11 +++++++++++ controllers/runner_controller.go | 6 ++++++ runner/entrypoint.sh | 6 +++++- 7 files changed, 45 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/runner_types.go b/api/v1alpha1/runner_types.go index 3ea55925..3a9f2ffe 100644 --- a/api/v1alpha1/runner_types.go +++ b/api/v1alpha1/runner_types.go @@ -31,6 +31,9 @@ type RunnerSpec struct { // +kubebuilder:validation:Pattern=`^[^/]*$` Repository string `json:"repository,omitempty"` + // +optional + Labels []string `json:"labels,omitempty"` + // +optional Containers []corev1.Container `json:"containers,omitempty"` // +optional @@ -84,6 +87,7 @@ type RunnerStatus struct { type RunnerStatusRegistration struct { Organization string `json:"organization"` Repository string `json:"repository,omitempty"` + Labels []string `json:"labels,omitempty"` Token string `json:"token"` ExpiresAt metav1.Time `json:"expiresAt"` } @@ -92,6 +96,7 @@ type RunnerStatusRegistration struct { // +kubebuilder:subresource:status // +kubebuilder:printcolumn:JSONPath=".spec.organization",name=Organization,type=string // +kubebuilder:printcolumn:JSONPath=".spec.repository",name=Repository,type=string +// +kubebuilder:printcolumn:JSONPath=".spec.labels",name=Labels,type=string // +kubebuilder:printcolumn:JSONPath=".status.phase",name=Status,type=string // Runner is the Schema for the runners API diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 0b700e1c..029f7219 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -277,6 +277,11 @@ func (in *RunnerReplicaSetStatus) DeepCopy() *RunnerReplicaSetStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) { *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Containers != nil { in, out := &in.Containers, &out.Containers *out = make([]v1.Container, len(*in)) @@ -404,6 +409,11 @@ func (in *RunnerStatus) DeepCopy() *RunnerStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RunnerStatusRegistration) DeepCopyInto(out *RunnerStatusRegistration) { *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make([]string, len(*in)) + copy(*out, *in) + } in.ExpiresAt.DeepCopyInto(&out.ExpiresAt) } diff --git a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml index 3158dbdc..5bca12b6 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml @@ -4111,6 +4111,10 @@ spec: - name type: object type: array + labels: + items: + type: string + type: array nodeSelector: additionalProperties: type: string diff --git a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml index fdc49396..193b1c33 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml @@ -4111,6 +4111,10 @@ spec: - name type: object type: array + labels: + items: + type: string + type: array nodeSelector: additionalProperties: type: string diff --git a/config/crd/bases/actions.summerwind.dev_runners.yaml b/config/crd/bases/actions.summerwind.dev_runners.yaml index 13f05915..2de67d7d 100644 --- a/config/crd/bases/actions.summerwind.dev_runners.yaml +++ b/config/crd/bases/actions.summerwind.dev_runners.yaml @@ -15,6 +15,9 @@ spec: - JSONPath: .spec.repository name: Repository type: string + - JSONPath: .spec.labels + name: Labels + type: string - JSONPath: .status.phase name: Status type: string @@ -3857,6 +3860,10 @@ spec: - name type: object type: array + labels: + items: + type: string + type: array nodeSelector: additionalProperties: type: string @@ -6316,6 +6323,10 @@ spec: expiresAt: format: date-time type: string + labels: + items: + type: string + type: array organization: type: string repository: diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index 92e06c49..be6863ed 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "reflect" + "strings" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/api/errors" @@ -119,6 +120,7 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { updated.Status.Registration = v1alpha1.RunnerStatusRegistration{ Organization: runner.Spec.Organization, Repository: runner.Spec.Repository, + Labels: runner.Spec.Labels, Token: rt.GetToken(), ExpiresAt: metav1.NewTime(rt.GetExpiresAt().Time), } @@ -262,6 +264,10 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { Name: "RUNNER_REPO", Value: runner.Spec.Repository, }, + { + Name: "RUNNER_LABELS", + Value: strings.Join(runner.Spec.Labels, ","), + }, { Name: "RUNNER_TOKEN", Value: runner.Status.Registration.Token, diff --git a/runner/entrypoint.sh b/runner/entrypoint.sh index 32d4ae31..56cb7281 100755 --- a/runner/entrypoint.sh +++ b/runner/entrypoint.sh @@ -16,13 +16,17 @@ else exit 1 fi +if [ -n "${RUNNER_LABELS}" ]; then + LABEL_ARG="--labels ${RUNNER_LABELS}" +fi + if [ -z "${RUNNER_TOKEN}" ]; then echo "RUNNER_TOKEN must be set" 1>&2 exit 1 fi cd /runner -./config.sh --unattended --replace --name "${RUNNER_NAME}" --url "https://github.com/${ATTACH}" --token "${RUNNER_TOKEN}" +./config.sh --unattended --replace --name "${RUNNER_NAME}" --url "https://github.com/${ATTACH}" --token "${RUNNER_TOKEN}" ${LABEL_ARG} unset RUNNER_NAME RUNNER_REPO RUNNER_TOKEN exec ./run.sh --once