ARO-RP/cmd/aro/main.go

87 строки
1.7 KiB
Go
Исходник Обычный вид История

2019-12-22 20:47:29 +03:00
package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
2020-01-21 05:57:53 +03:00
"flag"
"fmt"
"math/rand"
2020-10-14 18:14:20 +03:00
"net/http"
_ "net/http/pprof"
2019-12-22 20:47:29 +03:00
"os"
"strings"
"time"
2019-12-22 20:47:29 +03:00
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"
2019-12-22 20:47:29 +03:00
)
2020-01-21 05:57:53 +03:00
func usage() {
2020-03-22 07:35:17 +03:00
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])
2020-03-22 07:35:17 +03:00
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])
2020-01-21 05:57:53 +03:00
flag.PrintDefaults()
}
2019-12-22 20:47:29 +03:00
func main() {
rand.Seed(time.Now().UnixNano())
2020-01-21 05:57:53 +03:00
flag.Usage = usage
flag.Parse()
2020-01-19 02:46:58 +03:00
ctx := context.Background()
2019-12-22 20:47:29 +03:00
log := utillog.GetLogger()
2020-10-14 18:14:20 +03:00
go func() {
log.Warn(http.ListenAndServe("localhost:6060", nil))
}()
log.Printf("starting, git commit %s", version.GitCommit)
2019-12-22 20:47:29 +03:00
var err error
2020-03-05 05:02:28 +03:00
switch strings.ToLower(flag.Arg(0)) {
2019-12-22 20:47:29 +03:00
case "mirror":
checkMinArgs(1)
2020-01-19 02:46:58 +03:00
err = mirror(ctx, log)
case "monitor":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = monitor(ctx, log)
2019-12-22 20:47:29 +03:00
case "rp":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = rp(ctx, log)
2020-03-02 16:10:46 +03:00
case "deploy":
2020-03-06 13:28:05 +03:00
checkArgs(3)
2020-03-02 16:10:46 +03:00
err = deploy(ctx, log)
case "operator":
checkArgs(2)
err = operator(ctx, log)
2020-01-19 02:46:58 +03:00
default:
usage()
os.Exit(2)
2019-12-22 20:47:29 +03:00
}
if err != nil {
log.Fatal(err)
}
}
2020-03-06 13:28:05 +03:00
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)
}
}