Add Repository information to Runner Status (#2093)

Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Stephane Moser 2023-01-18 00:09:45 +00:00 committed by GitHub
parent de244a17be
commit 606ed1b28e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 157 additions and 2 deletions

View File

@ -248,10 +248,60 @@ type RunnerStatus struct {
// +optional // +optional
Message string `json:"message,omitempty"` Message string `json:"message,omitempty"`
// +optional // +optional
WorkflowStatus *WorkflowStatus `json:"workflow"`
// +optional
// +nullable // +nullable
LastRegistrationCheckTime *metav1.Time `json:"lastRegistrationCheckTime,omitempty"` LastRegistrationCheckTime *metav1.Time `json:"lastRegistrationCheckTime,omitempty"`
} }
// WorkflowStatus contains various information that is propagated
// from GitHub Actions workflow run environment variables to
// ease monitoring workflow run/job/steps that are triggerred on the runner.
type WorkflowStatus struct {
// +optional
// Name is the name of the workflow
// that is triggerred within the runner.
// It corresponds to GITHUB_WORKFLOW defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
Name string `json:"name,omitempty"`
// +optional
// Repository is the owner and repository name of the workflow
// that is triggerred within the runner.
// It corresponds to GITHUB_REPOSITORY defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
Repository string `json:"repository,omitempty"`
// +optional
// ReositoryOwner is the repository owner's name for the workflow
// that is triggerred within the runner.
// It corresponds to GITHUB_REPOSITORY_OWNER defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
RepositoryOwner string `json:"repositoryOwner,omitempty"`
// +optional
// GITHUB_RUN_NUMBER is the unique number for the current workflow run
// that is triggerred within the runner.
// It corresponds to GITHUB_RUN_ID defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
RunNumber string `json:"runNumber,omitempty"`
// +optional
// RunID is the unique number for the current workflow run
// that is triggerred within the runner.
// It corresponds to GITHUB_RUN_ID defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
RunID string `json:"runID,omitempty"`
// +optional
// Job is the name of the current job
// that is triggerred within the runner.
// It corresponds to GITHUB_JOB defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
Job string `json:"job,omitempty"`
// +optional
// Action is the name of the current action or the step ID of the current step
// that is triggerred within the runner.
// It corresponds to GITHUB_ACTION defined in
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
Action string `json:"action,omitempty"`
}
// RunnerStatusRegistration contains runner registration status // RunnerStatusRegistration contains runner registration status
type RunnerStatusRegistration struct { type RunnerStatusRegistration struct {
Enterprise string `json:"enterprise,omitempty"` Enterprise string `json:"enterprise,omitempty"`
@ -316,6 +366,8 @@ func (w *WorkVolumeClaimTemplate) V1VolumeMount(mountPath string) corev1.VolumeM
// +kubebuilder:printcolumn:JSONPath=".spec.labels",name=Labels,type=string // +kubebuilder:printcolumn:JSONPath=".spec.labels",name=Labels,type=string
// +kubebuilder:printcolumn:JSONPath=".status.phase",name=Status,type=string // +kubebuilder:printcolumn:JSONPath=".status.phase",name=Status,type=string
// +kubebuilder:printcolumn:JSONPath=".status.message",name=Message,type=string // +kubebuilder:printcolumn:JSONPath=".status.message",name=Message,type=string
// +kubebuilder:printcolumn:JSONPath=".status.workflow.repository",name=WF Repo,type=string
// +kubebuilder:printcolumn:JSONPath=".status.workflow.runID",name=WF Run,type=string
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// Runner is the Schema for the runners API // Runner is the Schema for the runners API

View File

@ -1049,6 +1049,11 @@ func (in *RunnerSpec) DeepCopy() *RunnerSpec {
func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) { func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) {
*out = *in *out = *in
in.Registration.DeepCopyInto(&out.Registration) in.Registration.DeepCopyInto(&out.Registration)
if in.WorkflowStatus != nil {
in, out := &in.WorkflowStatus, &out.WorkflowStatus
*out = new(WorkflowStatus)
**out = **in
}
if in.LastRegistrationCheckTime != nil { if in.LastRegistrationCheckTime != nil {
in, out := &in.LastRegistrationCheckTime, &out.LastRegistrationCheckTime in, out := &in.LastRegistrationCheckTime, &out.LastRegistrationCheckTime
*out = (*in).DeepCopy() *out = (*in).DeepCopy()
@ -1212,3 +1217,18 @@ func (in *WorkflowJobSpec) DeepCopy() *WorkflowJobSpec {
in.DeepCopyInto(out) in.DeepCopyInto(out)
return out return out
} }
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *WorkflowStatus) DeepCopyInto(out *WorkflowStatus) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowStatus.
func (in *WorkflowStatus) DeepCopy() *WorkflowStatus {
if in == nil {
return nil
}
out := new(WorkflowStatus)
in.DeepCopyInto(out)
return out
}

View File

@ -36,6 +36,12 @@ spec:
- jsonPath: .status.message - jsonPath: .status.message
name: Message name: Message
type: string type: string
- jsonPath: .status.workflow.repository
name: WF Repo
type: string
- jsonPath: .status.workflow.runID
name: WF Run
type: string
- jsonPath: .metadata.creationTimestamp - jsonPath: .metadata.creationTimestamp
name: Age name: Age
type: date type: date
@ -5225,6 +5231,31 @@ spec:
- expiresAt - expiresAt
- token - token
type: object type: object
workflow:
description: WorkflowStatus contains various information that is propagated from GitHub Actions workflow run environment variables to ease monitoring workflow run/job/steps that are triggerred on the runner.
properties:
action:
description: Action is the name of the current action or the step ID of the current step that is triggerred within the runner. It corresponds to GITHUB_ACTION defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
job:
description: Job is the name of the current job that is triggerred within the runner. It corresponds to GITHUB_JOB defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
name:
description: Name is the name of the workflow that is triggerred within the runner. It corresponds to GITHUB_WORKFLOW defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
repository:
description: Repository is the owner and repository name of the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
repositoryOwner:
description: ReositoryOwner is the repository owner's name for the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY_OWNER defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
runID:
description: RunID is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
runNumber:
description: GITHUB_RUN_NUMBER is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
type: object
type: object type: object
type: object type: object
served: true served: true

View File

@ -36,6 +36,12 @@ spec:
- jsonPath: .status.message - jsonPath: .status.message
name: Message name: Message
type: string type: string
- jsonPath: .status.workflow.repository
name: WF Repo
type: string
- jsonPath: .status.workflow.runID
name: WF Run
type: string
- jsonPath: .metadata.creationTimestamp - jsonPath: .metadata.creationTimestamp
name: Age name: Age
type: date type: date
@ -5225,6 +5231,31 @@ spec:
- expiresAt - expiresAt
- token - token
type: object type: object
workflow:
description: WorkflowStatus contains various information that is propagated from GitHub Actions workflow run environment variables to ease monitoring workflow run/job/steps that are triggerred on the runner.
properties:
action:
description: Action is the name of the current action or the step ID of the current step that is triggerred within the runner. It corresponds to GITHUB_ACTION defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
job:
description: Job is the name of the current job that is triggerred within the runner. It corresponds to GITHUB_JOB defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
name:
description: Name is the name of the workflow that is triggerred within the runner. It corresponds to GITHUB_WORKFLOW defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
repository:
description: Repository is the owner and repository name of the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
repositoryOwner:
description: ReositoryOwner is the repository owner's name for the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY_OWNER defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
runID:
description: RunID is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
runNumber:
description: GITHUB_RUN_NUMBER is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables
type: string
type: object
type: object type: object
type: object type: object
served: true served: true

View File

@ -15,9 +15,30 @@ if [[ ${RUNNER_STATUS_UPDATE_HOOK:-false} == true ]]; then
namespace=$(cat ${serviceaccount}/namespace) namespace=$(cat ${serviceaccount}/namespace)
token=$(cat ${serviceaccount}/token) token=$(cat ${serviceaccount}/token)
phase=$1 phase=$1
shift message=${2:-}
jq -n --arg phase "$phase" --arg message "${*:-}" '.status.phase = $phase | .status.message = $message' | curl \ data=$(jq -n --arg phase "$phase" \
--arg message "$message" \
--arg workflow_repository "${GITHUB_REPOSITORY:-}" \
--arg workflow_repository_owner "${GITHUB_REPOSITORY_OWNER:-}" \
--arg workflow_name "${GITHUB_WORKFLOW:-}" \
--arg workflow_run_id "${GITHUB_RUN_ID:-}" \
--arg workflow_run_number "${GITHUB_RUN_NUMBER:-}" \
--arg workflow_job "${GITHUB_JOB:-}" \
--arg workflow_action "${GITHUB_ACTION:-}" \
'
.status.phase = $phase
| .status.message = $message
| .status.workflow.name = $workflow_name
| .status.workflow.runID = $workflow_run_id
| .status.workflow.runNumber = $workflow_run_number
| .status.workflow.repository = $workflow_repository
| .status.workflow.repositoryOwner = $workflow_repository_owner
| .status.workflow.job = $workflow_job
| .status.workflow.action = $workflow_action
')
echo "$data" | curl \
--cacert ${serviceaccount}/ca.crt \ --cacert ${serviceaccount}/ca.crt \
--data @- \ --data @- \
--noproxy '*' \ --noproxy '*' \