Skip to content

Commit

Permalink
CLI for the installer library
Browse files Browse the repository at this point in the history
  • Loading branch information
ratanasovvmw committed Oct 28, 2021
1 parent 77a0407 commit 6c4188b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
101 changes: 101 additions & 0 deletions agent/installer/cli.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
12 changes: 12 additions & 0 deletions agent/installer/cli/main.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 6c4188b

Please sign in to comment.