Skip to content

Commit

Permalink
Fix 478: Copy Scenario into new structure (hobbyfarm#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel authored Jan 2, 2025
1 parent 0517a87 commit 9cafa53
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions v3/services/scenariosvc/internal/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,23 @@ func (s *GrpcScenarioServer) CopyScenario(ctx context.Context, req *generalpb.Re
id,
)
}

copyName := string(name) + " - Copy"
copyName = base64.StdEncoding.EncodeToString([]byte(copyName))
copyId := util.GenerateResourceName("s", copyName, 10)

scenario.Name = copyId
scenario.Spec.Name = copyName
copyScenario := &hfv1.Scenario{
ObjectMeta: metav1.ObjectMeta{
Name: copyId,
Labels: scenario.Labels,
Annotations: scenario.Annotations,
},
Spec: scenario.Spec,
}

copyScenario.Spec.Name = copyName

_, err = s.scenarioClient.Create(ctx, scenario, metav1.CreateOptions{})
_, err = s.scenarioClient.Create(ctx, copyScenario, metav1.CreateOptions{})
if err != nil {
glog.Errorf("Error attempting to create a copy of scenario %s: %v", id, err)
return &emptypb.Empty{}, hferrors.GrpcError(
Expand Down

0 comments on commit 9cafa53

Please sign in to comment.