mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-24 15:53:24 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
65c2cb0732 | |||
44df1cef98 | |||
881f5171ee | |||
970015ac85 | |||
283e8ed2c1 |
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
var providerCmd = &cobra.Command{
|
var providerCmd = &cobra.Command{
|
||||||
Use: "provider",
|
Use: "provider",
|
||||||
Short: "Run the faasd faas-provider",
|
Short: "Run the faasd-provider",
|
||||||
RunE: runProvider,
|
RunE: runProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func runProvider(_ *cobra.Command, _ []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("faas-containerd starting..\tService Timeout: %s\n", config.WriteTimeout.String())
|
log.Printf("faasd-provider starting..\tService Timeout: %s\n", config.WriteTimeout.String())
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -217,7 +217,7 @@ func makeServiceDefinitions(archSuffix string) []pkg.Service {
|
|||||||
Name: "gateway",
|
Name: "gateway",
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"basic_auth=true",
|
"basic_auth=true",
|
||||||
"functions_provider_url=http://faas-containerd:8081/",
|
"functions_provider_url=http://faasd-provider:8081/",
|
||||||
"direct_functions=false",
|
"direct_functions=false",
|
||||||
"read_timeout=60s",
|
"read_timeout=60s",
|
||||||
"write_timeout=60s",
|
"write_timeout=60s",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=faasd
|
Description=faasd
|
||||||
After=faas-containerd.service
|
After=faasd-provider.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
MemoryLimit=500M
|
MemoryLimit=500M
|
||||||
|
@ -27,6 +27,20 @@ const (
|
|||||||
faasdNamespace = "default"
|
faasdNamespace = "default"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
Image string
|
||||||
|
Env []string
|
||||||
|
Name string
|
||||||
|
Mounts []Mount
|
||||||
|
Caps []string
|
||||||
|
Args []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mount struct {
|
||||||
|
Src string
|
||||||
|
Dest string
|
||||||
|
}
|
||||||
|
|
||||||
type Supervisor struct {
|
type Supervisor struct {
|
||||||
client *containerd.Client
|
client *containerd.Client
|
||||||
cni gocni.CNI
|
cni gocni.CNI
|
||||||
@ -35,12 +49,12 @@ type Supervisor struct {
|
|||||||
func NewSupervisor(sock string) (*Supervisor, error) {
|
func NewSupervisor(sock string) (*Supervisor, error) {
|
||||||
client, err := containerd.New(sock)
|
client, err := containerd.New(sock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cni, err := cninetwork.InitNetwork()
|
cni, err := cninetwork.InitNetwork()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Supervisor{
|
return &Supervisor{
|
||||||
@ -49,28 +63,6 @@ func NewSupervisor(sock string) (*Supervisor, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Supervisor) Close() {
|
|
||||||
defer s.client.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Supervisor) Remove(svcs []Service) error {
|
|
||||||
ctx := namespaces.WithNamespace(context.Background(), faasdNamespace)
|
|
||||||
|
|
||||||
for _, svc := range svcs {
|
|
||||||
err := cninetwork.DeleteCNINetwork(ctx, s.cni, s.client, svc.Name)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[Delete] error removing CNI network for %s, %s\n", svc.Name, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = service.Remove(ctx, s.client, svc.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Supervisor) Start(svcs []Service) error {
|
func (s *Supervisor) Start(svcs []Service) error {
|
||||||
ctx := namespaces.WithNamespace(context.Background(), faasdNamespace)
|
ctx := namespaces.WithNamespace(context.Background(), faasdNamespace)
|
||||||
|
|
||||||
@ -82,7 +74,7 @@ func (s *Supervisor) Start(svcs []Service) error {
|
|||||||
}
|
}
|
||||||
hosts := fmt.Sprintf(`
|
hosts := fmt.Sprintf(`
|
||||||
127.0.0.1 localhost
|
127.0.0.1 localhost
|
||||||
%s faas-containerd`, gw)
|
%s faasd-provider`, gw)
|
||||||
|
|
||||||
writeHostsErr := ioutil.WriteFile(path.Join(wd, "hosts"),
|
writeHostsErr := ioutil.WriteFile(path.Join(wd, "hosts"),
|
||||||
[]byte(hosts), workingDirectoryPermission)
|
[]byte(hosts), workingDirectoryPermission)
|
||||||
@ -90,7 +82,6 @@ func (s *Supervisor) Start(svcs []Service) error {
|
|||||||
if writeHostsErr != nil {
|
if writeHostsErr != nil {
|
||||||
return fmt.Errorf("cannot write hosts file: %s", writeHostsErr)
|
return fmt.Errorf("cannot write hosts file: %s", writeHostsErr)
|
||||||
}
|
}
|
||||||
// os.Chown("hosts", 101, 101)
|
|
||||||
|
|
||||||
images := map[string]containerd.Image{}
|
images := map[string]containerd.Image{}
|
||||||
|
|
||||||
@ -211,6 +202,28 @@ func (s *Supervisor) Start(svcs []Service) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) Close() {
|
||||||
|
defer s.client.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) Remove(svcs []Service) error {
|
||||||
|
ctx := namespaces.WithNamespace(context.Background(), faasdNamespace)
|
||||||
|
|
||||||
|
for _, svc := range svcs {
|
||||||
|
err := cninetwork.DeleteCNINetwork(ctx, s.cni, s.client, svc.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[Delete] error removing CNI network for %s, %s\n", svc.Name, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = service.Remove(ctx, s.client, svc.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func withOCIArgs(args []string) oci.SpecOpts {
|
func withOCIArgs(args []string) oci.SpecOpts {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
return oci.WithProcessArgs(args...)
|
return oci.WithProcessArgs(args...)
|
||||||
@ -220,17 +233,3 @@ func withOCIArgs(args []string) oci.SpecOpts {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
Image string
|
|
||||||
Env []string
|
|
||||||
Name string
|
|
||||||
Mounts []Mount
|
|
||||||
Caps []string
|
|
||||||
Args []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Mount struct {
|
|
||||||
Src string
|
|
||||||
Dest string
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user