-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathready.go
More file actions
80 lines (65 loc) · 1.87 KB
/
ready.go
File metadata and controls
80 lines (65 loc) · 1.87 KB
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
// Copyright 2025 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
package ready
import (
"context"
"fmt"
"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/redpanda-data/redpanda-operator/operator/internal/probes"
internalclient "github.com/redpanda-data/redpanda-operator/operator/pkg/client"
)
func Command() *cobra.Command {
var (
redpandaYAMLPath string
brokerURL string
)
cmd := &cobra.Command{
Use: "ready",
Short: "Run the redpanda broker readiness probe and exit",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
return Run(
ctx,
redpandaYAMLPath,
brokerURL,
)
},
}
cmd.Flags().StringVar(&redpandaYAMLPath, "redpanda-yaml", "/etc/redpanda/redpanda.yaml", "Path to redpanda.yaml whose rpk stanza will be used for connecting to a Redpanda cluster.")
cmd.Flags().StringVar(&brokerURL, "broker-url", "", "The URL of the broker instance this readiness check is for.")
return cmd
}
func Run(
ctx context.Context,
redpandaYAMLPath string,
brokerURL string,
) error {
logger := ctrl.LoggerFrom(ctx)
if brokerURL == "" {
err := fmt.Errorf("invalid broker url: %q", brokerURL)
logger.Error(err, "must specify a broker via the -broker-url flag")
return err
}
prober := probes.NewProber(
internalclient.NewRPKOnlyFactory(),
redpandaYAMLPath,
probes.WithLogger(logger),
)
ready, err := prober.IsClusterBrokerReady(ctx, brokerURL)
if err != nil {
logger.Error(err, "error checking broker readiness")
return err
}
if !ready {
return errors.New("broker not ready")
}
return nil
}