mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 18:59:25 +00:00
🧪 test: add operator reconcile coverage
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
v1alpha1 "github.com/YuzuZensai/Minikura/operator/api/v1alpha1"
|
||||
)
|
||||
|
||||
func phaseFromReady(ready int32) string {
|
||||
if ready > 0 {
|
||||
return v1alpha1.PhaseRunning
|
||||
}
|
||||
return v1alpha1.PhasePending
|
||||
}
|
||||
|
||||
func conditionStatus(ok bool) metav1.ConditionStatus {
|
||||
if ok {
|
||||
return metav1.ConditionTrue
|
||||
@@ -22,6 +34,15 @@ func setCondition(conditions *[]metav1.Condition, c metav1.Condition) {
|
||||
meta.SetStatusCondition(conditions, c)
|
||||
}
|
||||
|
||||
func failWithStatus(ctx context.Context, c client.Client, obj client.Object, cause error, mutate func()) (ctrl.Result, error) {
|
||||
patch := client.MergeFrom(obj.DeepCopyObject().(client.Object))
|
||||
mutate()
|
||||
if err := c.Status().Patch(ctx, obj, patch); err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("%w (status patch failed: %v)", cause, err)
|
||||
}
|
||||
return ctrl.Result{}, cause
|
||||
}
|
||||
|
||||
func serviceEndpoint(svc *corev1.Service, namespace string) string {
|
||||
internal := fmt.Sprintf("%s.%s.svc.cluster.local", svc.Name, namespace)
|
||||
port := int32(0)
|
||||
|
||||
Reference in New Issue
Block a user