@@ -2,8 +2,8 @@ package e2e
22
33import (
44 "context"
5+ "errors"
56 "fmt"
6- "github.com/pkg/errors"
77 "math"
88 "time"
99
@@ -14,12 +14,14 @@ import (
1414
1515// Check our end-to-end test topic and adapt accordingly if something does not match our expectations.
1616// - does it exist?
17+ //
1718// - is it configured correctly?
18- // - does it have enough partitions?
19- // - is the replicationFactor correct?
19+ // - does it have enough partitions?
20+ // - is the replicationFactor correct?
21+ //
2022// - are assignments good?
21- // - is each broker leading at least one partition?
22- // - are replicas distributed correctly?
23+ // - is each broker leading at least one partition?
24+ // - are replicas distributed correctly?
2325func (s * Service ) validateManagementTopic (ctx context.Context ) error {
2426 s .logger .Debug ("validating end-to-end topic..." )
2527
@@ -30,10 +32,10 @@ func (s *Service) validateManagementTopic(ctx context.Context) error {
3032
3133 typedErr := kerr .TypedErrorForCode (meta .Topics [0 ].ErrorCode )
3234 topicExists := false
33- switch typedErr {
34- case nil :
35+ switch {
36+ case typedErr == nil :
3537 topicExists = true
36- case kerr .UnknownTopicOrPartition :
38+ case errors . Is ( typedErr , kerr .UnknownTopicOrPartition ) :
3739 // UnknownTopicOrPartition (Error code 3) means that the topic does not exist.
3840 // When the topic doesn't exist, continue to create it further down in the code.
3941 topicExists = false
@@ -72,8 +74,10 @@ func (s *Service) validateManagementTopic(ctx context.Context) error {
7274 return s .updatePartitionCount (ctx )
7375}
7476
75- // The partition count must be updated after topic validation because the validation process may lead to the
76- // creation of new partitions. This can occur when new brokers are added to the cluster.
77+ // updatePartitionCount retrieves metadata to inform kminion about the updated
78+ // partition count of its e2e topic. It must be updated after topic validation
79+ // because the validation process may lead to the creation of new partitions.
80+ // This can occur when new brokers are added to the cluster.
7781func (s * Service ) updatePartitionCount (ctx context.Context ) error {
7882 retryTicker := time .NewTicker (1 * time .Second )
7983 defer retryTicker .Stop ()
@@ -98,9 +102,9 @@ func (s *Service) updatePartitionCount(ctx context.Context) error {
98102 return fmt .Errorf ("unexpected error while updating partition count: %w" , typedErr )
99103 }
100104 s .logger .Warn ("updatePartitionCount: received UNKNOWN_TOPIC_OR_PARTITION error, possibly due to timing issue. Retrying..." )
101- // The UNKNOWN_TOPIC_OR_PARTITION error occurs occasionally even though the topic is created
102- // in the validateManagementTopic function. It appears to be a timing issue where the topic metadata
103- // is not immediately available after creation. In practice, waiting for a short period and then retrying
105+ // The UNKNOWN_TOPIC_OR_PARTITION error occurs occasionally even though the topic is created
106+ // in the validateManagementTopic function. It appears to be a timing issue where the topic metadata
107+ // is not immediately available after creation. In practice, waiting for a short period and then retrying
104108 // the operation resolves the issue.
105109 }
106110 }
0 commit comments