asD
This commit is contained in:
16
internal/controller/build.go
Normal file
16
internal/controller/build.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
locustCluster "git.lilpenguins.com/crichardson/locust-operator/api/v1alpha1"
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *LocustClusterReconciler) CreateLeaderJob(log logr.Logger, locustCluster *locustCluster.LocustCluster, ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LocustClusterReconciler) CreateLeaderService(log logr.Logger, locustCluster *locustCluster.LocustCluster,
|
||||||
|
ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,6 +1,56 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import "sigs.k8s.io/controller-runtime/pkg/client"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxConcurrentReconciles = 20
|
||||||
|
NamespaceDefault = "pie-coordination-dev"
|
||||||
|
TestEnvCheck = "TEST_ENV_CHECK"
|
||||||
|
KubernetesClusterEnv = "KUBERNETES_CLUSTER"
|
||||||
|
LocustOperatorVersionDesc = "Locust Operator Version"
|
||||||
|
LeaderContainer = "locustio/locust:2.37.1"
|
||||||
|
LeaderTestFile = "/usr/local/locust/dummy.py"
|
||||||
|
LeaderPortNameWeb = "locust-web"
|
||||||
|
LeaderPortProtocol = "TCP"
|
||||||
|
LeaderPortWeb = 8089
|
||||||
|
LeaderPortNameLocust1 = "listener1"
|
||||||
|
LeaderPortListener1 = 5557
|
||||||
|
LeaderPortNameLocust2 = "listener2"
|
||||||
|
LeaderPortListener2 = 5558
|
||||||
|
LeaderMaxCPU = "0.5"
|
||||||
|
LeaderMaxMemory = "1Gi"
|
||||||
|
LeaderMinCPU = "0.25"
|
||||||
|
LeaderMinMemory = "512Mi"
|
||||||
|
LeaderBuildParamConfig = "/usr/local/etc/locust_build_params"
|
||||||
|
MosaicContainer = "docker.apple.com/telemetry/mosaic-agent:2.19.1"
|
||||||
|
MosaicPortNameHttp = "mosaic-http"
|
||||||
|
MosaicPortHttp = 8080
|
||||||
|
MosaicPortProtocol = "TCP"
|
||||||
|
MosaicVolumeConfigPath = "/usr/local/mosaic/conf.d"
|
||||||
|
MosaicEndpointSuffix = "PROMETHEUS"
|
||||||
|
GrafanaEndpoint = "playground-fuji.grafana.telemetry.g.apple.com"
|
||||||
|
WorkerMaxCPU = "2"
|
||||||
|
WorkerMinCPU = "1"
|
||||||
|
WorkerMaxMemory = "3Gi"
|
||||||
|
WorkerMinMemory = "1Gi"
|
||||||
|
WorkerMaxStorage = "20Gi"
|
||||||
|
WorkerMinStorage = "10Gi"
|
||||||
|
SDRIdentName = "identity-certs"
|
||||||
|
CertsMount = "/certs/"
|
||||||
|
TimeoutDefault = time.Second * 20
|
||||||
|
TimeoutInterval = time.Millisecond * 250
|
||||||
|
SUCCESS bool = true
|
||||||
|
FAILURE bool = false
|
||||||
|
KeyMosaic = "mosaic"
|
||||||
|
KeyLeader = "leader"
|
||||||
|
KeyWorker = "worker"
|
||||||
|
KeyOperator = "operator"
|
||||||
|
KeyDB = "locust-db"
|
||||||
|
)
|
||||||
|
|
||||||
func BuildObjectKey(namespace string, name string) client.ObjectKey {
|
func BuildObjectKey(namespace string, name string) client.ObjectKey {
|
||||||
return client.ObjectKey{
|
return client.ObjectKey{
|
||||||
@@ -8,3 +58,7 @@ func BuildObjectKey(namespace string, name string) client.ObjectKey {
|
|||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BuildName(name string, suffix string) string {
|
||||||
|
return fmt.Sprintf("%s-%s", name, suffix)
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,24 +48,31 @@ type LocustClusterReconciler struct {
|
|||||||
// For more details, check Reconcile and its Result here:
|
// For more details, check Reconcile and its Result here:
|
||||||
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/reconcile
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/reconcile
|
||||||
func (r *LocustClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *LocustClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
_ = logf.FromContext(ctx)
|
log := logf.FromContext(ctx).WithValues()
|
||||||
|
|
||||||
logf.Log.Info("Looking up LocustCluster", "LocustClusterName", req.Name,
|
log.Info("Looking up LocustCluster")
|
||||||
"Namespace", req.Namespace)
|
// logf.Log.Info("Looking up LocustCluster", "LocustClusterName", req.Name,
|
||||||
|
// "Namespace", req.Namespace)
|
||||||
|
|
||||||
// locustCluster, err := GetLocustCluster(r.Client, ctx, req.Namespace, req.Name)
|
// locustCluster, err := GetLocustCluster(r.Client, ctx, req.Namespace, req.Name)
|
||||||
_, err := GetLocustCluster(r.Client, ctx, req.Namespace, req.Name)
|
locustCluster, err := GetLocustCluster(r.Client, ctx, req.Namespace, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
logf.Log.Info("LocustCluster not found", "LocustClusterName", req.Name,
|
log.Info("LocustCluster not found")
|
||||||
"Namespace", req.Namespace)
|
// logf.Log.Info("LocustCluster not found", "LocustClusterName", req.Name,
|
||||||
|
// "Namespace", req.Namespace)
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
logf.Log.Error(err, "Failed to lookup LocustCluster", "LocustClusterName", req.Name,
|
log.Error(err, "LocustCluster not found")
|
||||||
"Namespace", req.Namespace)
|
// logf.Log.Error(err, "Failed to lookup LocustCluster", "LocustClusterName", req.Name,
|
||||||
|
// "Namespace", req.Namespace)
|
||||||
return ctrl.Result{Requeue: true}, err
|
return ctrl.Result{Requeue: true}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
podList, err := r.IsLeaderUp(log, locustCluster, ctx)
|
||||||
|
|
||||||
|
r.CreateUpdateLeader(log, locustCluster, ctx, podList)
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
locustCluster "git.lilpenguins.com/crichardson/locust-operator/api/v1alpha1"
|
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"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,3 +17,35 @@ func GetLocustCluster(client client.Client, ctx context.Context, namespace strin
|
|||||||
}
|
}
|
||||||
return cluster, nil
|
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