Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
InfraKit
========

[![Circle
CI](https://circleci.com/gh/docker/infrakit.png?style=shield&circle-token=50d2063f283f98b7d94746416c979af3102275b5)](https://circleci.com/gh/docker/infrakit)
[![Circle CI](https://circleci.com/gh/docker/infrakit.png?style=shield&circle-token=50d2063f283f98b7d94746416c979af3102275b5)](https://circleci.com/gh/docker/infrakit)
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/infrakit)](https://goreportcard.com/report/github.com/docker/infrakit)
[![codecov.io](https://codecov.io/github/docker/infrakit/coverage.svg?branch=master&token=z08ZKeIJfA)](https://codecov.io/github/docker/infrakit?branch=master)

_InfraKit_ is a toolkit for creating and managing declarative, self-healing infrastructure.
Expand Down
9 changes: 5 additions & 4 deletions cmd/cli/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/infrakit/pkg/launch/os"
"github.com/docker/infrakit/pkg/plugin"
"github.com/docker/infrakit/pkg/template"
"github.com/docker/infrakit/pkg/types"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -63,10 +64,10 @@ func pluginCommand(plugins func() discovery.Plugins) *cobra.Command {
return err
}

configs := launch.Config([]byte(view))
configs := types.AnyString(view)

parsedRules := []launch.Rule{}
err = configs.Unmarshal(&parsedRules)
err = configs.Decode(&parsedRules)
if err != nil {
return err
}
Expand Down Expand Up @@ -107,11 +108,11 @@ func pluginCommand(plugins func() discovery.Plugins) *cobra.Command {
name := pluginToStart
ch <- launch.StartPlugin{
Plugin: plugin.Name(name),
Started: func(config *launch.Config) {
Started: func(config *types.Any) {
fmt.Println(name, "started.")
wait.Done()
},
Error: func(config *launch.Config, err error) {
Error: func(config *types.Any, err error) {
fmt.Println("Error starting", name, "err=", err)
wait.Done()
},
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/group.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Group plugin API

<!-- SOURCE-CHECKSUM pkg/spi/group/* 4bc86b2ae0893db92f880ab4bb2479b5def55746 -->
<!-- SOURCE-CHECKSUM pkg/spi/group/* 98638b90e25c24c9c750b61d8a288ee332977214 -->

## API

Expand Down
4 changes: 2 additions & 2 deletions pkg/discovery/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func TestDirDiscovery(t *testing.T) {

blockWhileFileExists(path2)

p, err = discover.Find(plugin.Name(name1))
_, err = discover.Find(plugin.Name(name1))
require.Error(t, err)

p, err = discover.Find(plugin.Name(name2))
_, err = discover.Find(plugin.Name(name2))
require.Error(t, err)

list, err := discover.List()
Expand Down
7 changes: 1 addition & 6 deletions pkg/example/flavor/combo/flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ func (f flavorCombo) Prepare(
return inst, err
}

var props json.RawMessage
if pluginSpec.Properties != nil {
props = *pluginSpec.Properties
}

flavorOutput, err := plugin.Prepare(props, clone, allocation)
flavorOutput, err := plugin.Prepare(types.RawMessage(pluginSpec.Properties), clone, allocation)
if err != nil {
return inst, err
}
Expand Down
45 changes: 0 additions & 45 deletions pkg/launch/config.go

This file was deleted.

6 changes: 5 additions & 1 deletion pkg/launch/exec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package launch

import (
"github.com/docker/infrakit/pkg/types"
)

// Exec is a service that is able to start plugins based on different
// mechanisms from running local binary to pulling and running docker containers or engine plugins
type Exec interface {
Expand All @@ -14,5 +18,5 @@ type Exec interface {
// status of the plugin.
// The client can receive and block on the returned channel
// and add optional timeout in its own select statement.
Exec(name string, config *Config) (<-chan error, error)
Exec(name string, config *types.Any) (<-chan error, error)
}
15 changes: 8 additions & 7 deletions pkg/launch/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/pkg/plugin"
"github.com/docker/infrakit/pkg/types"
)

var errNoConfig = errors.New("no-counfig")
var errNoConfig = errors.New("no-config")

// ExecRule encapsulates what's required to exec a plugin
type ExecRule struct {
// Exec is the name of the exec to use to start the plugin
Exec string
// Properties is the properties for the executor
Properties *Config
Properties *types.Any
}

// Rule provides the instructions on starting the plugin
Expand Down Expand Up @@ -58,17 +59,17 @@ func NewMonitor(l Exec, rules []Rule) *Monitor {
// StartPlugin is the command to start a plugin
type StartPlugin struct {
Plugin plugin.Name
Started func(*Config)
Error func(*Config, error)
Started func(*types.Any)
Error func(*types.Any, error)
}

func (s StartPlugin) reportError(config *Config, e error) {
func (s StartPlugin) reportError(config *types.Any, e error) {
if s.Error != nil {
go s.Error(config, e)
}
}

func (s StartPlugin) reportSuccess(config *Config) {
func (s StartPlugin) reportSuccess(config *types.Any) {
if s.Started != nil {
go s.Started(config)
}
Expand Down Expand Up @@ -111,7 +112,7 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) {
continue loop
}

configCopy := &Config{}
configCopy := types.AnyBytes(nil)
if r.Launch.Properties != nil {
*configCopy = *r.Launch.Properties
}
Expand Down
46 changes: 16 additions & 30 deletions pkg/launch/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package launch
import (
"testing"

"github.com/docker/infrakit/pkg/types"
"github.com/stretchr/testify/require"
)

Expand All @@ -14,16 +15,16 @@ type testConfig struct {
type testLauncher struct {
name string
t *testing.T
callback func(*Config)
callback func(*types.Any)
}

func (l *testLauncher) Name() string {
return l.name
}

func (l *testLauncher) Exec(name string, config *Config) (<-chan error, error) {
func (l *testLauncher) Exec(name string, config *types.Any) (<-chan error, error) {
rule := testConfig{}
err := config.Unmarshal(&rule)
err := config.Decode(&rule)
if err != nil {
return nil, err
}
Expand All @@ -47,7 +48,7 @@ func TestMonitorLoopNoRules(t *testing.T) {

input <- StartPlugin{
Plugin: "test",
Error: func(config *Config, e error) {
Error: func(config *types.Any, e error) {
errChan <- e
},
}
Expand All @@ -60,28 +61,23 @@ func TestMonitorLoopNoRules(t *testing.T) {

func TestMonitorLoopValidRule(t *testing.T) {

raw := &Config{}
config := &testConfig{
Cmd: "hello",
Args: []string{"world", "hello"},
}

rawErr := raw.Marshal(config)
require.NoError(t, rawErr)
require.True(t, len([]byte(*raw)) > 0)

var receivedArgs *Config
var receivedArgs *types.Any
rule := Rule{
Plugin: "hello",
Launch: ExecRule{
Exec: "test",
Properties: raw,
Properties: types.AnyValueMust(config),
},
}
monitor := NewMonitor(&testLauncher{
name: "test",
t: t,
callback: func(c *Config) {
callback: func(c *types.Any) {
receivedArgs = c
},
}, []Rule{rule})
Expand All @@ -93,45 +89,38 @@ func TestMonitorLoopValidRule(t *testing.T) {
started := make(chan interface{})
input <- StartPlugin{
Plugin: "hello",
Started: func(config *Config) {
Started: func(config *types.Any) {
close(started)
},
}

<-started

expected := &Config{}
err = expected.Marshal(config)
require.NoError(t, err)

expected := types.AnyValueMust(config)
require.Equal(t, *expected, *receivedArgs)

monitor.Stop()
}

func TestMonitorLoopRuleLookupBehavior(t *testing.T) {
raw := &Config{}

config := &testConfig{
Cmd: "hello",
Args: []string{"world", "hello"},
}

rawErr := raw.Marshal(config)
require.NoError(t, rawErr)
require.True(t, len([]byte(*raw)) > 0)

var receivedArgs *Config
var receivedArgs *types.Any
rule := Rule{
Plugin: "hello",
Launch: ExecRule{
Exec: "test",
Properties: raw,
Properties: types.AnyValueMust(config),
},
}
monitor := NewMonitor(&testLauncher{
name: "test",
t: t,
callback: func(c *Config) {
callback: func(c *types.Any) {
receivedArgs = c
},
}, []Rule{rule})
Expand All @@ -143,17 +132,14 @@ func TestMonitorLoopRuleLookupBehavior(t *testing.T) {
started := make(chan interface{})
input <- StartPlugin{
Plugin: "hello",
Started: func(config *Config) {
Started: func(config *types.Any) {
close(started)
},
}

<-started

expected := &Config{}
err = expected.Marshal(config)
require.NoError(t, err)

expected := types.AnyValueMust(config)
require.Equal(t, *expected, *receivedArgs)

monitor.Stop()
Expand Down
3 changes: 2 additions & 1 deletion pkg/launch/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package launch

import (
log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/pkg/types"
)

type noOp int
Expand All @@ -17,7 +18,7 @@ func (n noOp) Name() string {
}

// Launch starts the plugin given the name
func (n noOp) Exec(name string, config *Config) (<-chan error, error) {
func (n noOp) Exec(name string, config *types.Any) (<-chan error, error) {
log.Infoln("NO-OP Exec: not automatically starting plugin", name, "args=", config)

starting := make(chan error)
Expand Down
6 changes: 3 additions & 3 deletions pkg/launch/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package os
import (
"sync"

"github.com/docker/infrakit/pkg/launch"
"github.com/docker/infrakit/pkg/types"
)

// LaunchConfig is the rule for how to start up a os process.
Expand Down Expand Up @@ -45,10 +45,10 @@ func (l *Launcher) Name() string {
// The command is run in the background / asynchronously. The returned read channel
// stops blocking as soon as the command completes (which uses shell to run the real task in
// background).
func (l *Launcher) Exec(name string, config *launch.Config) (<-chan error, error) {
func (l *Launcher) Exec(name string, config *types.Any) (<-chan error, error) {

launchConfig := &LaunchConfig{}
if err := config.Unmarshal(launchConfig); err != nil {
if err := config.Decode(launchConfig); err != nil {
return nil, err
}

Expand Down
Loading