Skip to content

Commit

Permalink
Merge branch 'clean_agent' into 'master'
Browse files Browse the repository at this point in the history
remove agent macvlan support

See merge request !124
  • Loading branch information
CMGS committed Aug 3, 2017
2 parents a5061f9 + e13050c commit ccb83d7
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 89 deletions.
70 changes: 1 addition & 69 deletions cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"strings"
"text/template"

log "github.com/Sirupsen/logrus"
enginetypes "github.com/docker/docker/api/types"
Expand All @@ -19,28 +18,6 @@ import (
"gopkg.in/yaml.v2"
)

const launcherScript = `#! /bin/sh
echo 32768 > /writable-proc/sys/net/core/somaxconn
echo 1 > /writable-proc/sys/vm/overcommit_memory
chmod 777 /dev/stdout
chmod 777 /dev/stderr
neednetwork=$1
if [ $neednetwork = "network" ]; then
# wait for macvlan
while ( ! ip addr show | grep 'UP' | grep 'vnbe'); do
echo -n o
sleep .5
done
fi
sleep 1
shift
{{.Command}}
`

const dockerFile = `ARG Base
FROM ${Base}
ARG Appdir
Expand All @@ -53,8 +30,6 @@ ENV Appname ${Appname}
ENV Appdir ${Appdir}
ENV ERU 1
ADD ${Reponame} ${Appdir}/${Appname}
ADD launcher /usr/local/bin/launcher
ADD launcheroot /usr/local/bin/launcheroot
WORKDIR ${Appdir}/${Appname}
RUN useradd -u ${UID} -d /nonexistent -s /sbin/nologin -U ${Appname}
RUN chown -R ${UID} ${Appdir}/${Appname}
Expand Down Expand Up @@ -106,8 +81,6 @@ func getRandomNode(c *calcium, podname string) (*types.Node, error) {
//
// buildDir ├─ :appname ├─ code
// ├─ Dockerfile
// ├─ launcher
// ├─ launcheroot
func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *types.BuildImageMessage, error) {
ch := make(chan *types.BuildImageMessage)

Expand Down Expand Up @@ -169,11 +142,8 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
}
}

// create launcher scripts and dockerfile
// create dockerfile
rs := richSpecs{specs, "", strings.TrimRight(c.config.AppDir, "/"), uid}
if err := createLauncher(buildDir, rs); err != nil {
return ch, err
}
if err := createDockerfile(buildDir); err != nil {
return ch, err
}
Expand Down Expand Up @@ -277,44 +247,6 @@ func createTarStream(path string) (io.ReadCloser, error) {
return archive.TarWithOptions(path, tarOpts)
}

// launcher scripts
func createLauncher(buildDir string, rs richSpecs) error {
launcherScriptTemplate, _ := template.New("launcher script").Parse(launcherScript)

entryCommand := fmt.Sprintf("exec sudo -E -u %s $@", rs.Appname)
entryRootCommand := "exec $@"

f, err := os.Create(filepath.Join(buildDir, "launcher"))
if err != nil {
return err
}
defer f.Close()
rs.Command = entryCommand
launcherScriptTemplate.Execute(f, rs)
if err := f.Sync(); err != nil {
return err
}
if err := f.Chmod(0755); err != nil {
return err
}

fr, err := os.Create(filepath.Join(buildDir, "launcheroot"))
if err != nil {
return err
}
defer fr.Close()
rs.Command = entryRootCommand
launcherScriptTemplate.Execute(fr, rs)
if err := fr.Sync(); err != nil {
return err
}
if err := fr.Chmod(0755); err != nil {
return err
}

return nil
}

// Dockerfile
func createDockerfile(buildDir string) error {
f, err := os.Create(filepath.Join(buildDir, "Dockerfile"))
Expand Down
15 changes: 0 additions & 15 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,6 @@ func (c *calcium) makeContainerOptions(index int, quota map[string]int, specs ty
}
// command and user
slices := utils.MakeCommandLineArgs(entry.Command + " " + opts.ExtraArgs)

// if not use raw to deploy, or use agent as network manager
// we need to use our own script to start command
if !opts.Raw && c.network.Type() == "agent" {
starter, needNetwork := "launcher", "network"
if entry.Privileged != "" {
starter = "launcheroot"
}
if len(opts.Networks) == 0 {
needNetwork = "nonetwork"
}
slices = append([]string{fmt.Sprintf("/usr/local/bin/%s", starter), needNetwork}, slices...)
// use default empty value, as root
user = "root"
}
cmd := engineslice.StrSlice(slices)

// calculate CPUShares and CPUSet
Expand Down
1 change: 0 additions & 1 deletion core.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bind: ":5001"
agent_port: "12345"
appdir: "/home"
permdir: "/mnt/mfs/permdirs"
backupdir: "/mnt/mfs/backupdirs"
Expand Down
1 change: 0 additions & 1 deletion network/calico/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type titanium struct{}

// type of the network manager
// if set to "plugin", then it will act like a plugin
// if set to "agent", then it will act like an agent
// main difference is the order of connect/disconnect
func (t *titanium) Type() string {
return "plugin"
Expand Down
1 change: 0 additions & 1 deletion rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func initConfig(mStore *mockstore.MockStore) (types.Config, *vibranium) {

config := types.Config{
Bind: ":5001", // HTTP API address
AgentPort: ":12345", // Agent HTTP port, may not be used
AppDir: "/tmp", // App directory inside container
PermDir: "/tmp", // Permanent dir on host
BackupDir: "/tmp", // Backup dir on host
Expand Down
1 change: 0 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
// Config holds eru-core config
type Config struct {
Bind string `yaml:"bind"` // HTTP API address
AgentPort string `yaml:"agent_port"` // Agent HTTP port, may not be used
AppDir string `yaml:"appdir"` // App directory inside container
PermDir string `yaml:"permdir"` // Permanent dir on host
BackupDir string `yaml:"backupdir"` // Backup dir on host
Expand Down
2 changes: 1 addition & 1 deletion types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type DeployOptions struct {
Memory int64 // Memory for container, in bytes
Env []string // Env for container
Networks map[string]string // Network names and specified IPs
Raw bool // If use raw, launcher won't be used
Raw bool // Raw mode, use docker image online
Debug bool // debug mode, use syslog as log driver
OpenStdin bool // OpenStdin for container
}
Expand Down

0 comments on commit ccb83d7

Please sign in to comment.