From ba940bfc80a104143215366356f7e14ff82fb314 Mon Sep 17 00:00:00 2001 From: pb Date: Mon, 12 May 2025 12:23:38 +0200 Subject: [PATCH] changed the way kube manifest are applyied --- infrastructure/kubernetes.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/infrastructure/kubernetes.go b/infrastructure/kubernetes.go index c512068..1e74f24 100644 --- a/infrastructure/kubernetes.go +++ b/infrastructure/kubernetes.go @@ -307,7 +307,7 @@ func (k *KubernetesService) CreateAdmiraltyTarget(context context.Context, execu }, } - res, err := dynamicClientApply(executionId, "target", gvrTargets, context, target) + res, err := dynamicClientApply(executionId, "target-" + peerId + "-" +executionId, gvrTargets, context, target) if err != nil { return nil, errors.New("Error when trying to apply Target definition :" + err.Error()) } @@ -339,7 +339,7 @@ func (k *KubernetesService) CreateAdmiraltySource(context context.Context,execut } - res, err := dynamicClientApply(executionId, "source",gvrSources, context, source) + res, err := dynamicClientApply(executionId, "source-" + executionId,gvrSources, context, source) if err != nil { return nil, errors.New("Error when trying to apply Source definition :" + err.Error()) } @@ -449,7 +449,7 @@ func getCDRapiKube(client kubernetes.Clientset, ctx context.Context, path string return resp, nil } -func dynamicClientApply(executionId string, typeResource string, resourceDefinition schema.GroupVersionResource, ctx context.Context, object map[string]interface{}) ([]byte, error) { +func dynamicClientApply(executionId string, resourceName string, resourceDefinition schema.GroupVersionResource, ctx context.Context, object map[string]interface{}) ([]byte, error) { cli, err := NewDynamicClient() if err != nil { return nil, errors.New("Could not retrieve dynamic client when creating Admiralty Source : " + err.Error()) @@ -458,14 +458,15 @@ func dynamicClientApply(executionId string, typeResource string, resourceDefinit res, err := cli.Resource(resourceDefinition). Namespace(executionId). Apply(ctx, - typeResource + "-" + executionId, + resourceName, &unstructured.Unstructured{Object: object}, metav1.ApplyOptions{ FieldManager: "kubectl-client-side-apply", }, ) if err != nil { - fmt.Println("Error from k8s API when applying " + fmt.Sprint(object) + " to " + gvrSources.String() + " : " , err) + o, err := json.Marshal(object) + fmt.Println("Error from k8s API when applying " + fmt.Sprint(string(o)) + " to " + gvrSources.String() + " : " , err) return nil,err }