Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Move to external exec package
Browse files Browse the repository at this point in the history
There is an external package which is also used by k3sup that
can be used here instead of maintaining two copies of the
library.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 24, 2019
1 parent b35f07e commit 2b2ba70
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 205 deletions.
4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "gopkg.in/yaml.v2"
version = "2.2.3"

[[constraint]]
name = "github.com/alexellis/go-execute"
version = "0.1.1"

[prune]
go-tests = true
unused-packages = true
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"time"

"github.com/openfaas-incubator/ofc-bootstrap/pkg/execute"
"github.com/alexellis/go-execute"
"github.com/openfaas-incubator/ofc-bootstrap/pkg/ingress"
"github.com/openfaas-incubator/ofc-bootstrap/pkg/stack"
"github.com/openfaas-incubator/ofc-bootstrap/pkg/tls"
Expand Down
89 changes: 0 additions & 89 deletions pkg/execute/exec.go

This file was deleted.

82 changes: 0 additions & 82 deletions pkg/execute/exec_test.go

This file was deleted.

36 changes: 19 additions & 17 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package ingress

import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"

"github.com/openfaas-incubator/ofc-bootstrap/pkg/execute"
"github.com/alexellis/go-execute"
"github.com/openfaas-incubator/ofc-bootstrap/pkg/types"
)

Expand Down Expand Up @@ -44,25 +45,11 @@ func Apply(plan types.Plan) error {
return nil
}

func applyTemplate(templateFileName string, templateValues IngressTemplate) ([]byte, error) {
data, err := ioutil.ReadFile(templateFileName)
if err != nil {
return nil, err
}
t := template.Must(template.New(templateFileName).Parse(string(data)))

buffer := new(bytes.Buffer)

executeErr := t.Execute(buffer, templateValues)

return buffer.Bytes(), executeErr
}

func apply(source string, name string, ingress IngressTemplate) error {

generatedData, err := applyTemplate("templates/k8s/"+source, ingress)
if err != nil {
return err
return fmt.Errorf("unable to read template %s (%s), error: %q", name, "templates/k8s/"+source, err)
}

tempFilePath := "tmp/generated-ingress-" + name + ".yaml"
Expand All @@ -80,7 +67,8 @@ func apply(source string, name string, ingress IngressTemplate) error {
}

execTask := execute.ExecTask{
Command: "kubectl apply -f " + tempFilePath,
Command: "kubectl",
Args: []string{"apply", "-f", tempFilePath},
Shell: false,
}

Expand All @@ -93,3 +81,17 @@ func apply(source string, name string, ingress IngressTemplate) error {

return nil
}

func applyTemplate(templateFileName string, templateValues IngressTemplate) ([]byte, error) {
data, err := ioutil.ReadFile(templateFileName)
if err != nil {
return nil, err
}
t := template.Must(template.New(templateFileName).Parse(string(data)))

buffer := new(bytes.Buffer)

executeErr := t.Execute(buffer, templateValues)

return buffer.Bytes(), executeErr
}
28 changes: 14 additions & 14 deletions pkg/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ type stackConfig struct {
GitHub bool
}

func applyTemplate(templateFileName string, templateType interface{}) ([]byte, error) {
data, err := ioutil.ReadFile(templateFileName)
if err != nil {
return nil, err
}
t := template.Must(template.New(templateFileName).Parse(string(data)))

buffer := new(bytes.Buffer)

executeErr := t.Execute(buffer, templateType)

return buffer.Bytes(), executeErr
}

func generateTemplate(fileName string, plan types.Plan, templateType interface{}) error {

generatedData, err := applyTemplate("templates/"+fileName+".yml", templateType)
Expand All @@ -147,3 +133,17 @@ func generateTemplate(fileName string, plan types.Plan, templateType interface{}

return nil
}

func applyTemplate(templateFileName string, templateType interface{}) ([]byte, error) {
data, err := ioutil.ReadFile(templateFileName)
if err != nil {
return nil, err
}
t := template.Must(template.New(templateFileName).Parse(string(data)))

buffer := new(bytes.Buffer)

executeErr := t.Execute(buffer, templateType)

return buffer.Bytes(), executeErr
}
2 changes: 1 addition & 1 deletion pkg/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"os"

"github.com/openfaas-incubator/ofc-bootstrap/pkg/execute"
"github.com/alexellis/go-execute"
"github.com/openfaas-incubator/ofc-bootstrap/pkg/types"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/types/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"os"

"github.com/openfaas-incubator/ofc-bootstrap/pkg/execute"
"github.com/alexellis/go-execute"
)

func CreateDockerSecret(kvn KeyValueNamespaceTuple) string {
Expand Down

0 comments on commit 2b2ba70

Please sign in to comment.