-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
121 lines (107 loc) · 3.9 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"flag"
"fmt"
"github.com/arlonproj/arlon/cmd/clustercontroller"
"os"
"go.uber.org/zap/zapcore"
"github.com/arlonproj/arlon/cmd/app"
"github.com/arlonproj/arlon/cmd/appprofile"
"github.com/arlonproj/arlon/cmd/appprofilecontroller"
"github.com/arlonproj/arlon/cmd/webhook"
apppkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/util/io"
"github.com/spf13/cobra"
"github.com/arlonproj/arlon/cmd/basecluster"
"github.com/arlonproj/arlon/cmd/bundle"
"github.com/arlonproj/arlon/cmd/callhomecontroller"
"github.com/arlonproj/arlon/cmd/cluster"
"github.com/arlonproj/arlon/cmd/controller"
"github.com/arlonproj/arlon/cmd/gitrepo"
"github.com/arlonproj/arlon/cmd/initialize"
"github.com/arlonproj/arlon/cmd/install"
"github.com/arlonproj/arlon/cmd/list_clusters"
"github.com/arlonproj/arlon/cmd/profile"
"github.com/arlonproj/arlon/cmd/verify"
"github.com/arlonproj/arlon/cmd/version"
"github.com/arlonproj/arlon/pkg/argocd"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
)
func main() {
command := &cobra.Command{
Use: "arlon",
Short: "Run the Arlon program",
Long: "Run the Arlon program",
DisableAutoGenTag: true,
PersistentPreRun: checkForArgocd,
Run: func(c *cobra.Command, args []string) {
c.Println(c.UsageString())
},
}
// don't display usage upon error
command.SilenceUsage = true
command.AddCommand(controller.NewCommand())
command.AddCommand(callhomecontroller.NewCommand())
command.AddCommand(appprofilecontroller.NewCommand())
command.AddCommand(clustercontroller.NewCommand())
command.AddCommand(list_clusters.NewCommand())
command.AddCommand(bundle.NewCommand())
command.AddCommand(profile.NewCommand())
// `clusterspec` is gen-1 only
//command.AddCommand(clusterspec.NewCommand())
command.AddCommand(cluster.NewCommand())
command.AddCommand(webhook.NewCommand())
command.AddCommand(basecluster.NewCommand())
command.AddCommand(gitrepo.NewCommand())
command.AddCommand(verify.NewCommand())
command.AddCommand(install.NewCommand())
command.AddCommand(app.NewCommand())
command.AddCommand(appprofile.NewCommand())
command.AddCommand(initialize.NewCommand())
command.AddCommand(version.NewCommand())
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
}
opts.BindFlags(flag.CommandLine)
// override default log level, which is initially set to 'debug'
_ = flag.Set("zap-log-level", "info")
flag.Parse()
logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)
args := flag.Args()
command.SetArgs(args)
if err := command.Execute(); err != nil {
os.Exit(1)
}
}
func checkForArgocd(cmd *cobra.Command, args []string) {
if cmd.Name() == "cluster" || cmd.Name() == "listclusters" {
conn, appIf := argocd.NewArgocdClientOrDie("").NewApplicationClientOrDie()
defer io.Close(conn)
query := "managed-by=arlon,arlon-type=cluster"
_, err := appIf.List(context.Background(), &apppkg.ApplicationQuery{Selector: &query})
if err != nil {
fmt.Println("ArgoCD auth token has expired....Login to ArgoCD again")
os.Exit(1)
}
}
}