Skip to content

Commit

Permalink
chore: add a check for Instance state when cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Oct 8, 2024
1 parent 339f749 commit a511357
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/instance/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,5 @@ var (
ErrAddingHostToProxyNotAllowed = errors.New("AddingHostToProxyNotAllowed", "adding host to proxy is only allowed in state 'Started' and 'Preparing'. Current state is '%s'")
ErrInstanceNameAlreadyExists = errors.New("InstanceNameAlreadyExists", "instance name '%s' already exists")
ErrSettingSidecarName = errors.New("SettingSidecarName", "error setting sidecar name with prefix '%s' for instance '%s'")
ErrCannotCloneInstance = errors.New("CannotCloneInstance", "cannot clone instance '%s' in state '%s'")
)
4 changes: 4 additions & 0 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (i *Instance) CloneWithSuffix(suffix string) (*Instance, error) {
// When cloning an instance that is a sidecar, the clone will be not a sidecar
// When cloning an instance with sidecars, the sidecars will be cloned as well
func (i *Instance) CloneWithName(name string) (*Instance, error) {
if !i.IsInState(StateCommitted, StateStopped) {
return nil, ErrCannotCloneInstance.WithParams(i.name, i.state)
}

clonedSidecars, err := i.sidecars.clone(name)
if err != nil {
return nil, err
Expand Down

0 comments on commit a511357

Please sign in to comment.