Merge pull request #6 from mumoshu/rename-runnerset
Rename RunnerSet to RunnerReplicaSet
This commit is contained in:
		
						commit
						ce3011fe1b
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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"` | ||||
| } | ||||
|  | @ -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
 | ||||
|  | @ -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"` | ||||
|  | @ -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"` | ||||
| 
 | ||||
|  | @ -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{}) | ||||
| } | ||||
|  |  | |||
|  | @ -180,7 +180,7 @@ func (in *RunnerList) DeepCopyObject() runtime.Object { | |||
| } | ||||
| 
 | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 | ||||
| func (in *RunnerSet) DeepCopyInto(out *RunnerSet) { | ||||
| func (in *RunnerReplicaSet) DeepCopyInto(out *RunnerReplicaSet) { | ||||
| 	*out = *in | ||||
| 	out.TypeMeta = in.TypeMeta | ||||
| 	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) | ||||
|  | @ -188,18 +188,18 @@ func (in *RunnerSet) DeepCopyInto(out *RunnerSet) { | |||
| 	out.Status = in.Status | ||||
| } | ||||
| 
 | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSet.
 | ||||
| func (in *RunnerSet) DeepCopy() *RunnerSet { | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSet.
 | ||||
| func (in *RunnerReplicaSet) DeepCopy() *RunnerReplicaSet { | ||||
| 	if in == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	out := new(RunnerSet) | ||||
| 	out := new(RunnerReplicaSet) | ||||
| 	in.DeepCopyInto(out) | ||||
| 	return out | ||||
| } | ||||
| 
 | ||||
| // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
 | ||||
| func (in *RunnerSet) DeepCopyObject() runtime.Object { | ||||
| func (in *RunnerReplicaSet) DeepCopyObject() runtime.Object { | ||||
| 	if c := in.DeepCopy(); c != nil { | ||||
| 		return c | ||||
| 	} | ||||
|  | @ -207,31 +207,31 @@ func (in *RunnerSet) DeepCopyObject() runtime.Object { | |||
| } | ||||
| 
 | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 | ||||
| func (in *RunnerSetList) DeepCopyInto(out *RunnerSetList) { | ||||
| func (in *RunnerReplicaSetList) DeepCopyInto(out *RunnerReplicaSetList) { | ||||
| 	*out = *in | ||||
| 	out.TypeMeta = in.TypeMeta | ||||
| 	in.ListMeta.DeepCopyInto(&out.ListMeta) | ||||
| 	if in.Items != nil { | ||||
| 		in, out := &in.Items, &out.Items | ||||
| 		*out = make([]RunnerSet, len(*in)) | ||||
| 		*out = make([]RunnerReplicaSet, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetList.
 | ||||
| func (in *RunnerSetList) DeepCopy() *RunnerSetList { | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetList.
 | ||||
| func (in *RunnerReplicaSetList) DeepCopy() *RunnerReplicaSetList { | ||||
| 	if in == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	out := new(RunnerSetList) | ||||
| 	out := new(RunnerReplicaSetList) | ||||
| 	in.DeepCopyInto(out) | ||||
| 	return out | ||||
| } | ||||
| 
 | ||||
| // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
 | ||||
| func (in *RunnerSetList) DeepCopyObject() runtime.Object { | ||||
| func (in *RunnerReplicaSetList) DeepCopyObject() runtime.Object { | ||||
| 	if c := in.DeepCopy(); c != nil { | ||||
| 		return c | ||||
| 	} | ||||
|  | @ -239,7 +239,7 @@ func (in *RunnerSetList) DeepCopyObject() runtime.Object { | |||
| } | ||||
| 
 | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 | ||||
| func (in *RunnerSetSpec) DeepCopyInto(out *RunnerSetSpec) { | ||||
| func (in *RunnerReplicaSetSpec) DeepCopyInto(out *RunnerReplicaSetSpec) { | ||||
| 	*out = *in | ||||
| 	if in.Replicas != nil { | ||||
| 		in, out := &in.Replicas, &out.Replicas | ||||
|  | @ -249,27 +249,27 @@ func (in *RunnerSetSpec) DeepCopyInto(out *RunnerSetSpec) { | |||
| 	in.Template.DeepCopyInto(&out.Template) | ||||
| } | ||||
| 
 | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetSpec.
 | ||||
| func (in *RunnerSetSpec) DeepCopy() *RunnerSetSpec { | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetSpec.
 | ||||
| func (in *RunnerReplicaSetSpec) DeepCopy() *RunnerReplicaSetSpec { | ||||
| 	if in == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	out := new(RunnerSetSpec) | ||||
| 	out := new(RunnerReplicaSetSpec) | ||||
| 	in.DeepCopyInto(out) | ||||
| 	return out | ||||
| } | ||||
| 
 | ||||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 | ||||
| func (in *RunnerSetStatus) DeepCopyInto(out *RunnerSetStatus) { | ||||
| func (in *RunnerReplicaSetStatus) DeepCopyInto(out *RunnerReplicaSetStatus) { | ||||
| 	*out = *in | ||||
| } | ||||
| 
 | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetStatus.
 | ||||
| func (in *RunnerSetStatus) DeepCopy() *RunnerSetStatus { | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetStatus.
 | ||||
| func (in *RunnerReplicaSetStatus) DeepCopy() *RunnerReplicaSetStatus { | ||||
| 	if in == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	out := new(RunnerSetStatus) | ||||
| 	out := new(RunnerReplicaSetStatus) | ||||
| 	in.DeepCopyInto(out) | ||||
| 	return out | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  | @ -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 | ||||
|  | @ -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 | ||||
|  | @ -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") | ||||
| 
 | ||||
|  | @ -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 | ||||
|  | @ -206,7 +206,7 @@ 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.
 | ||||
|  | @ -214,14 +214,14 @@ func (r *RunnerDeploymentReconciler) newRunnerSet(rd v1alpha1.RunnerDeployment) | |||
| 
 | ||||
| 	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, | ||||
| 		}, | ||||
|  | @ -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 | ||||
|  | @ -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) | ||||
| } | ||||
|  |  | |||
|  | @ -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" | ||||
| 
 | ||||
| 			{ | ||||
|  | @ -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 { | ||||
|  | @ -138,7 +138,7 @@ 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) | ||||
| 
 | ||||
|  | @ -146,7 +146,7 @@ var _ = Context("Inside of a new namespace", func() { | |||
| 				}, | ||||
| 					time.Second*1, time.Millisecond*500).Should(BeNil()) | ||||
| 
 | ||||
| 				runnerSets := actionsv1alpha1.RunnerSetList{Items: []actionsv1alpha1.RunnerSet{}} | ||||
| 				runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}} | ||||
| 
 | ||||
| 				Eventually( | ||||
| 					func() int { | ||||
|  |  | |||
|  | @ -32,8 +32,8 @@ import ( | |||
| 	"github.com/summerwind/actions-runner-controller/api/v1alpha1" | ||||
| ) | ||||
| 
 | ||||
| // RunnerSetReconciler reconciles a Runner object
 | ||||
| type RunnerSetReconciler struct { | ||||
| // RunnerReplicaSetReconciler reconciles a Runner object
 | ||||
| type RunnerReplicaSetReconciler struct { | ||||
| 	client.Client | ||||
| 	Log      logr.Logger | ||||
| 	Recorder record.EventRecorder | ||||
|  | @ -45,11 +45,11 @@ type RunnerSetReconciler struct { | |||
| // +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runners,verbs=get;list;watch;create;update;patch;delete
 | ||||
| // +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runners/status,verbs=get;update;patch
 | ||||
| 
 | ||||
| func (r *RunnerSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | ||||
| func (r *RunnerReplicaSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | ||||
| 	ctx := context.Background() | ||||
| 	log := r.Log.WithValues("runner", req.NamespacedName) | ||||
| 
 | ||||
| 	var rs v1alpha1.RunnerSet | ||||
| 	var rs v1alpha1.RunnerReplicaSet | ||||
| 	if err := r.Get(ctx, req.NamespacedName, &rs); err != nil { | ||||
| 		return ctrl.Result{}, client.IgnoreNotFound(err) | ||||
| 	} | ||||
|  | @ -137,7 +137,7 @@ func (r *RunnerSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | |||
| 	return ctrl.Result{}, nil | ||||
| } | ||||
| 
 | ||||
| func (r *RunnerSetReconciler) newRunner(rs v1alpha1.RunnerSet) (v1alpha1.Runner, error) { | ||||
| func (r *RunnerReplicaSetReconciler) newRunner(rs v1alpha1.RunnerReplicaSet) (v1alpha1.Runner, error) { | ||||
| 	objectMeta := rs.Spec.Template.ObjectMeta.DeepCopy() | ||||
| 
 | ||||
| 	objectMeta.GenerateName = rs.ObjectMeta.Name | ||||
|  | @ -156,11 +156,11 @@ func (r *RunnerSetReconciler) newRunner(rs v1alpha1.RunnerSet) (v1alpha1.Runner, | |||
| 	return runner, nil | ||||
| } | ||||
| 
 | ||||
| func (r *RunnerSetReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||||
| func (r *RunnerReplicaSetReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||||
| 	r.Recorder = mgr.GetEventRecorderFor("runnerset-controller") | ||||
| 
 | ||||
| 	return ctrl.NewControllerManagedBy(mgr). | ||||
| 		For(&v1alpha1.RunnerSet{}). | ||||
| 		For(&v1alpha1.RunnerReplicaSet{}). | ||||
| 		Owns(&v1alpha1.Runner{}). | ||||
| 		Complete(r) | ||||
| } | ||||
|  | @ -22,7 +22,7 @@ import ( | |||
| // This includes:
 | ||||
| // * creating a Namespace to be used during the test
 | ||||
| // * starting the 'RunnerReconciler'
 | ||||
| // * stopping the 'RunnerSetReconciler" after the test ends
 | ||||
| // * stopping the 'RunnerReplicaSetReconciler" after the test ends
 | ||||
| // Call this function at the start of each of your tests.
 | ||||
| func SetupTest(ctx context.Context) *corev1.Namespace { | ||||
| 	var stopCh chan struct{} | ||||
|  | @ -40,7 +40,7 @@ func SetupTest(ctx context.Context) *corev1.Namespace { | |||
| 		mgr, err := ctrl.NewManager(cfg, ctrl.Options{}) | ||||
| 		Expect(err).NotTo(HaveOccurred(), "failed to create manager") | ||||
| 
 | ||||
| 		controller := &RunnerSetReconciler{ | ||||
| 		controller := &RunnerReplicaSetReconciler{ | ||||
| 			Client:   mgr.GetClient(), | ||||
| 			Scheme:   scheme.Scheme, | ||||
| 			Log:      logf.Log, | ||||
|  | @ -91,12 +91,12 @@ var _ = Context("Inside of a new namespace", func() { | |||
| 			name := "example-runnerset" | ||||
| 
 | ||||
| 			{ | ||||
| 				rs := &actionsv1alpha1.RunnerSet{ | ||||
| 				rs := &actionsv1alpha1.RunnerReplicaSet{ | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Name:      name, | ||||
| 						Namespace: ns.Name, | ||||
| 					}, | ||||
| 					Spec: actionsv1alpha1.RunnerSetSpec{ | ||||
| 					Spec: actionsv1alpha1.RunnerReplicaSetSpec{ | ||||
| 						Replicas: intPtr(1), | ||||
| 						Template: actionsv1alpha1.RunnerTemplate{ | ||||
| 							Spec: actionsv1alpha1.RunnerSpec{ | ||||
|  | @ -112,7 +112,7 @@ 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") | ||||
| 
 | ||||
| 				runners := actionsv1alpha1.RunnerList{Items: []actionsv1alpha1.Runner{}} | ||||
| 
 | ||||
|  | @ -133,11 +133,11 @@ var _ = Context("Inside of a new namespace", func() { | |||
| 				// made by the controller to update .Status.AvailableReplicas and .Status.ReadyReplicas
 | ||||
| 				//   Operation cannot be fulfilled on runnersets.actions.summerwind.dev "example-runnerset": the object has been modified; please apply your changes to the latest version and try again
 | ||||
| 				Eventually(func() error { | ||||
| 					var rs actionsv1alpha1.RunnerSet | ||||
| 					var rs actionsv1alpha1.RunnerReplicaSet | ||||
| 
 | ||||
| 					err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs) | ||||
| 
 | ||||
| 					Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerSet resource") | ||||
| 					Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerReplicaSet resource") | ||||
| 
 | ||||
| 					rs.Spec.Replicas = intPtr(2) | ||||
| 
 | ||||
|  | @ -164,11 +164,11 @@ var _ = Context("Inside of a new namespace", func() { | |||
| 				// made by the controller to update .Status.AvailableReplicas and .Status.ReadyReplicas
 | ||||
| 				//   Operation cannot be fulfilled on runnersets.actions.summerwind.dev "example-runnerset": the object has been modified; please apply your changes to the latest version and try again
 | ||||
| 				Eventually(func() error { | ||||
| 					var rs actionsv1alpha1.RunnerSet | ||||
| 					var rs actionsv1alpha1.RunnerReplicaSet | ||||
| 
 | ||||
| 					err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs) | ||||
| 
 | ||||
| 					Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerSet resource") | ||||
| 					Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerReplicaSet resource") | ||||
| 
 | ||||
| 					rs.Spec.Replicas = intPtr(0) | ||||
| 
 | ||||
							
								
								
									
										6
									
								
								main.go
								
								
								
								
							
							
						
						
									
										6
									
								
								main.go
								
								
								
								
							|  | @ -111,14 +111,14 @@ func main() { | |||
| 		os.Exit(1) | ||||
| 	} | ||||
| 
 | ||||
| 	runnerSetReconciler := &controllers.RunnerSetReconciler{ | ||||
| 	runnerSetReconciler := &controllers.RunnerReplicaSetReconciler{ | ||||
| 		Client: mgr.GetClient(), | ||||
| 		Log:    ctrl.Log.WithName("controllers").WithName("RunnerSet"), | ||||
| 		Log:    ctrl.Log.WithName("controllers").WithName("RunnerReplicaSet"), | ||||
| 		Scheme: mgr.GetScheme(), | ||||
| 	} | ||||
| 
 | ||||
| 	if err = runnerSetReconciler.SetupWithManager(mgr); err != nil { | ||||
| 		setupLog.Error(err, "unable to create controller", "controller", "RunnerSet") | ||||
| 		setupLog.Error(err, "unable to create controller", "controller", "RunnerReplicaSet") | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue