-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2020 Target Brands, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by the LICENSE file in this repository. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const kubectlBin = "/bin/kubectl" | ||
|
||
// execCmd is a helper function to | ||
// run the provided command. | ||
func execCmd(e *exec.Cmd) error { | ||
logrus.Tracef("executing cmd %s", strings.Join(e.Args, " ")) | ||
|
||
// set command stdout to OS stdout | ||
e.Stdout = os.Stdout | ||
// set command stderr to OS stderr | ||
e.Stderr = os.Stderr | ||
|
||
// output "trace" string for command | ||
fmt.Println("$", strings.Join(e.Args, " ")) | ||
|
||
return e.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2020 Target Brands, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by the LICENSE file in this repository. | ||
|
||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestKubernetes_execCmd(t *testing.T) { | ||
// setup types | ||
e := exec.Command("echo", "hello") | ||
|
||
err := execCmd(e) | ||
if err != nil { | ||
t.Errorf("execCmd returned err: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2020 Target Brands, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by the LICENSE file in this repository. | ||
|
||
package main | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Plugin represents the configuration loaded for the plugin. | ||
type Plugin struct{} | ||
|
||
// Command formats and outputs the command necessary for | ||
// kubectl to manage Kubernetes resources. | ||
func (p *Plugin) Command() *exec.Cmd { | ||
logrus.Debug("creating kubectl command from plugin configuration") | ||
|
||
// variable to store flags for command | ||
var flags []string | ||
|
||
return exec.Command(kubectlBin, flags...) | ||
} | ||
|
||
// Exec formats and runs the commands for managing resources in Kubernetes. | ||
func (p *Plugin) Exec() error { | ||
logrus.Debug("running plugin with provided configuration") | ||
|
||
return nil | ||
} | ||
|
||
// Validate verifies the plugin is properly configured. | ||
func (p *Plugin) Validate() error { | ||
logrus.Debug("validating plugin configuration") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2020 Target Brands, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by the LICENSE file in this repository. | ||
|
||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestKubernetes_Plugin_Command(t *testing.T) { | ||
// setup types | ||
p := &Plugin{} | ||
|
||
want := exec.Command( | ||
kubectlBin, | ||
) | ||
|
||
// run test | ||
got := p.Command() | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("Command is %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestKubernetes_Plugin_Exec(t *testing.T) { | ||
// setup types | ||
p := &Plugin{} | ||
|
||
err := p.Exec() | ||
if err != nil { | ||
t.Errorf("Exec returned err: %v", err) | ||
} | ||
} | ||
|
||
func TestKubernetes_Plugin_Validate(t *testing.T) { | ||
// setup types | ||
p := &Plugin{} | ||
|
||
err := p.Validate() | ||
if err != nil { | ||
t.Errorf("Validate returned err: %v", err) | ||
} | ||
} |