changed the way kube manifest are applyied

This commit is contained in:
pb 2025-05-12 12:23:38 +02:00
parent 063d57d9e7
commit ba940bfc80

View File

@ -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
}