()
| 25 | ) |
| 26 | |
| 27 | func 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: |
no test coverage detected