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

Skip wait for Pods on headless Service #2475

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [sdk/python] Fix bug with class methods for YAML transformations (https://github.com/pulumi/pulumi-kubernetes/pull/2469)
- Fix StatefulSet await logic for OnDelete update (https://github.com/pulumi/pulumi-kubernetes/pull/2473)
- Skip wait for Pods on headless Service (https://github.com/pulumi/pulumi-kubernetes/pull/2475)

## 3.29.1 (June 14, 2023)

Expand Down
19 changes: 2 additions & 17 deletions provider/pkg/await/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (sia *serviceInitAwaiter) processEndpointEvent(event watch.Event, settledCh

func (sia *serviceInitAwaiter) errorMessages() []string {
messages := make([]string, 0)
if sia.emptyHeadlessOrExternalName() {
if sia.isHeadlessService() || sia.isExternalNameService() {
return messages
}

Expand Down Expand Up @@ -389,21 +389,6 @@ func (sia *serviceInitAwaiter) isExternalNameService() bool {
return sia.serviceType == string(v1.ServiceTypeExternalName)
}

// emptyHeadlessOrExternalName checks whether the current `Service` is either an "empty" headless
// `Service`[1] (i.e., it targets 0 `Pod`s) or a `Service` with `.spec.type: ExternalName` (which
// also targets 0 `Pod`s). This is useful to know when deciding whether to wait for a `Service` to
// target some number of `Pod`s.
//
// [1]: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services
func (sia *serviceInitAwaiter) emptyHeadlessOrExternalName() bool {
selectorI, _ := openapi.Pluck(sia.service.Object, "spec", "selector")
selector, _ := selectorI.(map[string]any)

headlessEmpty := len(selector) == 0 && sia.isHeadlessService()
return headlessEmpty || sia.isExternalNameService()

}

// hasHeadlessServicePortBug checks whether the current `Service` is affected by a bug [1][2]
// that prevents endpoints from being populated when ports are not specified for a headless
// or external name Service.
Expand Down Expand Up @@ -434,7 +419,7 @@ func (sia *serviceInitAwaiter) hasHeadlessServicePortBug(version cluster.ServerV
// shouldWaitForPods determines whether to wait for Pods to be ready before marking the Service ready.
func (sia *serviceInitAwaiter) shouldWaitForPods(version cluster.ServerVersion) bool {
// For these special cases, skip the wait for Pod logic.
if sia.emptyHeadlessOrExternalName() || sia.hasHeadlessServicePortBug(version) {
if sia.isExternalNameService() || sia.isHeadlessService() || sia.hasHeadlessServicePortBug(version) {
sia.endpointsReady = true
return false
}
Expand Down
12 changes: 2 additions & 10 deletions provider/pkg/await/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func Test_Core_Service(t *testing.T) {
},
},
{
description: "Should fail if non-empty headless service doesn't target any Pods",
description: "Should succeed if non-empty headless service doesn't target any Pods",
serviceInput: headlessNonemptyServiceInput,
version: cluster.ServerVersion{Major: 1, Minor: 12},
do: func(services, endpoints chan watch.Event, settled chan struct{}, timeout chan time.Time) {
Expand All @@ -211,11 +211,6 @@ func Test_Core_Service(t *testing.T) {
// Finally, time out.
timeout <- time.Now()
},
expectedError: &timeoutError{
object: headlessNonemptyServiceOutput("default", "foo-4setj4y6"),
subErrors: []string{
"Service does not target any Pods. Selected Pods may not be ready, or " +
"field '.spec.selector' may not match labels on any Pods"}},
},
}

Expand Down Expand Up @@ -284,13 +279,10 @@ func Test_Core_Service_Read(t *testing.T) {
version: cluster.ServerVersion{Major: 1, Minor: 11},
},
{
description: "Read fail if headless non-empty Service doesn't target any Pods",
description: "Read succeed if headless non-empty Service doesn't target any Pods",
serviceInput: headlessNonemptyServiceInput,
service: headlessNonemptyServiceInput,
version: cluster.ServerVersion{Major: 1, Minor: 12},
expectedSubErrors: []string{
"Service does not target any Pods. Selected Pods may not be ready, or " +
"field '.spec.selector' may not match labels on any Pods"},
},
}

Expand Down
Loading