Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tfo unlock rerun #32

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/api/get_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@ func (h APIHandler) UnlockTerraform(c *gin.Context) {
c.JSON(http.StatusUnprocessableEntity, response(http.StatusUnprocessableEntity, fmt.Sprintf("terraform unlock failed: %s", err), nil))
return
}
err = rerun(h.clientset, clusterName, namespace, name, "unlock-terraform-triggered-rerun", c)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, response(http.StatusUnprocessableEntity, fmt.Sprintf("Failed to trigger rerun: %s", err), []any{}))
return
}

c.JSON(http.StatusOK, response(http.StatusOK, "terraform unlocked", nil))

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ func (h APIHandler) rerunWorkflow(c *gin.Context) {
name := c.Param("name")
namespace := c.Param("namespace")

err := rerun(h.clientset, clusterName, namespace, name, c)
err := rerun(h.clientset, clusterName, namespace, name, "api-triggered-rerun", c)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, response(http.StatusUnprocessableEntity, fmt.Sprintf("Failed to trigger rerun: %s", err), []any{}))
return
}
c.JSON(http.StatusNoContent, nil)
}

func rerun(parentClientset kubernetes.Interface, clusterName, namespace, name string, ctx context.Context) error {
func rerun(parentClientset kubernetes.Interface, clusterName, namespace, name, rerunLabelValue string, ctx context.Context) error {
config, err := getVclusterConfig(parentClientset, "internal", clusterName)
if err != nil {
return err
Expand All @@ -373,7 +373,7 @@ func rerun(parentClientset kubernetes.Interface, clusterName, namespace, name st
resource.Labels = map[string]string{}
}

resource.Labels["kubernetes.io/change-cause"] = fmt.Sprintf("api-triggered-rerun-%s", time.Now().Format("20060102150405"))
resource.Labels["kubernetes.io/change-cause"] = fmt.Sprintf("%s-%s", rerunLabelValue, time.Now().Format("20060102150405"))
_, err = tfoclientset.TfV1beta1().Terraforms(namespace).Update(ctx, resource, metav1.UpdateOptions{})
if err != nil {
return err
Expand Down
Loading