Skip to content

Commit

Permalink
Rename RunnerSet to RunnerReplicaSet
Browse files Browse the repository at this point in the history
To hand over the name `RunnerSet` to the new StatefulSet-based implementation of that being developed at actions#4
  • Loading branch information
mumoshu committed Mar 10, 2020
1 parent de85823 commit c19a1b3
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Now your can use your self-hosted runner. See the [official documentation](https

### RunnerDeployments

There's also `RunnerSet` and `RunnerDeployment` that corresponds to `ReplicaSet` and `Deployment` but for `Runner`.
There's also `RunnerReplicaSet` and `RunnerDeployment` that corresponds to `ReplicaSet` and `Deployment` but for `Runner`.

You usually need only `RunnerDeployment` rather than `RunnerSet` as the former is for managing the latter.
You usually need only `RunnerDeployment` rather than `RunnerReplicaSet` as the former is for managing the latter.

```yaml
# runnerdeployment.yaml
Expand Down
24 changes: 12 additions & 12 deletions api/v1alpha1/runner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ type RunnerList struct {
// +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
// +kubebuilder:printcolumn:JSONPath=".status.readyReplicas",name=Ready,type=number

// RunnerSet is the Schema for the runnersets API
type RunnerSet struct {
// RunnerReplicaSet is the Schema for the runnersets API
type RunnerReplicaSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RunnerSetSpec `json:"spec,omitempty"`
Status RunnerSetStatus `json:"status,omitempty"`
Spec RunnerReplicaSetSpec `json:"spec,omitempty"`
Status RunnerReplicaSetStatus `json:"status,omitempty"`
}

// RunnerSetSpec defines the desired state of RunnerSet
type RunnerSetSpec struct {
// RunnerReplicaSetSpec defines the desired state of RunnerReplicaSet
type RunnerReplicaSetSpec struct {
Replicas *int `json:"replicas"`

Template RunnerTemplate `json:"template"`
}

type RunnerSetStatus struct {
type RunnerReplicaSetStatus struct {
AvailableReplicas int `json:"availableReplicas"`
ReadyReplicas int `json:"readyReplicas"`
}
Expand All @@ -124,10 +124,10 @@ type RunnerTemplate struct {
// +kubebuilder:object:root=true

// RunnerList contains a list of Runner
type RunnerSetList struct {
type RunnerReplicaSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RunnerSet `json:"items"`
Items []RunnerReplicaSet `json:"items"`
}

// +kubebuilder:object:root=true
Expand All @@ -136,7 +136,7 @@ type RunnerSetList struct {
// +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
// +kubebuilder:printcolumn:JSONPath=".status.readyReplicas",name=Ready,type=number

// RunnerSet is the Schema for the runnersets API
// RunnerReplicaSet is the Schema for the runnersets API
type RunnerDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -145,7 +145,7 @@ type RunnerDeployment struct {
Status RunnerDeploymentStatus `json:"status,omitempty"`
}

// RunnerSetSpec defines the desired state of RunnerDeployment
// RunnerReplicaSetSpec defines the desired state of RunnerDeployment
type RunnerDeploymentSpec struct {
Replicas *int `json:"replicas"`

Expand All @@ -167,5 +167,5 @@ type RunnerDeploymentList struct {
}

func init() {
SchemeBuilder.Register(&Runner{}, &RunnerList{}, &RunnerSet{}, &RunnerSetList{}, &RunnerDeployment{}, &RunnerDeploymentList{})
SchemeBuilder.Register(&Runner{}, &RunnerList{}, &RunnerReplicaSet{}, &RunnerReplicaSetList{}, &RunnerDeployment{}, &RunnerDeploymentList{})
}
38 changes: 19 additions & 19 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
status: {}
validation:
openAPIV3Schema:
description: RunnerSet is the Schema for the runnersets API
description: RunnerReplicaSet is the Schema for the runnersets API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -44,7 +44,7 @@ spec:
metadata:
type: object
spec:
description: RunnerSetSpec defines the desired state of RunnerDeployment
description: RunnerReplicaSetSpec defines the desired state of RunnerDeployment
properties:
replicas:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
creationTimestamp: null
name: runnersets.actions.summerwind.dev
name: runnerreplicasets.actions.summerwind.dev
spec:
additionalPrinterColumns:
- JSONPath: .spec.replicas
Expand All @@ -20,16 +20,16 @@ spec:
type: number
group: actions.summerwind.dev
names:
kind: RunnerSet
listKind: RunnerSetList
plural: runnersets
singular: runnerset
kind: RunnerReplicaSet
listKind: RunnerReplicaSetList
plural: runnerreplicasets
singular: runnerreplicaset
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: RunnerSet is the Schema for the runnersets API
description: RunnerReplicaSet is the Schema for the runnersets API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -44,7 +44,7 @@ spec:
metadata:
type: object
spec:
description: RunnerSetSpec defines the desired state of RunnerSet
description: RunnerReplicaSetSpec defines the desired state of RunnerReplicaSet
properties:
replicas:
type: integer
Expand Down
40 changes: 20 additions & 20 deletions controllers/runnerdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ func (r *RunnerDeploymentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
return ctrl.Result{}, nil
}

var myRunnerSetList v1alpha1.RunnerSetList
if err := r.List(ctx, &myRunnerSetList, client.InNamespace(req.Namespace), client.MatchingFields{runnerSetOwnerKey: req.Name}); err != nil {
var myRunnerReplicaSetList v1alpha1.RunnerReplicaSetList
if err := r.List(ctx, &myRunnerReplicaSetList, client.InNamespace(req.Namespace), client.MatchingFields{runnerSetOwnerKey: req.Name}); err != nil {
return ctrl.Result{}, err
}

myRunnerSets := myRunnerSetList.Items
myRunnerReplicaSets := myRunnerReplicaSetList.Items

sort.Slice(myRunnerSets, func(i, j int) bool {
return myRunnerSets[i].GetCreationTimestamp().After(myRunnerSets[j].GetCreationTimestamp().Time)
sort.Slice(myRunnerReplicaSets, func(i, j int) bool {
return myRunnerReplicaSets[i].GetCreationTimestamp().After(myRunnerReplicaSets[j].GetCreationTimestamp().Time)
})

var newestSet *v1alpha1.RunnerSet
var newestSet *v1alpha1.RunnerReplicaSet

var oldSets []v1alpha1.RunnerSet
var oldSets []v1alpha1.RunnerReplicaSet

if len(myRunnerSets) > 0 {
newestSet = &myRunnerSets[0]
if len(myRunnerReplicaSets) > 0 {
newestSet = &myRunnerReplicaSets[0]
}

if len(myRunnerSets) > 1 {
oldSets = myRunnerSets[1:]
if len(myRunnerReplicaSets) > 1 {
oldSets = myRunnerReplicaSets[1:]
}

desiredRS, err := r.newRunnerSet(rd)
desiredRS, err := r.newRunnerReplicaSet(rd)
if err != nil {
log.Error(err, "Could not create runnerset")

Expand Down Expand Up @@ -153,14 +153,14 @@ func (r *RunnerDeploymentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
return ctrl.Result{}, err
}

r.Recorder.Event(&rd, corev1.EventTypeNormal, "RunnerSetDeleted", fmt.Sprintf("Deleted runnerset '%s'", rs.Name))
r.Recorder.Event(&rd, corev1.EventTypeNormal, "RunnerReplicaSetDeleted", fmt.Sprintf("Deleted runnerset '%s'", rs.Name))
log.Info("Deleted runnerset", "runnerdeployment", rd.ObjectMeta.Name, "runnerset", rs.Name)
}

return ctrl.Result{}, nil
}

func getTemplateHash(rs *v1alpha1.RunnerSet) (string, bool) {
func getTemplateHash(rs *v1alpha1.RunnerReplicaSet) (string, bool) {
hash, ok := rs.Labels[LabelKeyRunnerTemplateHash]

return hash, ok
Expand Down Expand Up @@ -206,22 +206,22 @@ func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map
return newLabels
}

func (r *RunnerDeploymentReconciler) newRunnerSet(rd v1alpha1.RunnerDeployment) (v1alpha1.RunnerSet, error) {
func (r *RunnerDeploymentReconciler) newRunnerReplicaSet(rd v1alpha1.RunnerDeployment) (v1alpha1.RunnerReplicaSet, error) {
newRSTemplate := *rd.Spec.Template.DeepCopy()
templateHash := ComputeHash(&newRSTemplate)
// Add template hash label to selector.
labels := CloneAndAddLabel(rd.Spec.Template.Labels, LabelKeyRunnerTemplateHash, templateHash)

newRSTemplate.Labels = labels

rs := v1alpha1.RunnerSet{
rs := v1alpha1.RunnerReplicaSet{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
GenerateName: rd.ObjectMeta.Name,
Namespace: rd.ObjectMeta.Namespace,
Labels: labels,
},
Spec: v1alpha1.RunnerSetSpec{
Spec: v1alpha1.RunnerReplicaSetSpec{
Replicas: rd.Spec.Replicas,
Template: newRSTemplate,
},
Expand All @@ -237,8 +237,8 @@ func (r *RunnerDeploymentReconciler) newRunnerSet(rd v1alpha1.RunnerDeployment)
func (r *RunnerDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Recorder = mgr.GetEventRecorderFor("runnerdeployment-controller")

if err := mgr.GetFieldIndexer().IndexField(&v1alpha1.RunnerSet{}, runnerSetOwnerKey, func(rawObj runtime.Object) []string {
runnerSet := rawObj.(*v1alpha1.RunnerSet)
if err := mgr.GetFieldIndexer().IndexField(&v1alpha1.RunnerReplicaSet{}, runnerSetOwnerKey, func(rawObj runtime.Object) []string {
runnerSet := rawObj.(*v1alpha1.RunnerReplicaSet)
owner := metav1.GetControllerOf(runnerSet)
if owner == nil {
return nil
Expand All @@ -255,6 +255,6 @@ func (r *RunnerDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {

return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.RunnerDeployment{}).
Owns(&v1alpha1.RunnerSet{}).
Owns(&v1alpha1.RunnerReplicaSet{}).
Complete(r)
}
10 changes: 5 additions & 5 deletions controllers/runnerdeployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Context("Inside of a new namespace", func() {

Describe("when no existing resources exist", func() {

It("should create a new RunnerSet resource from the specified template, add a another RunnerSet on template modification, and eventually removes old runnersets", func() {
It("should create a new RunnerReplicaSet resource from the specified template, add a another RunnerReplicaSet on template modification, and eventually removes old runnersets", func() {
name := "example-runnerdeploy"

{
Expand All @@ -97,9 +97,9 @@ var _ = Context("Inside of a new namespace", func() {

err := k8sClient.Create(ctx, rs)

Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerSet resource")
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerReplicaSet resource")

runnerSets := actionsv1alpha1.RunnerSetList{Items: []actionsv1alpha1.RunnerSet{}}
runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}}

Eventually(
func() int {
Expand Down Expand Up @@ -138,15 +138,15 @@ var _ = Context("Inside of a new namespace", func() {

err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rd)

Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerSet resource")
Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerReplicaSet resource")

rd.Spec.Replicas = intPtr(2)

return k8sClient.Update(ctx, &rd)
},
time.Second*1, time.Millisecond*500).Should(BeNil())

runnerSets := actionsv1alpha1.RunnerSetList{Items: []actionsv1alpha1.RunnerSet{}}
runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}}

Eventually(
func() int {
Expand Down
Loading

0 comments on commit c19a1b3

Please sign in to comment.