Implement Runner resource
This commit is contained in:
parent
04a8e562c0
commit
6b392aedda
|
|
@ -20,25 +20,30 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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
|
// RunnerSpec defines the desired state of Runner
|
||||||
type RunnerSpec struct {
|
type RunnerSpec struct {
|
||||||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
|
Repository string `json:"repository"`
|
||||||
// Important: Run "make" to regenerate code after modifying this file
|
|
||||||
|
|
||||||
// Foo is an example field of Runner. Edit Runner_types.go to remove/update
|
// +optional
|
||||||
Foo string `json:"foo,omitempty"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunnerStatus defines the observed state of Runner
|
// RunnerStatus defines the observed state of Runner
|
||||||
type RunnerStatus struct {
|
type RunnerStatus struct {
|
||||||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
|
Registration RunnerStatusRegistration `json:"registration"`
|
||||||
// Important: Run "make" to regenerate code after modifying this file
|
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:object:root=true
|
||||||
|
// +kubebuilder:subresource:status
|
||||||
|
|
||||||
// Runner is the Schema for the runners API
|
// Runner is the Schema for the runners API
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
|
|
@ -49,6 +54,23 @@ type Runner struct {
|
||||||
Status RunnerStatus `json:"status,omitempty"`
|
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
|
// +kubebuilder:object:root=true
|
||||||
|
|
||||||
// RunnerList contains a list of Runner
|
// RunnerList contains a list of Runner
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func (in *Runner) DeepCopyInto(out *Runner) {
|
||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
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.
|
// 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.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) {
|
func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
in.Registration.DeepCopyInto(&out.Registration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerStatus.
|
// 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)
|
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 *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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
controller-gen.kubebuilder.io/version: v0.2.4
|
||||||
|
creationTimestamp: null
|
||||||
|
name: runners.actions.summerwind.dev
|
||||||
|
spec:
|
||||||
|
group: actions.summerwind.dev
|
||||||
|
names:
|
||||||
|
kind: Runner
|
||||||
|
listKind: RunnerList
|
||||||
|
plural: runners
|
||||||
|
singular: runner
|
||||||
|
scope: Namespaced
|
||||||
|
subresources:
|
||||||
|
status: {}
|
||||||
|
validation:
|
||||||
|
openAPIV3Schema:
|
||||||
|
description: Runner is the Schema for the runners API
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
description: 'APIVersion defines the versioned schema of this representation
|
||||||
|
of an object. Servers should convert recognized schemas to the latest
|
||||||
|
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
description: 'Kind is a string value representing the REST resource this
|
||||||
|
object represents. Servers may infer this from the endpoint the client
|
||||||
|
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||||
|
type: string
|
||||||
|
metadata:
|
||||||
|
type: object
|
||||||
|
spec:
|
||||||
|
description: RunnerSpec defines the desired state of Runner
|
||||||
|
properties:
|
||||||
|
image:
|
||||||
|
type: string
|
||||||
|
repository:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- repository
|
||||||
|
type: object
|
||||||
|
status:
|
||||||
|
description: RunnerStatus defines the observed state of Runner
|
||||||
|
properties:
|
||||||
|
Message:
|
||||||
|
type: string
|
||||||
|
Phase:
|
||||||
|
type: string
|
||||||
|
Reason:
|
||||||
|
type: string
|
||||||
|
registration:
|
||||||
|
properties:
|
||||||
|
expiresAt:
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
|
repository:
|
||||||
|
type: string
|
||||||
|
token:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- expiresAt
|
||||||
|
- repository
|
||||||
|
- token
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- Message
|
||||||
|
- Phase
|
||||||
|
- Reason
|
||||||
|
- registration
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
version: v1alpha1
|
||||||
|
versions:
|
||||||
|
- name: v1alpha1
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
status:
|
||||||
|
acceptedNames:
|
||||||
|
kind: ""
|
||||||
|
plural: ""
|
||||||
|
conditions: []
|
||||||
|
storedVersions: []
|
||||||
Loading…
Reference in New Issue