mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-11 12:06:57 +00:00
Implement Runner resource
This commit is contained in:
@@ -20,25 +20,30 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
||||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
|
||||
|
||||
// RunnerSpec defines the desired state of Runner
|
||||
type RunnerSpec struct {
|
||||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
|
||||
// Important: Run "make" to regenerate code after modifying this file
|
||||
Repository string `json:"repository"`
|
||||
|
||||
// Foo is an example field of Runner. Edit Runner_types.go to remove/update
|
||||
Foo string `json:"foo,omitempty"`
|
||||
// +optional
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
// RunnerStatus defines the observed state of Runner
|
||||
type RunnerStatus struct {
|
||||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
|
||||
// Important: Run "make" to regenerate code after modifying this file
|
||||
Registration RunnerStatusRegistration `json:"registration"`
|
||||
Phase string `json:"Phase"`
|
||||
Reason string `json:"Reason"`
|
||||
Message string `json:"Message"`
|
||||
}
|
||||
|
||||
type RunnerStatusRegistration struct {
|
||||
Repository string `json:"repository"`
|
||||
Token string `json:"token"`
|
||||
ExpiresAt metav1.Time `json:"expiresAt"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:subresource:status
|
||||
|
||||
// Runner is the Schema for the runners API
|
||||
type Runner struct {
|
||||
@@ -49,6 +54,23 @@ type Runner struct {
|
||||
Status RunnerStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (r Runner) IsRegisterable() bool {
|
||||
if r.Status.Registration.Repository != r.Spec.Repository {
|
||||
return false
|
||||
}
|
||||
|
||||
if r.Status.Registration.Token == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
now := metav1.Now()
|
||||
if r.Status.Registration.ExpiresAt.Before(&now) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
|
||||
// RunnerList contains a list of Runner
|
||||
|
||||
@@ -30,7 +30,7 @@ func (in *Runner) DeepCopyInto(out *Runner) {
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
out.Spec = in.Spec
|
||||
out.Status = in.Status
|
||||
in.Status.DeepCopyInto(&out.Status)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Runner.
|
||||
@@ -101,6 +101,7 @@ func (in *RunnerSpec) DeepCopy() *RunnerSpec {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) {
|
||||
*out = *in
|
||||
in.Registration.DeepCopyInto(&out.Registration)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerStatus.
|
||||
@@ -112,3 +113,19 @@ func (in *RunnerStatus) DeepCopy() *RunnerStatus {
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// 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
|
||||
in.ExpiresAt.DeepCopyInto(&out.ExpiresAt)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerStatusRegistration.
|
||||
func (in *RunnerStatusRegistration) DeepCopy() *RunnerStatusRegistration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(RunnerStatusRegistration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user