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/kubernetestest: support getting resource by name #2937

Conversation

AlexanderYastrebov
Copy link
Member

This is useful for testing getting endpoints by service name.

For #2476

This is useful for testing getting endpoints by service name.

For #2476

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
@AlexanderYastrebov AlexanderYastrebov added the minor no risk changes, for example new filters label Feb 14, 2024
pathRx: regexp.MustCompile(
"(/namespaces/([^/]+))?/(services|ingresses|routegroups|endpointslices|endpoints|secrets)",
"(?:/namespaces/([^/]+))?/(services|ingresses|routegroups|endpointslices|endpoints|secrets)(?:/(.+))?",
Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Feb 14, 2024

Choose a reason for hiding this comment

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

We may consider refactoring this later to use https://pkg.go.dev/net/http#hdr-Patterns added in go 1.22

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about having test like this? For you not to forget to have a look when we will update Go version.

func TestPathRx(t *testing.T) {
    if runtime.Version() == "go1.22" {
        t.Error("please pay attention to dataclients/kubernetes/kubernetestest/api.go:49 using http.Patterns")
    }
}

https://pkg.go.dev/runtime#Version

Copy link
Member Author

Choose a reason for hiding this comment

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

This will fail as we use 1.22 already.
We can use 1.22 features after we bump min version in go.mod

The proposed change is optional it may wait until we touch this code again.

Items []struct {
Metadata struct {
Name string `json:"name"`
Copy link
Member

@RomanZavodskikh RomanZavodskikh Feb 14, 2024

Choose a reason for hiding this comment

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

Should we consider namespace here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can add it but is not used as the test api only filters by name or labels

check(t, sec, 0, "Secret")
})

t.Run("resource by name", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add "resource with this name does not exist in current namespace, but exists in another"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? The result will be the same as "resource name does not exist" below

Copy link
Member

Choose a reason for hiding this comment

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

I expected to have some probability of some bug related to it in k8s API, but maybe I am too paranoid.

@RomanZavodskikh
Copy link
Member

👍

get := func(t *testing.T, uri string, o interface{}) {
t.Helper()
err := getJSON(s.URL+uri, o)
require.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

get function looks a bit weird as a name if we start to check for error. Maybe mustGet

Copy link
Member Author

Choose a reason for hiding this comment

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

Its just a helper closure, does it matter?

@AlexanderYastrebov
Copy link
Member Author

👍

@AlexanderYastrebov AlexanderYastrebov merged commit ecb8c0b into master Feb 14, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the dataclients/kubernetes/kubernetestest-resource-by-name branch February 14, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor no risk changes, for example new filters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants