Tweak CLI interface
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-06-01 22:04:20 +02:00
parent 7f10c6a2c2
commit 2ea2ebe836
3 changed files with 26 additions and 26 deletions

View File

@ -49,7 +49,7 @@ type PodWatcherFunc func(KubernetesClient, string, *metav1.LabelSelector, io.Wri
type Watcher struct {
deployName string
container string
allowNonExistentDeployment bool
strictExist bool
clientset KubernetesClient
deployment *appsv1.Deployment
podWatcher PodWatcherInterface
@ -59,11 +59,11 @@ type Watcher struct {
}
// NewWatcher creates a new Watcher.
func NewWatcher(deployName string, container string, allowNonExistentDeployment bool, clientset KubernetesClient, podWatcherFunc PodWatcherFunc, dst io.Writer) *Watcher {
func NewWatcher(deployName string, container string, strictExist bool, clientset KubernetesClient, podWatcherFunc PodWatcherFunc, dst io.Writer) *Watcher {
return &Watcher{
deployName: deployName,
container: container,
allowNonExistentDeployment: allowNonExistentDeployment,
strictExist: strictExist,
clientset: clientset,
podWatcherFunc: podWatcherFunc,
errChan: make(chan error),

View File

@ -36,7 +36,7 @@ func TestWatcherAllowNonExistent(t *testing.T) {
var buf bytes.Buffer
client := logs.KubernetesClient{Interface: clientset}
watcher := logs.NewWatcher("mydeployment", "mycontainer", false, client, mockPodwatcherFunc(nil), &buf)
watcher := logs.NewWatcher("mydeployment", "mycontainer", true, client, mockPodwatcherFunc(nil), &buf)
err := watcher.Watch(context.Background())
assert.EqualError(t, err, `deployments.apps "mydeployment" not found`)
@ -52,7 +52,7 @@ func TestWatcherPodWatcherError(t *testing.T) {
var buf bytes.Buffer
client := logs.KubernetesClient{Interface: clientset}
wantErr := errors.New("foo")
watcher := logs.NewWatcher("mydeployment", "mycontainer", false, client, mockPodwatcherFunc(wantErr), &buf)
watcher := logs.NewWatcher("mydeployment", "mycontainer", true, client, mockPodwatcherFunc(wantErr), &buf)
go func() {
defer deploymentsWatcher.Stop()
@ -105,7 +105,7 @@ func TestWatcherWithPodWatcher(t *testing.T) {
var buf bytes.Buffer
client := logs.KubernetesClient{Interface: clientset}
watcher := logs.NewWatcher("mydeployment", "mycontainer", true, client, logs.NewPodWatcher, &buf)
watcher := logs.NewWatcher("mydeployment", "mycontainer", false, client, logs.NewPodWatcher, &buf)
err := watcher.Watch(ctx)
require.EqualError(t, err, context.Canceled.Error())

View File

@ -18,7 +18,7 @@ func main() {
kubeconfig *string
deployName *string
container *string
allowNonExistentDeployment *bool
strictExist *bool
)
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
@ -27,7 +27,7 @@ func main() {
}
deployName = flag.String("deployment", "", "name of a deployment to monitor")
container = flag.String("container", "", "name of a specific container")
allowNonExistentDeployment = flag.Bool("allow-nonexistent", true, "allow deployment to be non-existent on launch")
strictExist = flag.Bool("strict-exist", false, "require deployment to exist on launch")
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
@ -44,7 +44,7 @@ func main() {
watcher := logs.NewWatcher(
*deployName,
*container,
*allowNonExistentDeployment,
*strictExist,
logs.KubernetesClient{Interface: clientset},
logs.NewPodWatcher,
os.Stdout,