(ctx *gin.Context)
| 334 | } |
| 335 | |
| 336 | func (m *Modules) UpdateModule(ctx *gin.Context) { |
| 337 | ctx.Header("Access-Control-Allow-Origin", "*") |
| 338 | |
| 339 | var request dto.Module |
| 340 | if err := ctx.BindJSON(&request); err != nil { |
| 341 | fmt.Println(err) |
| 342 | ctx.JSON(http.StatusBadRequest, dto.NewError("Error mapping module request", err.Error())) |
| 343 | return |
| 344 | } |
| 345 | |
| 346 | curr, err := m.kubernetesClient.GetModule(request.Name) |
| 347 | if err != nil { |
| 348 | fmt.Println(err) |
| 349 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching module", err.Error())) |
| 350 | return |
| 351 | } |
| 352 | |
| 353 | module, err := mapper.RequestToModule(request) |
| 354 | if err != nil { |
| 355 | fmt.Println(err) |
| 356 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error())) |
| 357 | return |
| 358 | } |
| 359 | |
| 360 | module.Spec.TemplateRef.SourceType = curr.Spec.TemplateRef.SourceType |
| 361 | |
| 362 | module.Status.TemplateResolvedVersion = request.Template.ResolvedVersion |
| 363 | module.Status.ReconciliationStatus = curr.Status.ReconciliationStatus |
| 364 | module.Status.IconURL = curr.Status.IconURL |
| 365 | module.Status.ManagedGVRs = curr.Status.ManagedGVRs |
| 366 | |
| 367 | module.Spec.TargetNamespace = curr.Spec.TargetNamespace |
| 368 | module.SetLabels(curr.GetLabels()) |
| 369 | |
| 370 | annotations := curr.GetAnnotations() |
| 371 | moduleAnnotations := module.GetAnnotations() |
| 372 | |
| 373 | if annotations == nil { |
| 374 | annotations = make(map[string]string) |
| 375 | } |
| 376 | |
| 377 | if moduleAnnotations != nil { |
| 378 | if _, ok := moduleAnnotations["cyclops-ui.com/write-repo"]; ok { |
| 379 | annotations["cyclops-ui.com/write-repo"] = moduleAnnotations["cyclops-ui.com/write-repo"] |
| 380 | } |
| 381 | if _, ok := moduleAnnotations["cyclops-ui.com/write-path"]; ok { |
| 382 | annotations["cyclops-ui.com/write-path"] = moduleAnnotations["cyclops-ui.com/write-path"] |
| 383 | } |
| 384 | if _, ok := moduleAnnotations["cyclops-ui.com/write-revision"]; ok { |
| 385 | annotations["cyclops-ui.com/write-revision"] = moduleAnnotations["cyclops-ui.com/write-revision"] |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if len(moduleAnnotations) == 0 || len(moduleAnnotations[v1alpha1.GitOpsWriteRepoAnnotation]) == 0 { |
| 390 | delete(annotations, v1alpha1.GitOpsWriteRepoAnnotation) |
| 391 | } |
| 392 | if len(moduleAnnotations) == 0 || len(moduleAnnotations[v1alpha1.GitOpsWritePathAnnotation]) == 0 { |
| 393 | delete(annotations, v1alpha1.GitOpsWritePathAnnotation) |
nothing calls this directly
no test coverage detected