From 8e8d0d3e01f46e4dbc3d55f7b74059adff0b968b Mon Sep 17 00:00:00 2001 From: pb Date: Mon, 5 May 2025 16:13:49 +0200 Subject: [PATCH] added a new parameter to the /admiralty/targets route to specify the peerId of the peer targeted, allowing to name differently peers targeted in a namespace --- controllers/admiralty.go | 10 +++++++++- infrastructure/interface.go | 2 +- infrastructure/kubernetes.go | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/controllers/admiralty.go b/controllers/admiralty.go index 4418d74..65b984a 100644 --- a/controllers/admiralty.go +++ b/controllers/admiralty.go @@ -168,13 +168,21 @@ func (c *AdmiraltyController) CreateAdmiraltySource() { // @Title CreateAdmiraltyTarget // @Description Create an Admiralty Target in the namespace associated to the executionID // @Param execution path string true "execution id of the workflow" +// @Param peer path string true "peerId of the peer the target points to" // @Success 201 // @router /target/:execution [post] func (c *AdmiraltyController) CreateAdmiraltyTarget(){ var data map[string]interface{} execution := c.Ctx.Input.Param(":execution") + peerId := c.Ctx.Input.Param(":peer") + if execution == "" || peerId == "" { + c.Ctx.Output.SetStatus(400) + c.Data["json"] = map[string]string{"error" : "parameters can be empty"} + c.ServeJSON() + return + } serv, err := infrastructure.NewService() if err != nil { @@ -185,7 +193,7 @@ func (c *AdmiraltyController) CreateAdmiraltyTarget(){ return } - resp, err := serv.CreateAdmiraltyTarget(c.Ctx.Request.Context(),execution) + resp, err := serv.CreateAdmiraltyTarget(c.Ctx.Request.Context(),execution, peerId) if err != nil { // change code to 500 c.Ctx.Output.SetStatus(500) diff --git a/infrastructure/interface.go b/infrastructure/interface.go index 2f8fbf1..02807ac 100644 --- a/infrastructure/interface.go +++ b/infrastructure/interface.go @@ -19,7 +19,7 @@ type Infrastructure interface { CreateAdmiraltySource(context context.Context,executionId string) ([]byte, error) CreateKubeconfigSecret(context context.Context,kubeconfig string, executionId string) ([]byte, error) GetKubeconfigSecret(context context.Context,executionId string) ([]byte, error) - CreateAdmiraltyTarget(context context.Context,executionId string)([]byte,error) + CreateAdmiraltyTarget(context context.Context,executionId string, peerId string)([]byte,error) GetOneNode(context context.Context,executionID string) (*v1.Node, error) } diff --git a/infrastructure/kubernetes.go b/infrastructure/kubernetes.go index 963ae3d..0d39b46 100644 --- a/infrastructure/kubernetes.go +++ b/infrastructure/kubernetes.go @@ -280,7 +280,7 @@ func (k *KubernetesService) GetTargets(ctx context.Context) ([]string, error) { // - have declared the same namespace as the one where the pods are created in the local cluster // // - have delcared a serviceAccount with sufficient permission to create pods -func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, executionId string) ([]byte, error) { +func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, executionId string, peerId string) ([]byte, error) { exists, err := k.GetKubeconfigSecret(context, executionId) if err != nil { fmt.Println("Error verifying kube-secret before creating target") @@ -297,7 +297,7 @@ func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, execu "apiVersion": "multicluster.admiralty.io/v1alpha1", "kind": "Target", "metadata": map[string]interface{}{ - "name": "target-"+executionId, + "name": "target-" + peerId + "-" +executionId, "namespace": executionId, }, "spec": map[string]interface{}{