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 | ### 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 | ```yaml | ||||||
| # runnerdeployment.yaml | # runnerdeployment.yaml | ||||||
|  |  | ||||||
|  | @ -94,23 +94,23 @@ type RunnerList struct { | ||||||
| // +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
 | // +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
 | ||||||
| // +kubebuilder:printcolumn:JSONPath=".status.readyReplicas",name=Ready,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 RunnerSet struct { | type RunnerReplicaSet struct { | ||||||
| 	metav1.TypeMeta   `json:",inline"` | 	metav1.TypeMeta   `json:",inline"` | ||||||
| 	metav1.ObjectMeta `json:"metadata,omitempty"` | 	metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
| 
 | 
 | ||||||
| 	Spec   RunnerSetSpec   `json:"spec,omitempty"` | 	Spec   RunnerReplicaSetSpec   `json:"spec,omitempty"` | ||||||
| 	Status RunnerSetStatus `json:"status,omitempty"` | 	Status RunnerReplicaSetStatus `json:"status,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // RunnerSetSpec defines the desired state of RunnerSet
 | // RunnerReplicaSetSpec defines the desired state of RunnerReplicaSet
 | ||||||
| type RunnerSetSpec struct { | type RunnerReplicaSetSpec struct { | ||||||
| 	Replicas *int `json:"replicas"` | 	Replicas *int `json:"replicas"` | ||||||
| 
 | 
 | ||||||
| 	Template RunnerTemplate `json:"template"` | 	Template RunnerTemplate `json:"template"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type RunnerSetStatus struct { | type RunnerReplicaSetStatus struct { | ||||||
| 	AvailableReplicas int `json:"availableReplicas"` | 	AvailableReplicas int `json:"availableReplicas"` | ||||||
| 	ReadyReplicas     int `json:"readyReplicas"` | 	ReadyReplicas     int `json:"readyReplicas"` | ||||||
| } | } | ||||||
|  | @ -124,10 +124,10 @@ type RunnerTemplate struct { | ||||||
| // +kubebuilder:object:root=true
 | // +kubebuilder:object:root=true
 | ||||||
| 
 | 
 | ||||||
| // RunnerList contains a list of Runner
 | // RunnerList contains a list of Runner
 | ||||||
| type RunnerSetList struct { | type RunnerReplicaSetList struct { | ||||||
| 	metav1.TypeMeta `json:",inline"` | 	metav1.TypeMeta `json:",inline"` | ||||||
| 	metav1.ListMeta `json:"metadata,omitempty"` | 	metav1.ListMeta `json:"metadata,omitempty"` | ||||||
| 	Items           []RunnerSet `json:"items"` | 	Items           []RunnerReplicaSet `json:"items"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // +kubebuilder:object:root=true
 | // +kubebuilder:object:root=true
 | ||||||
|  | @ -136,7 +136,7 @@ type RunnerSetList struct { | ||||||
| // +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
 | // +kubebuilder:printcolumn:JSONPath=".status.availableReplicas",name=Current,type=number
 | ||||||
| // +kubebuilder:printcolumn:JSONPath=".status.readyReplicas",name=Ready,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 { | type RunnerDeployment struct { | ||||||
| 	metav1.TypeMeta   `json:",inline"` | 	metav1.TypeMeta   `json:",inline"` | ||||||
| 	metav1.ObjectMeta `json:"metadata,omitempty"` | 	metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
|  | @ -145,7 +145,7 @@ type RunnerDeployment struct { | ||||||
| 	Status RunnerDeploymentStatus `json:"status,omitempty"` | 	Status RunnerDeploymentStatus `json:"status,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // RunnerSetSpec defines the desired state of RunnerDeployment
 | // RunnerReplicaSetSpec defines the desired state of RunnerDeployment
 | ||||||
| type RunnerDeploymentSpec struct { | type RunnerDeploymentSpec struct { | ||||||
| 	Replicas *int `json:"replicas"` | 	Replicas *int `json:"replicas"` | ||||||
| 
 | 
 | ||||||
|  | @ -167,5 +167,5 @@ type RunnerDeploymentList struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func init() { | 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.
 | // 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 = *in | ||||||
| 	out.TypeMeta = in.TypeMeta | 	out.TypeMeta = in.TypeMeta | ||||||
| 	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) | 	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) | ||||||
|  | @ -188,18 +188,18 @@ func (in *RunnerSet) DeepCopyInto(out *RunnerSet) { | ||||||
| 	out.Status = in.Status | 	out.Status = in.Status | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSet.
 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSet.
 | ||||||
| func (in *RunnerSet) DeepCopy() *RunnerSet { | func (in *RunnerReplicaSet) DeepCopy() *RunnerReplicaSet { | ||||||
| 	if in == nil { | 	if in == nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	out := new(RunnerSet) | 	out := new(RunnerReplicaSet) | ||||||
| 	in.DeepCopyInto(out) | 	in.DeepCopyInto(out) | ||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
 | // 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 { | 	if c := in.DeepCopy(); c != nil { | ||||||
| 		return c | 		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.
 | // 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 = *in | ||||||
| 	out.TypeMeta = in.TypeMeta | 	out.TypeMeta = in.TypeMeta | ||||||
| 	in.ListMeta.DeepCopyInto(&out.ListMeta) | 	in.ListMeta.DeepCopyInto(&out.ListMeta) | ||||||
| 	if in.Items != nil { | 	if in.Items != nil { | ||||||
| 		in, out := &in.Items, &out.Items | 		in, out := &in.Items, &out.Items | ||||||
| 		*out = make([]RunnerSet, len(*in)) | 		*out = make([]RunnerReplicaSet, len(*in)) | ||||||
| 		for i := range *in { | 		for i := range *in { | ||||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetList.
 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetList.
 | ||||||
| func (in *RunnerSetList) DeepCopy() *RunnerSetList { | func (in *RunnerReplicaSetList) DeepCopy() *RunnerReplicaSetList { | ||||||
| 	if in == nil { | 	if in == nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	out := new(RunnerSetList) | 	out := new(RunnerReplicaSetList) | ||||||
| 	in.DeepCopyInto(out) | 	in.DeepCopyInto(out) | ||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
 | // 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 { | 	if c := in.DeepCopy(); c != nil { | ||||||
| 		return c | 		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.
 | // 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 | 	*out = *in | ||||||
| 	if in.Replicas != nil { | 	if in.Replicas != nil { | ||||||
| 		in, out := &in.Replicas, &out.Replicas | 		in, out := &in.Replicas, &out.Replicas | ||||||
|  | @ -249,27 +249,27 @@ func (in *RunnerSetSpec) DeepCopyInto(out *RunnerSetSpec) { | ||||||
| 	in.Template.DeepCopyInto(&out.Template) | 	in.Template.DeepCopyInto(&out.Template) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetSpec.
 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetSpec.
 | ||||||
| func (in *RunnerSetSpec) DeepCopy() *RunnerSetSpec { | func (in *RunnerReplicaSetSpec) DeepCopy() *RunnerReplicaSetSpec { | ||||||
| 	if in == nil { | 	if in == nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	out := new(RunnerSetSpec) | 	out := new(RunnerReplicaSetSpec) | ||||||
| 	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.
 | // 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 | 	*out = *in | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSetStatus.
 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerReplicaSetStatus.
 | ||||||
| func (in *RunnerSetStatus) DeepCopy() *RunnerSetStatus { | func (in *RunnerReplicaSetStatus) DeepCopy() *RunnerReplicaSetStatus { | ||||||
| 	if in == nil { | 	if in == nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	out := new(RunnerSetStatus) | 	out := new(RunnerReplicaSetStatus) | ||||||
| 	in.DeepCopyInto(out) | 	in.DeepCopyInto(out) | ||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ spec: | ||||||
|     status: {} |     status: {} | ||||||
|   validation: |   validation: | ||||||
|     openAPIV3Schema: |     openAPIV3Schema: | ||||||
|       description: RunnerSet is the Schema for the runnersets API |       description: RunnerReplicaSet is the Schema for the runnersets API | ||||||
|       properties: |       properties: | ||||||
|         apiVersion: |         apiVersion: | ||||||
|           description: 'APIVersion defines the versioned schema of this representation |           description: 'APIVersion defines the versioned schema of this representation | ||||||
|  | @ -44,7 +44,7 @@ spec: | ||||||
|         metadata: |         metadata: | ||||||
|           type: object |           type: object | ||||||
|         spec: |         spec: | ||||||
|           description: RunnerSetSpec defines the desired state of RunnerDeployment |           description: RunnerReplicaSetSpec defines the desired state of RunnerDeployment | ||||||
|           properties: |           properties: | ||||||
|             replicas: |             replicas: | ||||||
|               type: integer |               type: integer | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ metadata: | ||||||
|   annotations: |   annotations: | ||||||
|     controller-gen.kubebuilder.io/version: v0.2.4 |     controller-gen.kubebuilder.io/version: v0.2.4 | ||||||
|   creationTimestamp: null |   creationTimestamp: null | ||||||
|   name: runnersets.actions.summerwind.dev |   name: runnerreplicasets.actions.summerwind.dev | ||||||
| spec: | spec: | ||||||
|   additionalPrinterColumns: |   additionalPrinterColumns: | ||||||
|   - JSONPath: .spec.replicas |   - JSONPath: .spec.replicas | ||||||
|  | @ -20,16 +20,16 @@ spec: | ||||||
|     type: number |     type: number | ||||||
|   group: actions.summerwind.dev |   group: actions.summerwind.dev | ||||||
|   names: |   names: | ||||||
|     kind: RunnerSet |     kind: RunnerReplicaSet | ||||||
|     listKind: RunnerSetList |     listKind: RunnerReplicaSetList | ||||||
|     plural: runnersets |     plural: runnerreplicasets | ||||||
|     singular: runnerset |     singular: runnerreplicaset | ||||||
|   scope: Namespaced |   scope: Namespaced | ||||||
|   subresources: |   subresources: | ||||||
|     status: {} |     status: {} | ||||||
|   validation: |   validation: | ||||||
|     openAPIV3Schema: |     openAPIV3Schema: | ||||||
|       description: RunnerSet is the Schema for the runnersets API |       description: RunnerReplicaSet is the Schema for the runnersets API | ||||||
|       properties: |       properties: | ||||||
|         apiVersion: |         apiVersion: | ||||||
|           description: 'APIVersion defines the versioned schema of this representation |           description: 'APIVersion defines the versioned schema of this representation | ||||||
|  | @ -44,7 +44,7 @@ spec: | ||||||
|         metadata: |         metadata: | ||||||
|           type: object |           type: object | ||||||
|         spec: |         spec: | ||||||
|           description: RunnerSetSpec defines the desired state of RunnerSet |           description: RunnerReplicaSetSpec defines the desired state of RunnerReplicaSet | ||||||
|           properties: |           properties: | ||||||
|             replicas: |             replicas: | ||||||
|               type: integer |               type: integer | ||||||
|  | @ -67,30 +67,30 @@ func (r *RunnerDeploymentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e | ||||||
| 		return ctrl.Result{}, nil | 		return ctrl.Result{}, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var myRunnerSetList v1alpha1.RunnerSetList | 	var myRunnerReplicaSetList v1alpha1.RunnerReplicaSetList | ||||||
| 	if err := r.List(ctx, &myRunnerSetList, client.InNamespace(req.Namespace), client.MatchingFields{runnerSetOwnerKey: req.Name}); err != nil { | 	if err := r.List(ctx, &myRunnerReplicaSetList, client.InNamespace(req.Namespace), client.MatchingFields{runnerSetOwnerKey: req.Name}); err != nil { | ||||||
| 		return ctrl.Result{}, err | 		return ctrl.Result{}, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	myRunnerSets := myRunnerSetList.Items | 	myRunnerReplicaSets := myRunnerReplicaSetList.Items | ||||||
| 
 | 
 | ||||||
| 	sort.Slice(myRunnerSets, func(i, j int) bool { | 	sort.Slice(myRunnerReplicaSets, func(i, j int) bool { | ||||||
| 		return myRunnerSets[i].GetCreationTimestamp().After(myRunnerSets[j].GetCreationTimestamp().Time) | 		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 { | 	if len(myRunnerReplicaSets) > 0 { | ||||||
| 		newestSet = &myRunnerSets[0] | 		newestSet = &myRunnerReplicaSets[0] | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if len(myRunnerSets) > 1 { | 	if len(myRunnerReplicaSets) > 1 { | ||||||
| 		oldSets = myRunnerSets[1:] | 		oldSets = myRunnerReplicaSets[1:] | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	desiredRS, err := r.newRunnerSet(rd) | 	desiredRS, err := r.newRunnerReplicaSet(rd) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Error(err, "Could not create runnerset") | 		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 | 			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) | 		log.Info("Deleted runnerset", "runnerdeployment", rd.ObjectMeta.Name, "runnerset", rs.Name) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return ctrl.Result{}, nil | 	return ctrl.Result{}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getTemplateHash(rs *v1alpha1.RunnerSet) (string, bool) { | func getTemplateHash(rs *v1alpha1.RunnerReplicaSet) (string, bool) { | ||||||
| 	hash, ok := rs.Labels[LabelKeyRunnerTemplateHash] | 	hash, ok := rs.Labels[LabelKeyRunnerTemplateHash] | ||||||
| 
 | 
 | ||||||
| 	return hash, ok | 	return hash, ok | ||||||
|  | @ -206,7 +206,7 @@ func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map | ||||||
| 	return newLabels | 	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() | 	newRSTemplate := *rd.Spec.Template.DeepCopy() | ||||||
| 	templateHash := ComputeHash(&newRSTemplate) | 	templateHash := ComputeHash(&newRSTemplate) | ||||||
| 	// Add template hash label to selector.
 | 	// Add template hash label to selector.
 | ||||||
|  | @ -214,14 +214,14 @@ func (r *RunnerDeploymentReconciler) newRunnerSet(rd v1alpha1.RunnerDeployment) | ||||||
| 
 | 
 | ||||||
| 	newRSTemplate.Labels = labels | 	newRSTemplate.Labels = labels | ||||||
| 
 | 
 | ||||||
| 	rs := v1alpha1.RunnerSet{ | 	rs := v1alpha1.RunnerReplicaSet{ | ||||||
| 		TypeMeta: metav1.TypeMeta{}, | 		TypeMeta: metav1.TypeMeta{}, | ||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			GenerateName: rd.ObjectMeta.Name, | 			GenerateName: rd.ObjectMeta.Name, | ||||||
| 			Namespace:    rd.ObjectMeta.Namespace, | 			Namespace:    rd.ObjectMeta.Namespace, | ||||||
| 			Labels:       labels, | 			Labels:       labels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: v1alpha1.RunnerSetSpec{ | 		Spec: v1alpha1.RunnerReplicaSetSpec{ | ||||||
| 			Replicas: rd.Spec.Replicas, | 			Replicas: rd.Spec.Replicas, | ||||||
| 			Template: newRSTemplate, | 			Template: newRSTemplate, | ||||||
| 		}, | 		}, | ||||||
|  | @ -237,8 +237,8 @@ func (r *RunnerDeploymentReconciler) newRunnerSet(rd v1alpha1.RunnerDeployment) | ||||||
| func (r *RunnerDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { | func (r *RunnerDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||||||
| 	r.Recorder = mgr.GetEventRecorderFor("runnerdeployment-controller") | 	r.Recorder = mgr.GetEventRecorderFor("runnerdeployment-controller") | ||||||
| 
 | 
 | ||||||
| 	if err := mgr.GetFieldIndexer().IndexField(&v1alpha1.RunnerSet{}, runnerSetOwnerKey, func(rawObj runtime.Object) []string { | 	if err := mgr.GetFieldIndexer().IndexField(&v1alpha1.RunnerReplicaSet{}, runnerSetOwnerKey, func(rawObj runtime.Object) []string { | ||||||
| 		runnerSet := rawObj.(*v1alpha1.RunnerSet) | 		runnerSet := rawObj.(*v1alpha1.RunnerReplicaSet) | ||||||
| 		owner := metav1.GetControllerOf(runnerSet) | 		owner := metav1.GetControllerOf(runnerSet) | ||||||
| 		if owner == nil { | 		if owner == nil { | ||||||
| 			return nil | 			return nil | ||||||
|  | @ -255,6 +255,6 @@ func (r *RunnerDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||||||
| 
 | 
 | ||||||
| 	return ctrl.NewControllerManagedBy(mgr). | 	return ctrl.NewControllerManagedBy(mgr). | ||||||
| 		For(&v1alpha1.RunnerDeployment{}). | 		For(&v1alpha1.RunnerDeployment{}). | ||||||
| 		Owns(&v1alpha1.RunnerSet{}). | 		Owns(&v1alpha1.RunnerReplicaSet{}). | ||||||
| 		Complete(r) | 		Complete(r) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ var _ = Context("Inside of a new namespace", func() { | ||||||
| 
 | 
 | ||||||
| 	Describe("when no existing resources exist", 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" | 			name := "example-runnerdeploy" | ||||||
| 
 | 
 | ||||||
| 			{ | 			{ | ||||||
|  | @ -97,9 +97,9 @@ var _ = Context("Inside of a new namespace", func() { | ||||||
| 
 | 
 | ||||||
| 				err := k8sClient.Create(ctx, rs) | 				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( | 				Eventually( | ||||||
| 					func() int { | 					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) | 					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) | 					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()) | 					time.Second*1, time.Millisecond*500).Should(BeNil()) | ||||||
| 
 | 
 | ||||||
| 				runnerSets := actionsv1alpha1.RunnerSetList{Items: []actionsv1alpha1.RunnerSet{}} | 				runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}} | ||||||
| 
 | 
 | ||||||
| 				Eventually( | 				Eventually( | ||||||
| 					func() int { | 					func() int { | ||||||
|  |  | ||||||
|  | @ -32,8 +32,8 @@ import ( | ||||||
| 	"github.com/summerwind/actions-runner-controller/api/v1alpha1" | 	"github.com/summerwind/actions-runner-controller/api/v1alpha1" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // RunnerSetReconciler reconciles a Runner object
 | // RunnerReplicaSetReconciler reconciles a Runner object
 | ||||||
| type RunnerSetReconciler struct { | type RunnerReplicaSetReconciler struct { | ||||||
| 	client.Client | 	client.Client | ||||||
| 	Log      logr.Logger | 	Log      logr.Logger | ||||||
| 	Recorder record.EventRecorder | 	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,verbs=get;list;watch;create;update;patch;delete
 | ||||||
| // +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runners/status,verbs=get;update;patch
 | // +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() | 	ctx := context.Background() | ||||||
| 	log := r.Log.WithValues("runner", req.NamespacedName) | 	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 { | 	if err := r.Get(ctx, req.NamespacedName, &rs); err != nil { | ||||||
| 		return ctrl.Result{}, client.IgnoreNotFound(err) | 		return ctrl.Result{}, client.IgnoreNotFound(err) | ||||||
| 	} | 	} | ||||||
|  | @ -137,7 +137,7 @@ func (r *RunnerSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | ||||||
| 	return ctrl.Result{}, nil | 	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 := rs.Spec.Template.ObjectMeta.DeepCopy() | ||||||
| 
 | 
 | ||||||
| 	objectMeta.GenerateName = rs.ObjectMeta.Name | 	objectMeta.GenerateName = rs.ObjectMeta.Name | ||||||
|  | @ -156,11 +156,11 @@ func (r *RunnerSetReconciler) newRunner(rs v1alpha1.RunnerSet) (v1alpha1.Runner, | ||||||
| 	return runner, nil | 	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") | 	r.Recorder = mgr.GetEventRecorderFor("runnerset-controller") | ||||||
| 
 | 
 | ||||||
| 	return ctrl.NewControllerManagedBy(mgr). | 	return ctrl.NewControllerManagedBy(mgr). | ||||||
| 		For(&v1alpha1.RunnerSet{}). | 		For(&v1alpha1.RunnerReplicaSet{}). | ||||||
| 		Owns(&v1alpha1.Runner{}). | 		Owns(&v1alpha1.Runner{}). | ||||||
| 		Complete(r) | 		Complete(r) | ||||||
| } | } | ||||||
|  | @ -22,7 +22,7 @@ import ( | ||||||
| // This includes:
 | // This includes:
 | ||||||
| // * creating a Namespace to be used during the test
 | // * creating a Namespace to be used during the test
 | ||||||
| // * starting the 'RunnerReconciler'
 | // * 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.
 | // Call this function at the start of each of your tests.
 | ||||||
| func SetupTest(ctx context.Context) *corev1.Namespace { | func SetupTest(ctx context.Context) *corev1.Namespace { | ||||||
| 	var stopCh chan struct{} | 	var stopCh chan struct{} | ||||||
|  | @ -40,7 +40,7 @@ func SetupTest(ctx context.Context) *corev1.Namespace { | ||||||
| 		mgr, err := ctrl.NewManager(cfg, ctrl.Options{}) | 		mgr, err := ctrl.NewManager(cfg, ctrl.Options{}) | ||||||
| 		Expect(err).NotTo(HaveOccurred(), "failed to create manager") | 		Expect(err).NotTo(HaveOccurred(), "failed to create manager") | ||||||
| 
 | 
 | ||||||
| 		controller := &RunnerSetReconciler{ | 		controller := &RunnerReplicaSetReconciler{ | ||||||
| 			Client:   mgr.GetClient(), | 			Client:   mgr.GetClient(), | ||||||
| 			Scheme:   scheme.Scheme, | 			Scheme:   scheme.Scheme, | ||||||
| 			Log:      logf.Log, | 			Log:      logf.Log, | ||||||
|  | @ -91,12 +91,12 @@ var _ = Context("Inside of a new namespace", func() { | ||||||
| 			name := "example-runnerset" | 			name := "example-runnerset" | ||||||
| 
 | 
 | ||||||
| 			{ | 			{ | ||||||
| 				rs := &actionsv1alpha1.RunnerSet{ | 				rs := &actionsv1alpha1.RunnerReplicaSet{ | ||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Name:      name, | 						Name:      name, | ||||||
| 						Namespace: ns.Name, | 						Namespace: ns.Name, | ||||||
| 					}, | 					}, | ||||||
| 					Spec: actionsv1alpha1.RunnerSetSpec{ | 					Spec: actionsv1alpha1.RunnerReplicaSetSpec{ | ||||||
| 						Replicas: intPtr(1), | 						Replicas: intPtr(1), | ||||||
| 						Template: actionsv1alpha1.RunnerTemplate{ | 						Template: actionsv1alpha1.RunnerTemplate{ | ||||||
| 							Spec: actionsv1alpha1.RunnerSpec{ | 							Spec: actionsv1alpha1.RunnerSpec{ | ||||||
|  | @ -112,7 +112,7 @@ var _ = Context("Inside of a new namespace", func() { | ||||||
| 
 | 
 | ||||||
| 				err := k8sClient.Create(ctx, rs) | 				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{}} | 				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
 | 				// 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
 | 				//   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 { | 				Eventually(func() error { | ||||||
| 					var rs actionsv1alpha1.RunnerSet | 					var rs actionsv1alpha1.RunnerReplicaSet | ||||||
| 
 | 
 | ||||||
| 					err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs) | 					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) | 					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
 | 				// 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
 | 				//   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 { | 				Eventually(func() error { | ||||||
| 					var rs actionsv1alpha1.RunnerSet | 					var rs actionsv1alpha1.RunnerReplicaSet | ||||||
| 
 | 
 | ||||||
| 					err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs) | 					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) | 					rs.Spec.Replicas = intPtr(0) | ||||||
| 
 | 
 | ||||||
							
								
								
									
										6
									
								
								main.go
								
								
								
								
							
							
						
						
									
										6
									
								
								main.go
								
								
								
								
							|  | @ -111,14 +111,14 @@ func main() { | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	runnerSetReconciler := &controllers.RunnerSetReconciler{ | 	runnerSetReconciler := &controllers.RunnerReplicaSetReconciler{ | ||||||
| 		Client: mgr.GetClient(), | 		Client: mgr.GetClient(), | ||||||
| 		Log:    ctrl.Log.WithName("controllers").WithName("RunnerSet"), | 		Log:    ctrl.Log.WithName("controllers").WithName("RunnerReplicaSet"), | ||||||
| 		Scheme: mgr.GetScheme(), | 		Scheme: mgr.GetScheme(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if err = runnerSetReconciler.SetupWithManager(mgr); err != nil { | 	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) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue