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

feat: podman attempt v2 #2518

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,8 @@ lerna-debug.log
# contains several libraries that get shipped
yarn.lock
package.json
package-lock.json
package-lock.json

# Nix
# ignores the default result symlink created when building with nix
result
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package host_machine_directories

import (
"io/ioutil"
"path"
"path/filepath"

"github.com/adrg/xdg"
"github.com/kurtosis-tech/stacktrace"
"path"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -107,9 +111,19 @@ func GetLastPesteredUserAboutOldVersionsFilepath() (string, error) {

func GetKurtosisCliLogsFileDirPath(fileName string) (string, error) {
xdgRelDirPath := getRelativeFilePathForKurtosisCliLogs()
kurtosisCliLogFilePath, err := xdg.DataFile(path.Join(xdgRelDirPath, fileName))
if err != nil {
return "", stacktrace.Propagate(err, "An error occurred getting the kurtosis cli logs file path using '%v'", kurtosisCliLogFilePath)
// kurtosisCliLogFilePath, err := xdg.DataFile(path.Join(xdgRelDirPath, fileName))
// if err != nil {
// return "", stacktrace.Propagate(err, "An error occurred getting the kurtosis cli logs file path using '%v'", kurtosisCliLogFilePath)
// }
kurtosisCliLogFilePath, errXdg := xdg.DataFile(path.Join(xdgRelDirPath, fileName))
if errXdg != nil {
// Fallback to temp folder if XDG fails to find a suitable location. For instance XDG will fail when testing inside Nix sandbox.
logrus.WithError(errXdg).Warnf("Couldn't create kurtosis cli logs file path in the user space '%v'. Trying on temp folder.", kurtosisCliLogFilePath)
kurtosisCliLogDir, errTemp := ioutil.TempDir("", applicationDirname)
if errTemp != nil {
return "", stacktrace.Propagate(errTemp, "An error occurred creating kurtosis cli logs file path using '%v'", kurtosisCliLogDir)
}
kurtosisCliLogFilePath = filepath.Join(kurtosisCliLogDir, fileName)
}
return kurtosisCliLogFilePath, nil
}
Expand Down
9 changes: 5 additions & 4 deletions cli/cli/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ fi
exit 1
fi
# Executing goreleaser v1.26.2 without needing to install it
if ! curl -sfL https://goreleaser.com/static/run | VERSION=v1.26.2 DISTRIBUTION=oss bash -s -- ${goreleaser_verb_and_flags}; then
echo "Error: Couldn't build the CLI binary for the current OS/arch" >&2
exit 1
fi
# if ! curl -sfL https://goreleaser.com/static/run | VERSION=v1.26.2 DISTRIBUTION=oss bash -s -- ${goreleaser_verb_and_flags}; then
if ! GORELEASER_CURRENT_TAG=$(cat $root_dirpath/version.txt) goreleaser ${goreleaser_verb_and_flags}; then
echo "Error: Couldn't build the CLI binary for the current OS/arch" >&2
exit 1
fi
)

# Final verification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
EngineConfigLocalDir = "/run/engine"

//The Docker network name where all the containers in the engine and logs service context will be added
NameOfNetworkToStartEngineAndLogServiceContainersIn = "bridge"
NameOfNetworkToStartEngineAndLogServiceContainersIn = "podman"
HttpApplicationProtocol = "http"

GitHubAuthStorageDirPath = "/kurtosis-data/github-auth/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import (
"context"
"github.com/sirupsen/logrus"
"net"
"time"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"
Expand Down Expand Up @@ -34,6 +36,9 @@
return nil
}

logrus.Infof("Waiting a few second before connecting reverse proxy to network...")
time.Sleep(10 * time.Second)

Check failure on line 40 in container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/network_reverse_proxy.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

mnd: Magic number: 10, in <argument> detected (gomnd)
logrus.Infof("Okay lets try and connect now.")
if err = dockerManager.ConnectContainerToNetwork(ctx, networkId, maybeReverseProxyContainerId, autoAssignIpAddressToReverseProxy, emptyAliasForReverseProxy); err != nil {
return stacktrace.Propagate(err, "An error occurred while connecting the reverse proxy with container id '%v' to the enclave network '%v'", maybeReverseProxyContainerId, networkId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"
"io"
"net"
"os"
Expand All @@ -14,6 +13,8 @@ import (
"strings"
"time"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"

"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/gammazero/workerpool"
Expand Down Expand Up @@ -417,24 +418,24 @@ func GetEngineAndLogsComponentsNetwork(
ctx context.Context,
dockerManager *docker_manager.DockerManager,
) (*types.Network, error) {
matchingNetworks, err := dockerManager.GetNetworksByName(ctx, consts.NameOfNetworkToStartEngineAndLogServiceContainersIn)
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred getting networks matching the network we want to start the engine in, '%v'",
consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
)
}
numMatchingNetworks := len(matchingNetworks)
if numMatchingNetworks == 0 && numMatchingNetworks > 1 {
return nil, stacktrace.NewError(
"Expected exactly one network matching the name of the network that we want to start the engine in, '%v', but got %v",
consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
numMatchingNetworks,
)
}
targetNetwork := matchingNetworks[0]
return targetNetwork, nil
// matchingNetworks, err := dockerManager.GetNetworksByName(ctx, consts.NameOfNetworkToStartEngineAndLogServiceContainersIn)
// if err != nil {
// return nil, stacktrace.Propagate(
// err,
// "An error occurred getting networks matching the network we want to start the engine in, '%v'",
// consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
// )
// }
// numMatchingNetworks := len(matchingNetworks)
// if numMatchingNetworks == 0 && numMatchingNetworks > 1 {
// return nil, stacktrace.NewError(
// "Expected exactly one network matching the name of the network that we want to start the engine in, '%v', but got %v",
// consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
// numMatchingNetworks,
// )
// }
// targetNetwork := matchingNetworks[0]
return dockerManager.GetDefaultNetwork(ctx)
}

func DumpContainers(ctx context.Context, dockerManager *docker_manager.DockerManager, containers []*types.Container, outputDirpath string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,15 @@ func createStartServiceOperation(
}
}

if logsCollectorAddress == "" {
return nil, stacktrace.NewError("Expected to have a logs collector server address value to send the user service logs, but it is empty")
}
// if logsCollectorAddress == "" {
// return nil, stacktrace.NewError("Expected to have a logs collector server address value to send the user service logs, but it is empty")
// }

// The container will be configured to send the logs to the Fluentbit logs collector server
fluentdLoggingDriverCnfg := docker_manager.NewFluentdLoggingDriver(
logsCollectorAddress,
logsCollectorLabels,
)
// // The container will be configured to send the logs to the Fluentbit logs collector server
// fluentdLoggingDriverCnfg := docker_manager.NewFluentdLoggingDriver(
// logsCollectorAddress,
// logsCollectorLabels,
// )

createAndStartArgsBuilder := docker_manager.NewCreateAndStartContainerArgsBuilder(
containerImageName,
Expand All @@ -703,8 +703,8 @@ func createStartServiceOperation(
tiniEnabled,
).WithVolumeMounts(
volumeMounts,
).WithLoggingDriver(
fluentdLoggingDriverCnfg,
// ).WithLoggingDriver(
// fluentdLoggingDriverCnfg,
).WithRestartPolicy(
restartPolicy,
).WithUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,32 @@
return nil
}

func (manager *DockerManager) GetDefaultNetwork(ctx context.Context) (*docker_manager_types.Network, error) {

matchingNetworks, err := manager.GetNetworksByName(ctx, consts.NameOfNetworkToStartEngineAndLogServiceContainersIn)
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred getting networks matching the network we want to start the engine in, '%v'",
consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
)
}
numMatchingNetworks := len(matchingNetworks)
if numMatchingNetworks > 1 {
return nil, stacktrace.NewError(
"Expected exactly one network matching the name of the network that we want to start the engine in, '%v', but got %v",
consts.NameOfNetworkToStartEngineAndLogServiceContainersIn,
numMatchingNetworks,
)
}

if numMatchingNetworks == 0 {
return nil, stacktrace.NewError(fmt.Sprintf("No matching network found with the configured name: %v", consts.NameOfNetworkToStartEngineAndLogServiceContainersIn))
}

return matchingNetworks[0], nil
}

