Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should refactor the agent cli output #311

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions agent/help_flag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package main

import (
"os/exec"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

var _ = Describe("Help flag for host agent", func() {
Context("When the help flag is provided", func() {
var (
expectedOptions = []string{
huchen2021 marked this conversation as resolved.
Show resolved Hide resolved
"-downloadpath string",
"-kubeconfig string",
"-label value",
"-metricsbindaddress string",
"-namespace string",
"-skip-installation",
}
)

It("should output the expected option", func() {
command := exec.Command(pathToHostAgentBinary, "--help")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session, "5s").Should(gexec.Exit(0))

output := string(session.Err.Contents())
for _, line := range strings.Split(strings.TrimRight(output, "\n"), "\n") {
line = strings.TrimSpace(line)
if !strings.HasPrefix(line, "-") {
continue
}
// Any option not belongs to expectedOptions is not allowed.
Expect(line).To(BeElementOf(expectedOptions))
}

})

})
})
31 changes: 21 additions & 10 deletions agent/installer/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (
)

var (
listSupportedFlag = flag.Bool("list-supported", false, "List all supported OS, Kubernetes versions and BYOH Bundle names")
detectOSFlag = flag.Bool("detect", false, "Detects the current operating system")
installFlag = flag.Bool("install", false, "Install a BYOH Bundle")
uninstallFlag = flag.Bool("uninstall", false, "Unnstall a BYOH Bundle")
bundleRepoFlag = flag.String("bundle-repo", "projects.registry.vmware.com", "BYOH Bundle Repository")
cachePathFlag = flag.String("cache-path", ".", "Path to the local bundle cache")
k8sFlag = flag.String("k8s", "1.22.1", "Kubernetes version")
osFlag = flag.String("os", "", "OS. If used with install/uninstall, override os detection")
tagFlag = flag.String("tag", "", "BYOH Bundle tag")
previewOSChangesFlag = flag.Bool("preview-os-changes", false, "Preview the install and uninstall changes for the specified OS")
listSupportedFlag *bool
detectOSFlag *bool
installFlag *bool
uninstallFlag *bool
bundleRepoFlag *string
cachePathFlag *string
k8sFlag *string
osFlag *string
tagFlag *string
previewOSChangesFlag *bool
)

const (
Expand All @@ -38,6 +38,17 @@ var (
func Main() {
klogger = klogr.New()

listSupportedFlag = flag.Bool("list-supported", false, "List all supported OS, Kubernetes versions and BYOH Bundle names")
detectOSFlag = flag.Bool("detect", false, "Detects the current operating system")
installFlag = flag.Bool("install", false, "Install a BYOH Bundle")
uninstallFlag = flag.Bool("uninstall", false, "Unnstall a BYOH Bundle")
bundleRepoFlag = flag.String("bundle-repo", "projects.registry.vmware.com", "BYOH Bundle Repository")
cachePathFlag = flag.String("cache-path", ".", "Path to the local bundle cache")
k8sFlag = flag.String("k8s", "1.22.1", "Kubernetes version")
anusha94 marked this conversation as resolved.
Show resolved Hide resolved
osFlag = flag.String("os", "", "OS. If used with install/uninstall, override os detection")
tagFlag = flag.String("tag", "", "BYOH Bundle tag")
previewOSChangesFlag = flag.Bool("preview-os-changes", false, "Preview the install and uninstall changes for the specified OS")

flag.Parse()

if *listSupportedFlag {
Expand Down
2 changes: 0 additions & 2 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog"
"k8s.io/klog/klogr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -88,7 +87,6 @@ func main() {
flag.StringVar(&metricsbindaddress, "metricsbindaddress", ":8080", "metricsbindaddress is the TCP address that the controller should bind to for serving prometheus metrics.It can be set to \"0\" to disable the metrics serving")
flag.StringVar(&downloadpath, "downloadpath", "/var/lib/byoh/bundles", "File System path to keep the downloads")
flag.BoolVar(&skipInstallation, "skip-installation", false, "If you want to skip installation of the kubernetes component binaries")
klog.InitFlags(nil)
flag.Parse()
scheme = runtime.NewScheme()
_ = infrastructurev1beta1.AddToScheme(scheme)
Expand Down