Skip to content

Commit

Permalink
Podman bug (#15)
Browse files Browse the repository at this point in the history
* seed RNG to create random strings and remove data races
  • Loading branch information
mfleader authored Jun 8, 2023
1 parent 8f2abfa commit 43ed53a
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 285 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Arcaflow engine deployer podman

This library is an implementation of the [arcaflow deployer interface](https://github.com/arcalot/arcaflow-engine-deployer) that uses the podman CLI.
This library is an implementation of the [arcaflow deployer interface](https://github.com/arcalot/arcaflow-engine-deployer) that uses the podman CLI.

## Verified Podman CLI Version

Testing has been performed on this Podman version to validate
functionality.

```
❯ podman version
Client: Podman Engine
Version: 4.5.0
API Version: 4.5.0
Go Version: go1.19.7
Built: Fri Apr 14 11:42:56 2023
OS/Arch: linux/amd64
```
16 changes: 10 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ const (
)

type Podman struct {
Path string `json:"path"`
ContainerName string `json:"containerName"`
CgroupNs string `json:"cgroupNs"`
NetworkMode string `json:"networkMode"`
ImageArchitecture string `json:"imageArchitecture"`
ImageOS string `json:"imageOS"`
Path string `json:"path"`
// Constant prefix prepended to the randomized container name string.
ContainerNamePrefix string `json:"containerNamePrefix"`
CgroupNs string `json:"cgroupNs"`
NetworkMode string `json:"networkMode"`
ImageArchitecture string `json:"imageArchitecture"`
ImageOS string `json:"imageOS"`
// The initial integer that is the starting point for a
// Random Number Generator's algorithm.
RngSeed int64 `json:"rngSeed"`
}

// Deployment contains the information about deploying the plugin.
Expand Down
31 changes: 24 additions & 7 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ package podman

import (
"context"

"fmt"
"github.com/docker/docker/api/types/container"
log "go.arcalot.io/log/v2"
"go.flow.arcalot.io/deployer"
args "go.flow.arcalot.io/podmandeployer/internal/argsbuilder"
"go.flow.arcalot.io/podmandeployer/internal/cliwrapper"
"go.flow.arcalot.io/podmandeployer/internal/util"
"math/rand"
"sync"
)

type Connector struct {
containerName string
config *Config
logger log.Logger
podmanCliWrapper cliwrapper.CliWrapper
containerNamePrefix string
config *Config
logger log.Logger
podmanCliWrapper cliwrapper.CliWrapper
rng *rand.Rand
// Random Number Generator to facilitate the generation
// of random strings for the container name suffix.
rngSeed int64
// The initial integer that is the starting point for a
// random number generator's algorithm.
lock *sync.Mutex
}

func (c *Connector) Deploy(ctx context.Context, image string) (deployer.Plugin, error) {
Expand All @@ -29,9 +39,10 @@ func (c *Connector) Deploy(ctx context.Context, image string) (deployer.Plugin,
containerConfig := c.unwrapContainerConfig()
hostConfig := c.unwrapHostConfig()
commandArgs := []string{"run", "-i", "-a", "stdin", "-a", "stdout", "-a", "stderr"}
containerName := c.NextContainerName(c.containerNamePrefix, 10)

args.NewBuilder(&commandArgs).
SetContainerName(c.containerName).
SetContainerName(containerName).
SetEnv(containerConfig.Env).
SetVolumes(hostConfig.Binds).
SetCgroupNs(c.config.Podman.CgroupNs).
Expand All @@ -46,7 +57,7 @@ func (c *Connector) Deploy(ctx context.Context, image string) (deployer.Plugin,
cliPlugin := CliPlugin{
wrapper: c.podmanCliWrapper,
containerImage: image,
containerName: c.containerName,
containerName: containerName,
config: c.config,
stdin: stdin,
stdout: stdout,
Expand Down Expand Up @@ -93,3 +104,9 @@ func (c *Connector) unwrapHostConfig() container.HostConfig {
}
return container.HostConfig{}
}

func (c *Connector) NextContainerName(containerNamePrefix string, randomStrSize int) string {
c.lock.Lock()
defer c.lock.Unlock()
return fmt.Sprintf("%s_%s", containerNamePrefix, util.GetRandomString(c.rng, randomStrSize))
}
Loading

0 comments on commit 43ed53a

Please sign in to comment.