Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lmm committed Dec 14, 2021
1 parent aab0790 commit 9557da1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,7 @@ install-calico-windows-script $(WINDOWS_INSTALL_SCRIPT): $(WINDOWS_GEN_INSTALL_S
-product "$(WINDOWS_INSTALL_SCRIPT_PRODUCT)" \
-version $(GIT_VERSION) \
-templatePath windows-packaging/install-calico-windows.ps1.tpl \
-baseUrl $(WINDOWS_ARCHIVE_BASE_URL) \
-debug true > $(WINDOWS_INSTALL_SCRIPT)
-baseUrl $(WINDOWS_ARCHIVE_BASE_URL) > $(WINDOWS_INSTALL_SCRIPT)

###############################################################################
# Utilities
Expand Down
55 changes: 25 additions & 30 deletions hack/gen-install-calico-windows-script/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,48 @@ type install struct {
ZipFileName string `json:"zipFileName"`
}

var installs = map[string]install{
"Calico": {
Product: "Calico",
ProductName: "Calico for Windows",
RootDir: "CalicoWindows",
ZipFileName: "calico-windows.zip",
},
"Calico Enterprise": {
Product: "Calico Enterprise",
ProductName: "Tigera Calico for Windows",
RootDir: "TigeraCalico",
ZipFileName: "tigera-calico-windows.zip",
},
}

func newInstall(product, version, baseUrl string) (install, error) {
data := install{
Product: product,
Version: version,
BaseUrl: baseUrl,
}
var productName, rootDir, zipFileName string

if product == "Calico" {
productName = "Calico for Windows"
rootDir = "CalicoWindows"
zipFileName = "calico-windows.zip"
} else if product == "Calico Enterprise" {
productName = "Tigera Calico for Windows"
rootDir = "TigeraCalico"
zipFileName = "tigera-calico-windows.zip"
} else {
return data, fmt.Errorf("invalid product: %v", product)
}
var data install

data.ProductName = productName
data.RootDir = rootDir
data.ZipFileName = zipFileName
return data, nil
if install, ok := installs[product]; ok {
data = install
data.Version = version
data.BaseUrl = baseUrl
return data, nil
}
return data, fmt.Errorf("invalid product: %v", product)
}

var (
product string
version string
templatePath string
baseUrl string
debug bool
)

func main() {
flag.StringVar(&product, "product", "", `product to generate install script for. either "Calico" or "Calico Enterprise"`)
flag.StringVar(&version, "version", "", `version`)
flag.StringVar(&templatePath, "templatePath", "", `path to the template for the installation script`)
flag.StringVar(&baseUrl, "baseUrl", "", `URL where the installation zip file will be hosted. Required for Calico only`)
flag.BoolVar(&debug, "debug", false, `enable debug logging`)
flag.Parse()

if debug {
log.Printf("product: %v, version: %v, templatePath: %v, baseUrl: %v", product, version, templatePath, baseUrl)
}
log.Printf("product: %v, version: %v, templatePath: %v, baseUrl: %v", product, version, templatePath, baseUrl)

if product == "" || version == "" || templatePath == "" {
log.Fatalf("product, version, templatePath, and baseUrl must all be specified")
Expand All @@ -95,9 +92,7 @@ func main() {
log.Fatalf("error generating installation script data: %v", err)
}

if debug {
log.Printf("using install data: %+v", data)
}
log.Printf("using install data: %+v", data)

t, err := template.ParseFiles(templatePath)
if err != nil {
Expand Down

0 comments on commit 9557da1

Please sign in to comment.