Skip to content

Commit 03e6216

Browse files
authored
Remove StartContainer from container interface (#123)
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
1 parent 9e97764 commit 03e6216

File tree

5 files changed

+4
-43
lines changed

5 files changed

+4
-43
lines changed

pkg/container/docker/client.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,29 +292,13 @@ func (c *Client) CreateContainer(
292292
return "", NewContainerError(err, "", fmt.Sprintf("failed to create container: %v", err))
293293
}
294294

295-
return resp.ID, nil
296-
}
297-
298-
// StartContainer starts a container
299-
// If the container is already running, it returns success
300-
func (c *Client) StartContainer(ctx context.Context, containerID string) error {
301-
// Check if the container is already running
302-
running, err := c.IsContainerRunning(ctx, containerID)
303-
if err != nil {
304-
return err
305-
}
306-
307-
// If the container is already running, return success
308-
if running {
309-
return nil
310-
}
311-
312295
// Start the container
313-
err = c.client.ContainerStart(ctx, containerID, container.StartOptions{})
296+
err = c.client.ContainerStart(ctx, resp.ID, container.StartOptions{})
314297
if err != nil {
315-
return NewContainerError(err, containerID, fmt.Sprintf("failed to start container: %v", err))
298+
return "", NewContainerError(err, resp.ID, fmt.Sprintf("failed to start container: %v", err))
316299
}
317-
return nil
300+
301+
return resp.ID, nil
318302
}
319303

320304
// ListContainers lists containers

pkg/container/kubernetes/client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,6 @@ func (c *Client) RemoveContainer(ctx context.Context, containerID string) error
523523
return nil
524524
}
525525

526-
// StartContainer implements runtime.Runtime.
527-
func (*Client) StartContainer(_ context.Context, containerID string) error {
528-
// In Kubernetes, we don't need to explicitly start containers as they are started
529-
// automatically when created. However, we could scale up a statefulset if it's scaled to 0.
530-
logger.Log.Info(fmt.Sprintf("Container %s is managed by Kubernetes and started automatically", containerID))
531-
return nil
532-
}
533-
534526
// StopContainer implements runtime.Runtime.
535527
func (*Client) StopContainer(_ context.Context, _ string) error {
536528
return nil

pkg/container/runtime/types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ type Runtime interface {
5555
options *CreateContainerOptions,
5656
) (string, error)
5757

58-
// StartContainer starts a container
59-
StartContainer(ctx context.Context, containerID string) error
60-
6158
// ListContainers lists containers
6259
ListContainers(ctx context.Context) ([]ContainerInfo, error)
6360

pkg/transport/sse.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ func (t *SSETransport) Start(ctx context.Context) error {
178178
return fmt.Errorf("container runtime not set")
179179
}
180180

181-
// Start the container
182-
logger.Log.Info(fmt.Sprintf("Starting container %s...", t.containerName))
183-
if err := t.runtime.StartContainer(ctx, t.containerID); err != nil {
184-
return fmt.Errorf("failed to start container: %v", err)
185-
}
186-
187181
// Create and start the transparent proxy
188182
// The SSE transport forwards requests from the host port to the container's target port
189183
// In a Docker bridge network, we need to use the specified target host

pkg/transport/stdio.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ func (t *StdioTransport) Start(ctx context.Context) error {
141141
return fmt.Errorf("container runtime not set")
142142
}
143143

144-
// Start the container
145-
logger.Log.Info(fmt.Sprintf("Starting container %s...", t.containerName))
146-
if err := t.runtime.StartContainer(ctx, t.containerID); err != nil {
147-
return fmt.Errorf("failed to start container: %v", err)
148-
}
149-
150144
// Attach to the container
151145
var err error
152146
t.stdin, t.stdout, err = t.runtime.AttachContainer(ctx, t.containerID)

0 commit comments

Comments
 (0)