Skip to content

Commit

Permalink
Merge pull request #16 from jstrachan/changes
Browse files Browse the repository at this point in the history
fixes #15 and improve the error reporting if the user omits the fn or flow
  • Loading branch information
jstrachan authored Jan 10, 2017
2 parents 0e31022 + a7272dd commit 5e3be86
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
63 changes: 42 additions & 21 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ const (
)

type debugCmd struct {
kubeclient *kubernetes.Clientset
cmd *cobra.Command
kubeConfigPath string
kubeclient *kubernetes.Clientset
cmd *cobra.Command
kubeConfigPath string

namespace string
kind string
name string
localPort int
remotePort int
chromeDevTools bool
portText string
namespace string
kind string
name string
localPort int
remotePort int
supportsChromeDevTools bool
chromeDevTools bool
portText string

podAction k8sutil.PodAction
debugCmd *exec.Cmd
podAction k8sutil.PodAction
debugCmd *exec.Cmd
}

func init() {
Expand All @@ -74,13 +75,18 @@ func newDebugCmd() *cobra.Command {
handleError(fmt.Errorf("No resource kind argument supplied! Possible values ['fn', 'flow']"))
return
}
p.kind = args[0]
kind, _, err := listOptsForKind(p.kind)
if err != nil {
handleError(err)
return
}
if len(args) < 2 {
handleError(fmt.Errorf("No name specified!"))
handleError(fmt.Errorf("No %s name specified!", kind))
return
}
p.kind = args[0]
p.name = args[1]
err := createKubernetesClient(cmd, p.kubeConfigPath, &p.kubeclient, &p.namespace)
err = createKubernetesClient(cmd, p.kubeConfigPath, &p.kubeclient, &p.namespace)
if err != nil {
handleError(err)
return
Expand All @@ -94,14 +100,14 @@ func newDebugCmd() *cobra.Command {
f.StringVarP(&p.name, "name", "v", "latest", "the version of the connectors to install")
f.IntVarP(&p.localPort, "local-port", "l", 0, "The localhost port to use for debugging or the container's debugging port is used")
f.IntVarP(&p.remotePort, "remote-port", "r", 0, "The remote container port to use for debugging or the container's debugging port is used")
f.BoolVarP(&p.chromeDevTools, "chrome", "c", false, "For node based containers open the Chrome DevTools to debug")
//f.BoolVarP(&p.chromeDevTools, "chrome", "c", false, "For node based containers open the Chrome DevTools to debug")
return cmd
}

func (p *debugCmd) run() error {
name, err := nameForDeployment(p.kubeclient, p.namespace, p.kind, p.name)
if err != nil {
return err
return err
}
portText, err := p.createPortText(p.kind, p.name)
if err != nil {
Expand Down Expand Up @@ -195,6 +201,19 @@ func (p *debugCmd) createPortText(kindText, name string) (string, error) {
}
}
}
annotations := found.Annotations
if kind == runtimeKind && annotations != nil {
flag := annotations[funktion.ChromeDevToolsAnnotation]
if flag == "true" {
p.supportsChromeDevTools = true
} else if len(flag) == 0 {
// TODO handle older nodejs runtimes which don't have the annotation
// remove after next funktion-connectors release!
if found.Name == "nodejs" {
p.supportsChromeDevTools = true
}
}
}
} else if kind == flowKind {
connector := ""
data := found.Labels
Expand Down Expand Up @@ -253,14 +272,14 @@ func (p *debugCmd) viewLog(pod *v1.Pod) error {
return err
}

if p.chromeDevTools {
return p.openChromeDevTools(pod, binaryFile)
if p.supportsChromeDevTools {
return p.findChromeDevToolsURL(pod, binaryFile)
}
}
return nil
}

func (p *debugCmd) openChromeDevTools(pod *v1.Pod, binaryFile string) error {
func (p *debugCmd) findChromeDevToolsURL(pod *v1.Pod, binaryFile string) error {
name := pod.Name

args := []string{"logs", "-f", name}
Expand All @@ -285,7 +304,9 @@ func (p *debugCmd) openChromeDevTools(pod *v1.Pod, binaryFile string) error {
fmt.Printf("\nTo Debug open: %s\n\n", text)
cmdReader.Close()
killCmd(cmd)
browser.OpenURL(text)
if p.chromeDevTools {
browser.OpenURL(text)
}
}
}
}()
Expand Down
4 changes: 4 additions & 0 deletions pkg/funktion/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const (

// Runtime

// ChromeDevToolsAnnotation boolean annotation to indicate chrome dev tools is enabled
// and that the URL will appear in the pods log
ChromeDevToolsAnnotation = "funktion.fabric8.io/chromeDevTools"

// VersionLabel the version of the runtime
VersionLabel = "version"

Expand Down
8 changes: 7 additions & 1 deletion pkg/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
update "github.com/inconshreveable/go-update"
pb "gopkg.in/cheggaaa/pb.v1"
githubutils "github.com/minishift/minishift/pkg/util/github"
"path/filepath"
)

const (
Expand Down Expand Up @@ -132,7 +133,12 @@ func getLatestVersionFromGitHub(githubOwner, githubRepo string) (semver.Version,
}

func writeTimeToFile(path string, inputTime time.Time) error {
err := ioutil.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0644)
dir := filepath.Dir(path)
err := os.MkdirAll(dir, 0777)
if err != nil {
return fmt.Errorf("Failed to create directory %s due to: %v", dir, err)
}
err = ioutil.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0644)
if err != nil {
return fmt.Errorf("Error writing current update time to file: %s", err)
}
Expand Down

0 comments on commit 5e3be86

Please sign in to comment.