Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Elasticsearch readiness port #7847

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/controller/elasticsearch/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func (u *urlProvider) HasEndpoints() bool {
return err == nil && len(k8s.RunningPods(pods)) > 0
}

// NewElasticsearchURLProvider returns a client.URLProvider that dynamically tries to find Pod URLs among the
// currently running Pods. Preferring ready Pods over running ones.
func NewElasticsearchURLProvider(es esv1.Elasticsearch, client k8s.Client) client.URLProvider {
return &urlProvider{
pods: func() ([]corev1.Pod, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestNewElasticsearchURLProvider(t *testing.T) {
wantErr bool
}{
{
name: "cache failures are swallowed but logged",
name: "cache failures are returned to the caller",
args: args{
es: mkElasticsearch(commonv1.HTTPConfig{}),
client: k8s.NewFailingClient(errors.New("boom")),
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/k8s/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func IsPodReady(pod corev1.Pod) bool {
return conditionsTrue == 2
}

// IsPodRunning returns true if the Pod is in phase running and not terminating.
func IsPodRunning(pod corev1.Pod) bool {
return pod.DeletionTimestamp.IsZero() && pod.Status.Phase == corev1.PodRunning
}
Expand All @@ -90,6 +91,7 @@ func TerminatingPods(pods []corev1.Pod) []corev1.Pod {
return terminating
}

// RunningPods filters pods for Pods are in running (and not terminating).
pebrc marked this conversation as resolved.
Show resolved Hide resolved
func RunningPods(pods []corev1.Pod) []corev1.Pod {
var running []corev1.Pod
for _, p := range pods {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/es/forced_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func TestForceUpgradePendingPodsInOneStatefulSet(t *testing.T) {
if err != nil {
return err
}
running := k8s.RunningPods(pods)
if len(running) == 0 {
if len(k8s.RunningPods(pods)) == 0 {
return errors.New("Elasticsearch does not have any running Pods")
}
return nil
Expand Down