Skip to content

Commit

Permalink
Enable eru core to make use of eru systemd runtime (#418)
Browse files Browse the repository at this point in the history
* use docker systemd engine to replace ssh engine

* refactor systemd engine

Co-authored-by: nyanpassu <[email protected]>
Co-authored-by: CMGS <[email protected]>
  • Loading branch information
3 people authored May 22, 2021
1 parent 582a6f0 commit 7f382e2
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 626 deletions.
7 changes: 5 additions & 2 deletions engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ const (
root = "root"
)

type rawArgs struct {
// RawArgs means some underlay args
type RawArgs struct {
PidMode dockercontainer.PidMode `json:"pid_mod"`
StorageOpt map[string]string `json:"storage_opt"`
CapAdd []string `json:"cap_add"`
CapDrop []string `json:"cap_drop"`
Ulimits []*units.Ulimit `json:"ulimits"`
Runtime string `json:"runtime"`
}

// VirtualizationCreate create a workload
Expand Down Expand Up @@ -125,7 +127,7 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir
Tty: opts.Stdin,
}

rArgs := &rawArgs{StorageOpt: map[string]string{}}
rArgs := &RawArgs{StorageOpt: map[string]string{}}
if len(opts.RawArgs) > 0 {
if err := json.Unmarshal(opts.RawArgs, rArgs); err != nil {
return r, err
Expand Down Expand Up @@ -188,6 +190,7 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir
Sysctls: opts.Sysctl,
PidMode: rArgs.PidMode,
StorageOpt: rArgs.StorageOpt,
Runtime: rArgs.Runtime,
}

if hostConfig.NetworkMode.IsBridge() {
Expand Down
2 changes: 1 addition & 1 deletion engine/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var engines = map[string]factory{
docker.SockPrefixKey: docker.MakeClient,
virt.HTTPPrefixKey: virt.MakeClient,
virt.GRPCPrefixKey: virt.MakeClient,
systemd.SSHPrefixKey: systemd.MakeClient,
systemd.TCPPrefix: systemd.MakeClient,
fakeengine.PrefixKey: fakeengine.MakeClient,
}

Expand Down
26 changes: 26 additions & 0 deletions engine/systemd/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package systemd

import (
"context"
"encoding/json"

"github.com/projecteru2/core/engine/docker"
enginetypes "github.com/projecteru2/core/engine/types"
)

// VirtualizationCreate create a workload
func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (*enginetypes.VirtualizationCreated, error) { // nolintlint
rArgs := &docker.RawArgs{StorageOpt: map[string]string{}}
if len(opts.RawArgs) > 0 {
if err := json.Unmarshal(opts.RawArgs, rArgs); err != nil {
return nil, err
}
}
rArgs.Runtime = e.config.Systemd.Runtime
b, err := json.Marshal(rArgs)
if err != nil {
return nil, err
}
opts.RawArgs = b
return e.API.VirtualizationCreate(ctx, opts)
}
6 changes: 3 additions & 3 deletions engine/systemd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
)

// Execute executes a cmd and attaches stdio
func (s *SSHClient) Execute(ctx context.Context, target string, config *enginetypes.ExecConfig) (execID string, stdout io.ReadCloser, stderr io.ReadCloser, writer io.WriteCloser, err error) {
func (e *Engine) Execute(ctx context.Context, target string, config *enginetypes.ExecConfig) (execID string, stdout io.ReadCloser, stderr io.ReadCloser, writer io.WriteCloser, err error) {
err = types.ErrEngineNotImplemented
return
}

// ExecResize resize the terminal size
func (s *SSHClient) ExecResize(ctx context.Context, execID string, height, width uint) (err error) {
func (e *Engine) ExecResize(ctx context.Context, execID string, height, width uint) (err error) {
err = types.ErrEngineNotImplemented
return
}

// ExecExitCode fetches exceuction exit code
func (s *SSHClient) ExecExitCode(ctx context.Context, execID string) (execCode int, err error) {
func (e *Engine) ExecExitCode(ctx context.Context, execID string) (execCode int, err error) {
err = types.ErrEngineNotImplemented
return
}
15 changes: 0 additions & 15 deletions engine/systemd/helper.go

This file was deleted.

63 changes: 2 additions & 61 deletions engine/systemd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,13 @@ import (
"github.com/projecteru2/core/types"
)

// ImageList lists image
func (s *SSHClient) ImageList(ctx context.Context, image string) (images []*enginetypes.Image, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageRemove removes image
func (s *SSHClient) ImageRemove(ctx context.Context, image string, force, prune bool) (layers []string, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImagesPrune prunes
func (s *SSHClient) ImagesPrune(ctx context.Context) (err error) {
err = types.ErrEngineNotImplemented
return
}

// ImagePull pulls image
func (s *SSHClient) ImagePull(ctx context.Context, ref string, all bool) (rc io.ReadCloser, err error) {
return
}

// ImagePush pushes image
func (s *SSHClient) ImagePush(ctx context.Context, ref string) (rc io.ReadCloser, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageBuild builds image
func (s *SSHClient) ImageBuild(ctx context.Context, input io.Reader, refs []string) (reader io.ReadCloser, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageBuildFromExist won't work for systemd engine
func (s *SSHClient) ImageBuildFromExist(ctx context.Context, ID, name, user string) (imageID string, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageBuildCachePrune prunes cache
func (s *SSHClient) ImageBuildCachePrune(ctx context.Context, all bool) (reclaimedInBytes uint64, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageLocalDigests gets image local digest
func (s *SSHClient) ImageLocalDigests(ctx context.Context, image string) (digests []string, err error) {
err = types.ErrEngineNotImplemented
return
}

// ImageRemoteDigest gets image remote digest
func (s *SSHClient) ImageRemoteDigest(ctx context.Context, image string) (digest string, err error) {
err = types.ErrEngineNotImplemented
return
}

// BuildRefs builds images refs
func (s *SSHClient) BuildRefs(ctx context.Context, name string, tags []string) (refs []string) {
func (e *Engine) BuildRefs(ctx context.Context, name string, tags []string) (refs []string) {
return
}

// BuildContent builds image content
func (s *SSHClient) BuildContent(ctx context.Context, scm coresource.Source, opts *enginetypes.BuildContentOptions) (dir string, reader io.Reader, err error) {
func (e *Engine) BuildContent(ctx context.Context, scm coresource.Source, opts *enginetypes.BuildContentOptions) (dir string, reader io.Reader, err error) {
err = types.ErrEngineNotImplemented
return
}
6 changes: 3 additions & 3 deletions engine/systemd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
)

// NetworkConnect connects target netloc
func (s *SSHClient) NetworkConnect(ctx context.Context, network, target, ipv4, ipv6 string) (subnets []string, err error) {
func (e *Engine) NetworkConnect(ctx context.Context, network, target, ipv4, ipv6 string) (subnets []string, err error) {
err = types.ErrEngineNotImplemented
return
}

// NetworkDisconnect disconnects target netloc
func (s *SSHClient) NetworkDisconnect(ctx context.Context, network, target string, force bool) (err error) {
func (e *Engine) NetworkDisconnect(ctx context.Context, network, target string, force bool) (err error) {
err = types.ErrEngineNotImplemented
return
}

// NetworkList lists networks
func (s *SSHClient) NetworkList(ctx context.Context, driver []string) (networks []*enginetypes.Network, err error) {
func (e *Engine) NetworkList(ctx context.Context, driver []string) (networks []*enginetypes.Network, err error) {
err = types.ErrEngineNotImplemented
return
}
12 changes: 12 additions & 0 deletions engine/systemd/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package systemd

import (
"context"

"github.com/projecteru2/core/types"
)

// ResourceValidate validates resources
func (e *Engine) ResourceValidate(ctx context.Context, cpu float64, cpumap map[string]int64, memory, storage int64) (err error) {
return types.ErrEngineNotImplemented
}
59 changes: 0 additions & 59 deletions engine/systemd/status.go

This file was deleted.

Loading

0 comments on commit 7f382e2

Please sign in to comment.