ARO-RP/cmd/aro/main.go

87 строки
1.7 KiB
Go

package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"flag"
"fmt"
"math/rand"
"net/http"
_ "net/http/pprof"
"os"
"strings"
"time"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
"github.com/Azure/ARO-RP/pkg/util/version"
)
func usage() {
fmt.Fprint(flag.CommandLine.Output(), "usage:\n")
fmt.Fprintf(flag.CommandLine.Output(), " %s deploy config.yaml location\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s mirror [release_image...]\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s monitor\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s rp\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s operator {master,worker}\n", os.Args[0])
flag.PrintDefaults()
}
func main() {
rand.Seed(time.Now().UnixNano())
flag.Usage = usage
flag.Parse()
ctx := context.Background()
log := utillog.GetLogger()
go func() {
log.Warn(http.ListenAndServe("localhost:6060", nil))
}()
log.Printf("starting, git commit %s", version.GitCommit)
var err error
switch strings.ToLower(flag.Arg(0)) {
case "mirror":
checkMinArgs(1)
err = mirror(ctx, log)
case "monitor":
checkArgs(1)
err = monitor(ctx, log)
case "rp":
checkArgs(1)
err = rp(ctx, log)
case "deploy":
checkArgs(3)
err = deploy(ctx, log)
case "operator":
checkArgs(2)
err = operator(ctx, log)
default:
usage()
os.Exit(2)
}
if err != nil {
log.Fatal(err)
}
}
func checkArgs(required int) {
if len(flag.Args()) != required {
usage()
os.Exit(2)
}
}
func checkMinArgs(required int) {
if len(flag.Args()) < required {
usage()
os.Exit(2)
}
}