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

dataclients/kubernetes: change GetEndpointAddresses to return addresses without scheme and port #2917

Conversation

AlexanderYastrebov
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov commented Feb 9, 2024

  • use -kubernetes-redis-service-port flag to explicitly configure redis port
  • use separate cluster state cache for addresses since cache key does not contain port
  • rename helpers protocol argument to scheme

This is a breaking change for users that:

  • use kubernetes dataclient GetEndpointAddresses method
  • use dynamic redis shards discovery AND use non-standard redis port AND do not specify -kubernetes-redis-service-port

For #2476

@AlexanderYastrebov AlexanderYastrebov added the minor no risk changes, for example new filters label Feb 9, 2024
@AlexanderYastrebov AlexanderYastrebov force-pushed the dataclients/kubernetes/refactor-get-endpoint-addresses branch from 302dd49 to 4b0187f Compare February 9, 2024 12:36
Comment on lines -89 to -92
epID := endpointID{
ResourceID: newResourceID(namespace, name),
Protocol: protocol,
}
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 9, 2024

Choose a reason for hiding this comment

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

This was logically wrong because it does not contain target port unlike other places that use state.cachedEndpoints

@@ -22,18 +22,18 @@ type endpointList struct {
Items []*endpoint `json:"items"`
}

func formatEndpointString(ip, protocol string, port int) string {
return protocol + "://" + net.JoinHostPort(ip, strconv.Itoa(port))
func formatEndpointString(ip, scheme string, port int) string {
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 9, 2024

Choose a reason for hiding this comment

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

This is not strictly required for this refactoring but I noticed the inconsistency and decided to fix it along.

@AlexanderYastrebov AlexanderYastrebov force-pushed the dataclients/kubernetes/refactor-get-endpoint-addresses branch 2 times, most recently from 9b79d6c to 493c3fc Compare February 9, 2024 15:36
@AlexanderYastrebov AlexanderYastrebov changed the title dataclients/kubernetes: refactor GetEndpointAddresses dataclients/kubernetes: change GetEndpointAddresses to return addresses without port Feb 9, 2024
state.mu.Lock()
defer state.mu.Unlock()
if cached, ok := state.cachedEndpoints[epID]; ok {
if cached, ok := state.cachedAddresses[rID]; ok {
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 9, 2024

Choose a reason for hiding this comment

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

I think we can even drop the cache as implementation became straightforward now

@AlexanderYastrebov AlexanderYastrebov force-pushed the dataclients/kubernetes/refactor-get-endpoint-addresses branch from 493c3fc to 471cfb4 Compare February 9, 2024 15:52
@AlexanderYastrebov AlexanderYastrebov changed the title dataclients/kubernetes: change GetEndpointAddresses to return addresses without port dataclients/kubernetes: change GetEndpointAddresses to return addresses without scheme and port Feb 9, 2024
@AlexanderYastrebov AlexanderYastrebov added major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs and removed minor no risk changes, for example new filters labels Feb 9, 2024
@AlexanderYastrebov AlexanderYastrebov force-pushed the dataclients/kubernetes/refactor-get-endpoint-addresses branch 2 times, most recently from a86199b to ce25bc5 Compare February 9, 2024 16:15
@RomanZavodskikh
Copy link
Member

I would like to kindly ask why we should provide format different from what we already have in the routing.Route? Does it make sense to have the same format there and here for increasing readability?

https://github.com/zalando/skipper/pull/2824/files#diff-bacdef5a036ec850a0efe0adc1f0288bc03339074b068f5b9b87e7d8532aaa5bR274

@AlexanderYastrebov
Copy link
Member Author

I would like to kindly ask why we should provide format different from what we already have in the routing.Route

Redis endpoints are used by redis client, these are not backend endpoints for the proxy.

@AlexanderYastrebov
Copy link
Member Author

AlexanderYastrebov commented Feb 9, 2024

TestConcurrentKubernetesClusterStateAccessWithRemoteRedis fails because it creates an endpoint with a single address and multiple ports

skipper/redis_test.go

Lines 150 to 166 in be4ef50

// apiserver1
specFmt := redisEpSpecFmt + redisPortFmt
redisSpec1 := fmt.Sprintf(specFmt, 0, host1, port1)
apiServer1, u1, err := createApiserver(kubeSpec + redisSpec1)
if err != nil {
t.Fatalf("Failed to start apiserver1: %v", err)
}
defer apiServer1.Close()
// apiserver2
specFmt += redisPortFmt
redisSpec2 := fmt.Sprintf(specFmt, 0, host1, port1, port2)
apiServer2, u2, err := createApiserver(kubeSpec + redisSpec2)
if err != nil {
t.Fatalf("Failed to start apiserver2: %v", err)
}
defer apiServer2.Close()

while in k8s cluster endpoints have multiple addresses and a single port.

I've created #2919 to address this.

…es without scheme and port

* use -kubernetes-redis-service-port flag to explicitly configure redis port
* use separate cluster state cache for addresses since cache key does not contain port
* rename helpers protocol argument to scheme

This is a breaking change for users that:

* use kubernetes dataclient GetEndpointAddresses method
* use dynamic redis shards discovery AND use non-standard redis port AND do not specify -kubernetes-redis-service-port

For #2476

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
@AlexanderYastrebov AlexanderYastrebov force-pushed the dataclients/kubernetes/refactor-get-endpoint-addresses branch from ce25bc5 to d05dd7b Compare February 12, 2024 11:57
@szuecs
Copy link
Member

szuecs commented Feb 12, 2024

👍

@szuecs
Copy link
Member

szuecs commented Feb 12, 2024

Please make sure that the release notes contain all information what needs to be done to migrate (breaking change with simple migration path if documented).

@AlexanderYastrebov
Copy link
Member Author

👍

@AlexanderYastrebov AlexanderYastrebov merged commit 3c3f0c1 into master Feb 12, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the dataclients/kubernetes/refactor-get-endpoint-addresses branch February 12, 2024 15:12
AlexanderYastrebov added a commit that referenced this pull request Feb 12, 2024
Returning cached endpoint addreses from exported GetEndpointAddresses
makes it possible for caller to modify cached values.

Since the logic of obtaining endpoint addresses is lightweight
this change simply drops caching altogether.

Follow up on #2917

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit that referenced this pull request Feb 12, 2024
Returning cached endpoint addreses from exported GetEndpointAddresses
makes it possible for caller to modify cached values.

Since the logic of obtaining endpoint addresses is lightweight
this change simply drops caching altogether.

Follow up on #2917

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
for i := 0; i < len(a); i++ {
a[i] = strings.TrimPrefix(a[i], "http://")
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 12, 2024

Choose a reason for hiding this comment

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

Comment on lines -1368 to +1370
a[i] = strings.TrimPrefix(a[i], "http://")
a[i] = net.JoinHostPort(a[i], port)
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 12, 2024

Choose a reason for hiding this comment

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

Here is an obscure bug - the code modifies cached value of a returned from kdc.GetEndpointAddresses, see #2929

Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 12, 2024

Choose a reason for hiding this comment

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

It was not observed in production because k8s poll interval is 3 seconds and redis endpoints update interval is 10s

AlexanderYastrebov added a commit that referenced this pull request Feb 12, 2024
Returning cached endpoint addreses from exported GetEndpointAddresses
makes it possible for caller to modify cached values.

Since the logic of obtaining endpoint addresses is lightweight
this change simply drops caching altogether.

Follow up on #2917

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit that referenced this pull request Feb 12, 2024
Returning cached endpoint addreses from exported GetEndpointAddresses
makes it possible for caller to modify cached values.

Since the logic of obtaining endpoint addresses is lightweight
this change simply drops caching altogether.

Follow up on #2917

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants