diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..15e53b1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,11 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.16 + + working_directory: /go/src/github.com/joyrex2001/kubedock + steps: + - checkout + - run: go vet ./... + - run: go test -v ./... diff --git a/README.md b/README.md index 270ad92..e5e046f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Kubedock is an experimental implementation of the docker api that will orchestra The current implementation is limited, but able to run containers that just expose ports, copy resources towards the container, or mount volumes. Containers that 'just' expose ports, require logging and copy resources to running containers will probably work. Volume mounting is implemented by copying the local volume towards the container, changes made by the container to this volume are not synced back. All data is considered emphemeral. +## Quick start + Running this locally with a testcontainers enabled unit-test requires to run kubedock (`make run`). After that start the unit tests in another termninal with the below environment variables set, for example: ```bash @@ -13,3 +15,29 @@ mvn test ``` The default configuration for kubedock is to orchestrate in the default kubernetes namespace, this can be configured with the `NAMESPACE` environment variable (or via the -n argument). The service requires permissions to create Deployments in the namespace. + +To see a complete list of available options: `kubedock --help`. + +## Compatibility + +This project is mainly focussed on getting [testcontainers-java](https://www.testcontainers.org) test running. Therefor it has limited support of the docker api, only the minimum that is typically used in testcontainers-java backed test. + +Most of the below use-cases as described by testcontainers are working: + +* [generic containers](https://www.testcontainers.org/features/creating_container/) +* [networking and communicating with containers](https://www.testcontainers.org/features/networking/) +* [executing commands](https://www.testcontainers.org/features/commands/) +* [waiting for containers to start or be ready](https://www.testcontainers.org/features/startup_and_waits/) +* [files and volumes](https://www.testcontainers.org/features/files/) +* [accessing container logs](https://www.testcontainers.org/features/container_logs/) + +The below use-cases are mostly not working: + +* [advanced networking](https://www.testcontainers.org/features/networking/) +* [creating images on-the-fly](https://www.testcontainers.org/features/creating_images/) +* [ryuk resource reaper](https://www.testcontainers.org/features/configuration/) +* [advanced options](https://www.testcontainers.org/features/advanced_options/) + +## Resource reaping + +kubedock will dynamically create deployments in the configured namespace. If kubedock is requested to delete a container, it will remove the deployment. However, if e.g. a test fails and didn't clean up its started containers, deployments will remain in the namespace. To prevent unused deployments lingering around, kubedock will automatically delete deployments that are older than 5 minutes (default) if it's owned by the current process. If the deployment is not owned by the running process, it will delete it after 10 minutes if the deployment has the label `kubedock=true`. \ No newline at end of file diff --git a/go.mod b/go.mod index e848e26..43f673d 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/go-playground/validator/v10 v10.5.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/go-memdb v1.3.2 - github.com/kisielk/errcheck v1.6.0 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.1.3 @@ -16,11 +15,8 @@ require ( github.com/spf13/viper v1.7.1 github.com/ugorji/go v1.2.5 // indirect golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect - golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect - golang.org/x/mod v0.4.2 // indirect golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 // indirect golang.org/x/text v0.3.6 // indirect - golang.org/x/tools v0.1.0 // indirect k8s.io/api v0.21.0 k8s.io/apimachinery v0.21.0 k8s.io/cli-runtime v0.21.0 diff --git a/go.sum b/go.sum index 8642830..53ef83c 100644 --- a/go.sum +++ b/go.sum @@ -288,8 +288,6 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/errcheck v1.6.0 h1:YTDO4pNy7AUN/021p+JGHycQyYNIyMoenM1YDVK6RlY= -github.com/kisielk/errcheck v1.6.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -488,8 +486,6 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= @@ -498,8 +494,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -578,10 +572,7 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 h1:cdsMqa2nXzqlgs183pHxtvoVwU7CyzaCTAUOg94af4c= golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -639,8 +630,6 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/backend/main.go b/internal/backend/main.go index d97faf9..11dfb65 100644 --- a/internal/backend/main.go +++ b/internal/backend/main.go @@ -42,7 +42,7 @@ type Config struct { InitImage string } -// New will return an ContainerFactory instance. +// New will return an Backend instance. func New(cfg Config) Backend { return &instance{ cli: cfg.Client, diff --git a/internal/util/portforward/randomport_test.go b/internal/util/portforward/randomport_test.go new file mode 100644 index 0000000..07f3dd6 --- /dev/null +++ b/internal/util/portforward/randomport_test.go @@ -0,0 +1,21 @@ +package portforward + +import ( + "testing" +) + +func TestRandomPort(t *testing.T) { + m := map[int]int{} + for i := 0; i < 100; i++ { + p := RandomPort() + if p < 1024 { + t.Errorf("Invalid random port %d", p) + break + } + if _, ok := m[p]; ok { + t.Errorf("Random port collision, port %d already provided", p) + break + } + m[p] = p + } +}