asD
This commit is contained in:
@@ -2,8 +2,9 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
locustCluster "git.lilpenguins.com/crichardson/locust-operator/api/v1alpha1"
|
||||
"github.com/go-logr/logr"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
@@ -16,3 +17,35 @@ func GetLocustCluster(client client.Client, ctx context.Context, namespace strin
|
||||
}
|
||||
return cluster, nil
|
||||
}
|
||||
|
||||
func (r *LocustClusterReconciler) IsLeaderUp(log logr.Logger, locustCluster *locustCluster.LocustCluster, ctx context.Context) (*unstructured.UnstructuredList, error) {
|
||||
podkind := &unstructured.UnstructuredList{}
|
||||
podkind.SetKind("pod")
|
||||
podkind.SetAPIVersion("v1")
|
||||
|
||||
searchLabels := map[string]string{
|
||||
"job-name": BuildName(locustCluster.GetName(), KeyLeader),
|
||||
}
|
||||
err := r.List(ctx, podkind, client.InNamespace(locustCluster.Namespace), client.MatchingLabels(searchLabels))
|
||||
if err != nil {
|
||||
log.Info("Leader not found")
|
||||
return nil, err
|
||||
}
|
||||
return podkind, nil
|
||||
}
|
||||
|
||||
func (r *LocustClusterReconciler) CreateUpdateLeader(log logr.Logger, locustCluster *locustCluster.LocustCluster, ctx context.Context,
|
||||
podList *unstructured.UnstructuredList) error {
|
||||
var err error
|
||||
if len(podList.Items) == 0 {
|
||||
if err = r.CreateLeaderJob(log, locustCluster, ctx); err != nil {
|
||||
log.Error(err, "Failed to create leader")
|
||||
return err
|
||||
}
|
||||
if err = r.CreateLeaderService(log, locustCluster, ctx); err != nil {
|
||||
log.Error(err, "Failed to create leader service")
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user