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

operator: use pod annotation for node_id and avoid mixing maintenance mode with decommissioning #7581

Closed

Conversation

joejulian
Copy link
Contributor

There were places where the pod ordinal was being used for the node_id (broker id). With v22.3.x those numbers may not match. By using the pod annotation, we can use the correct node_id.

This strategy doesn't work, however, when mixing decommission and maintenance mode. The preStop script would always set maintenance mode, even if the node was decommissioned, or in the process of being decommissioned. This avoids the need for running that workaround by checking in the preStop script and not setting maintenance mode if decommissioned/decommissioning.

Fixes #7541

Backports Required

  • none - not a bug fix
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v22.3.x
  • v22.2.x
  • v22.1.x

UX Changes

N/A

Release Notes

Bug Fixes

  • fixes the use of the pod ordinal for node_id when they are not aligned

@joejulian joejulian requested a review from a team as a code owner December 1, 2022 00:37
@joejulian joejulian self-assigned this Dec 1, 2022
@joejulian joejulian force-pushed the redpanda_use_annotation branch 2 times, most recently from bcba247 to 2d1e2a3 Compare December 2, 2022 07:34
alenkacz
alenkacz previously approved these changes Dec 15, 2022
Copy link
Contributor

@alenkacz alenkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no blockers but couple of nits

pretty interesting we did not have to touch much tests 😅

// "selector" are unavailable after the eviction, i.e. even in absence of
// the evicted pod. For example, one can prevent all voluntary evictions
// the evicted Pod. For example, one can prevent all voluntary evictions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just curious why is Pod capital? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k8s resources are proper nouns. Making this distinction helps comprehension, especially with Node and Service. I forget why this caught my attention but I did put it in its own commit in case it was hated 😁

@@ -281,7 +279,7 @@ func registerAdvertisedKafkaAPI(
}

func registerAdvertisedPandaproxyAPI(
c *configuratorConfig, cfg *config.Config, index brokerID, proxyAPIPort int,
c *configuratorConfig, cfg *config.Config, index int, proxyAPIPort int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this index is podOrdinal? Would. be nice to use just one name for the thing to avoid confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same thing but was concerned about blowing up scope since this was originally wanted within the day. I think I've addressed this.

@@ -414,7 +414,7 @@ func isSafeToRestart(
) bool {
configVersions := make(map[int64]bool)
for i := range clusterStatus {
log.Info(fmt.Sprintf("Node %d is using config version %d", clusterStatus[i].NodeID, clusterStatus[i].ConfigVersion))
log.Info(fmt.Sprintf("Node %d is using config version %d", clusterStatus[i].NodeID, clusterStatus[i].ConfigVersion)) // actually pod ordinal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should all this then say pod with ordinal X is using....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was wrong. Removed the comment.

Copy link
Contributor

@alenkacz alenkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

@RafalKorepta RafalKorepta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have problem with recommission logic and new feature gate. Other than that LGTM

src/go/k8s/pkg/resources/secret.go Show resolved Hide resolved
src/go/k8s/pkg/resources/statefulset.go Show resolved Hide resolved
@@ -224,25 +228,30 @@ func (r *StatefulSetResource) handleRecommission(ctx context.Context) error {
return err
}

broker, err := getNodeInfoFromCluster(ctx, *r.pandaCluster.Status.DecommissioningNode, adminAPI)
broker, err := getNodeInfoFromCluster(ctx, targetOrdinal, adminAPI)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is problem with this call.

// getNodeInfoFromCluster allows to get broker information using the admin API
func getNodeInfoFromCluster(
ctx context.Context, ordinal int32, adminAPI adminutils.AdminAPIClient,
) (*admin.Broker, error) {
brokers, err := adminAPI.Brokers(ctx)
if err != nil {
return nil, fmt.Errorf("could not get the list of brokers for checking decommission: %w", err)
}
for i := range brokers {
if brokers[i].NodeID == int(ordinal) {
return &brokers[i], nil
}
}
return nil, nil
}

The second argument is the Pod ordinal. The for loop will look for node with wrong ID. I think you should swap the getPodNodeIDFromAnnotation with getNodeInfoFromCluster and change targetOrdinal with brokerID as second argument in getNodeInfoFromCluster function.

Copy link
Contributor

@RafalKorepta RafalKorepta Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have e2e test that verifies that recommission broker is called. Maybe unit test would be enough to simulate 2 disjoint collections of ids:

  • POD ordinals - 0,1,2
  • Broker ID - 7, 8, 9

Unit test would need to assert that RecommissionBroker was called.

Copy link
Contributor

@alejandroEsc alejandroEsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one item, otherwise lgtm

// the last number is the index of replica. This index is then propagated
// to redpanda.node_id.
func hostIndex(hostName string) (brokerID, error) {
// getPodOrdinalFromHostname takes advantage of pod naming convention in Kubernetes StatfulSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// getPodOrdinalFromHostname takes advantage of pod naming convention in Kubernetes StatfulSet
// getPodOrdinalFromHostname takes advantage of Pod naming convention in Kubernetes StatefulSet

@joejulian
Copy link
Contributor Author

closing as it's horribly out-of-date and needs to be redone (if at all).

@joejulian joejulian closed this Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the pod annotation for broker id
4 participants