MCPcopy Create free account
hub / github.com/akash-network/provider / OperatorsCmd

Function OperatorsCmd

operator/cmd.go:27–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25)
26
27func OperatorsCmd() *cobra.Command {
28 cmd := &cobra.Command{
29 Use: "operator",
30 Short: "kubernetes operators control",
31 SilenceUsage: true,
32 PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
33 zconf := zap.NewDevelopmentConfig()
34 zconf.DisableCaller = true
35 zconf.DisableStacktrace = true
36 zconf.EncoderConfig.EncodeTime = func(time.Time, zapcore.PrimitiveArrayEncoder) {}
37
38 zapLog, _ := zconf.Build()
39
40 group, ctx := errgroup.WithContext(cmd.Context())
41
42 cmd.SetContext(logr.NewContext(ctx, zapr.NewLogger(zapLog)))
43
44 kubecfg, err := fromctx.KubeConfigFromCtx(cmd.Context())
45 if err != nil {
46 if err := clientcommon.SetKubeConfigToCmd(cmd); err != nil {
47 return err
48 }
49
50 kubecfg = fromctx.MustKubeConfigFromCtx(cmd.Context())
51 }
52
53 if val := ctx.Value(fromctx.CtxKeyKubeClientSet); val == nil {
54 kc, err := kubernetes.NewForConfig(kubecfg)
55 if err != nil {
56 return err
57 }
58 fromctx.CmdSetContextValue(cmd, fromctx.CtxKeyKubeClientSet, kubernetes.Interface(kc))
59 }
60
61 if val := ctx.Value(fromctx.CtxKeyAkashClientSet); val == nil {
62 ac, err := akashclientset.NewForConfig(kubecfg)
63 if err != nil {
64 return err
65 }
66
67 fromctx.CmdSetContextValue(cmd, fromctx.CtxKeyAkashClientSet, akashclientset.Interface(ac))
68 }
69
70 startupch := make(chan struct{}, 1)
71 fromctx.CmdSetContextValue(cmd, fromctx.CtxKeyStartupCh, (chan<- struct{})(startupch))
72
73 pctx, pcancel := context.WithCancel(context.Background())
74
75 fromctx.CmdSetContextValue(cmd, fromctx.CtxKeyErrGroup, group)
76 fromctx.CmdSetContextValue(cmd, fromctx.CtxKeyPubSub, pubsub.New(pctx, 1000))
77
78 go func() {
79 defer pcancel()
80
81 select {
82 case <-ctx.Done():
83 return
84 case <-startupch:

Callers 2

RunLocalOperatorFunction · 0.92
NewRootCmdFunction · 0.92

Calls 10

KubeConfigFromCtxFunction · 0.92
SetKubeConfigToCmdFunction · 0.92
MustKubeConfigFromCtxFunction · 0.92
CmdSetContextValueFunction · 0.92
CmdFunction · 0.92
CmdFunction · 0.92
CmdFunction · 0.92
DoneMethod · 0.65
StringMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected