(ctx *gin.Context)
| 520 | } |
| 521 | |
| 522 | func (m *Modules) RollbackModule(ctx *gin.Context) { |
| 523 | ctx.Header("Access-Control-Allow-Origin", "*") |
| 524 | |
| 525 | var request dto.RollbackRequest |
| 526 | if err := ctx.BindJSON(&request); err != nil { |
| 527 | fmt.Println(err) |
| 528 | ctx.JSON(http.StatusBadRequest, dto.NewError("Error mapping module request", err.Error())) |
| 529 | return |
| 530 | } |
| 531 | |
| 532 | curr, err := m.kubernetesClient.GetModule(request.ModuleName) |
| 533 | if err != nil { |
| 534 | fmt.Println(err) |
| 535 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching module", err.Error())) |
| 536 | return |
| 537 | } |
| 538 | |
| 539 | var targetGeneration *v1alpha1.HistoryEntry |
| 540 | for _, entry := range curr.History { |
| 541 | if entry.Generation == request.Generation { |
| 542 | targetGeneration = &entry |
| 543 | break |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if targetGeneration == nil { |
| 548 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Invalid rollback generation provided", fmt.Sprintf("Generation %d does not exist", request.Generation))) |
| 549 | return |
| 550 | } |
| 551 | |
| 552 | module := curr.DeepCopy() |
| 553 | |
| 554 | module.Kind = "Module" |
| 555 | module.APIVersion = "cyclops-ui.com/v1alpha1" |
| 556 | |
| 557 | history := module.History |
| 558 | if module.History == nil { |
| 559 | history = make([]v1alpha1.HistoryEntry, 0) |
| 560 | } |
| 561 | |
| 562 | module.History = append([]v1alpha1.HistoryEntry{{ |
| 563 | Generation: curr.Generation, |
| 564 | TargetNamespace: curr.Spec.TargetNamespace, |
| 565 | TemplateRef: v1alpha1.HistoryTemplateRef{ |
| 566 | URL: curr.Spec.TemplateRef.URL, |
| 567 | Path: curr.Spec.TemplateRef.Path, |
| 568 | Version: curr.Status.TemplateResolvedVersion, |
| 569 | SourceType: curr.Spec.TemplateRef.SourceType, |
| 570 | }, |
| 571 | Values: curr.Spec.Values, |
| 572 | }}, history...) |
| 573 | |
| 574 | if len(module.History) > 10 { |
| 575 | module.History = module.History[:len(module.History)-1] |
| 576 | } |
| 577 | |
| 578 | module.Spec.Values = targetGeneration.Values |
| 579 | module.Spec.TemplateRef = v1alpha1.TemplateRef{ |
nothing calls this directly
no test coverage detected