/*
CreateVolume
Creates a Docker volume identified by the given name.
Expand Down Expand Up @@ -481,6 +507,21 @@

result := []*volume.Volume{}
if resp.Volumes != nil {
// Podman API inconsistency - filter out the union matches that podman returns while docker only returns the intersect matches when filtering by label
for _, vol := range resp.Volumes {
allLabelsMatch := true

for label, val := range labels {
if volValue, exists := vol.Labels[label]; !exists || volValue != val {
allLabelsMatch = false
break
}
}

if allLabelsMatch {
result = append(result, vol)
}
}
result = resp.Volumes
}

Expand Down Expand Up @@ -804,8 +845,17 @@
return nil, stacktrace.Propagate(err, "An error occurred inspecting container with ID '%v'", containerId)
}
allNetworkInfo := resp.NetworkSettings.Networks
for _, networkInfo := range allNetworkInfo {
containerIps[networkInfo.NetworkID] = networkInfo.IPAddress
// for _, networkInfo := range allNetworkInfo {
// containerIps[networkInfo.NetworkID] = networkInfo.IPAddress
// }
for networkKey, networkInfo := range allNetworkInfo {
// podman does not return the networkID properly and as such we need to make sure we get it.
network, err := manager.dockerClient.NetworkInspect(ctx, networkInfo.NetworkID, types.NetworkInspectOptions{})

Check failure on line 853 in container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

Scope, Verbose are missing in NetworkInspectOptions (exhaustruct)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred inspecting network: '%v'", networkKey)
}

containerIps[network.ID] = networkInfo.IPAddress
}
return containerIps, nil
}
Expand Down Expand Up @@ -1172,6 +1222,15 @@

config := getEndpointSettingsForIpAddress(staticIpAddressStr, alias)

logrus.Infof("Listing all networks right before attempting to connect to network...")
networkResources, err := manager.dockerClient.NetworkList(ctx, types.NetworkListOptions{})

Check failure on line 1226 in container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

Filters is missing in NetworkListOptions (exhaustruct)
for _, networkResource := range networkResources {
logrus.Infof("Information about network '%v' that exists: %v", networkResource.Name, networkResource)
if networkResource.ID == networkId {
logrus.Infof("The network we are trying to connect to exists right before connection.")
}
}

err = manager.dockerClient.NetworkConnect(
ctx,
networkId,
Expand Down Expand Up @@ -1738,7 +1797,7 @@
portMap[containerPort] = []nat.PortBinding{
// Leaving this struct empty will cause Docker to automatically choose an interface IP & port on the host machine
{
HostIP: "",
HostIP: "0.0.0.0",
HostPort: "",
},
}
Expand Down Expand Up @@ -1773,6 +1832,7 @@
securityOptStr := string(securityOpt)
securityOptsSlice = append(securityOptsSlice, securityOptStr)
}
securityOptsSlice = append(securityOptsSlice, "")

Check failure on line 1835 in container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

ineffectual assignment to securityOptsSlice (ineffassign)

extraHosts := []string{}
if needsToAccessDockerHostMachine {
Expand Down Expand Up @@ -1875,21 +1935,25 @@
Privileged: false,
PublishAllPorts: false,
ReadonlyRootfs: false,
SecurityOpt: securityOptsSlice,
StorageOpt: nil,
Tmpfs: nil,
UTSMode: "",
UsernsMode: "",
ShmSize: 0,
Sysctls: nil,
Runtime: "",
ConsoleSize: [2]uint{},
Isolation: "",
Resources: resources,
Mounts: nil,
MaskedPaths: nil,
ReadonlyPaths: nil,
Init: &useInit,
//SecurityOpt: securityOptsSlice,
SecurityOpt: []string{
"label=disable", // Disables SELinux
"apparmor:unconfined", // Disables AppArmor
},
StorageOpt: nil,
Tmpfs: nil,
UTSMode: "",
UsernsMode: "",
ShmSize: 0,
Sysctls: nil,
Runtime: "",
ConsoleSize: [2]uint{},
Isolation: "",
Resources: resources,
Mounts: nil,
MaskedPaths: nil,
ReadonlyPaths: nil,
Init: &useInit,
}
return containerHostConfigPtr, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (provider *GitPackageContentProvider) StorePackageContents(packageId string

tempFile, err := os.CreateTemp(defaultTmpDir, temporaryArchiveFilePattern)
if err != nil {
return "", startosis_errors.NewInterpretationError("An error occurred while creating temporary file to write compressed '%v' to", packageId)
return "", startosis_errors.WrapWithInterpretationError(err, "An error occurred while creating temporary file to write compressed '%v' to temporary directory '%v' with temporary archive file pattern '%v'.", packageId, defaultTmpDir, temporaryArchiveFilePattern)
}
defer os.Remove(tempFile.Name())

Expand Down
15 changes: 15 additions & 0 deletions enclave-manager/local/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/kurtosis-tech/kurtosis/enclave-manager/local

go 1.20
replace (
github.com/kurtosis-tech/kurtosis/enclave-manager => ../server
github.com/kurtosis-tech/kurtosis/contexts-config-store => ../../contexts-config-store
github.com/kurtosis-tech/kurtosis/kurtosis_version => ../../kurtosis_version
)

require (
github.com/kurtosis-tech/kurtosis/enclave-manager v0.0.0-20230828153722-32770ca96513
github.com/sirupsen/logrus v1.9.3
)

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
15 changes: 15 additions & 0 deletions enclave-manager/local/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading