diff --git a/agent/installer/cli.go b/agent/installer/cli.go new file mode 100644 index 000000000..75b7e0581 --- /dev/null +++ b/agent/installer/cli.go @@ -0,0 +1,101 @@ +// Copyright 2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package installer + +import ( + "flag" + "fmt" + "k8s.io/klog" + "k8s.io/klog/klogr" +) + +var ( + listFlag = flag.Bool("list", false, "List all supported OS and Kubernetes versions") + listBundlesFlag = flag.Bool("listbundles", false, "List the BYOH Bundle names for all supported OS and Kubernetes versions") + 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("bundleRepo", "https://projects.registry.vmware.com", "BYOH Bundle Repository. If not set, will look for bundles locally") + k8sFlag = flag.String("k8sVer", "1.22.1", "Kubernetes version to install") +) + +const ( + doInstall = true + doUninstall = false +) + +func Main() { + flag.Parse() + + if *listFlag { + list() + } + + if *listBundlesFlag { + listBundles() + } + + if *detectOSFlag { + detectOS() + } + + if *installFlag { + runInstaller(doInstall) + } + + if *uninstallFlag { + runInstaller(doUninstall) + } +} + +func list() { + for _, os := range ListSupportedOS() { + for _, k8s := range ListSupportedK8s(os) { + fmt.Printf("%s %s\n", os, k8s) + } + } +} + +func listBundles() { + for _, os := range ListSupportedOS() { + for _, k8s := range ListSupportedK8s(os) { + fmt.Println(GetBundleName(os, k8s)) + } + } +} + +func detectOS() { + osd := osDetector{} + os, err := osd.Detect() + if err != nil { + fmt.Printf("Error detecting OS %s", err) + return + } + + fmt.Printf("Detected OS as: %s", os) +} + +func runInstaller(install bool) { + if *bundleRepoFlag == "" { + bd := bundleDownloader{"", "."} + fmt.Printf("Bundle repo not specified. Provide bundle contents in %s\n", bd.GetBundleDirPath(*k8sFlag)) + } + + klog.InitFlags(nil) + klogr.New() + + i, err := New("norepo", ".", klogr.New()) + if err != nil { + fmt.Println(err) + } + + if install { + err = i.Install(*k8sFlag) + } else { + err = i.Uninstall(*k8sFlag) + } + if err != nil { + fmt.Println(err) + } +} diff --git a/agent/installer/cli/main.go b/agent/installer/cli/main.go new file mode 100644 index 000000000..4611ec373 --- /dev/null +++ b/agent/installer/cli/main.go @@ -0,0 +1,12 @@ +// Copyright 2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "github.com/vmware-tanzu/cluster-api-provider-byoh/agent/installer" +) + +func main() { + installer.Main() +}