forked from k8sgateway/k8sgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6ba288e
commit 7b3c37a
Showing
13 changed files
with
376 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
changelog: | ||
- type: FIX | ||
issueLink: https://github.com/solo-io/gloo/issues/8635 | ||
description: > | ||
Fix a bug that caused discovered Upstreams to not reflect the updated state of parent Services discovered using | ||
watchLabels | ||
resolvesIssue: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
test/kubernetes/e2e/features/discovery_watchlabels/discovery_watchlabels_suite.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package discovery_watchlabels | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/onsi/gomega" | ||
|
||
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/kube/apis/gloo.solo.io/v1" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/options" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/plugins/kubernetes" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/solo-io/gloo/projects/gloo/pkg/defaults" | ||
"github.com/solo-io/gloo/test/kubernetes/e2e" | ||
"github.com/solo-io/solo-kit/pkg/api/v1/clients" | ||
"github.com/solo-io/solo-kit/pkg/api/v1/resources" | ||
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
var _ e2e.NewSuiteFunc = NewDiscoveryWatchlabelsSuite | ||
|
||
// discoveryWatchlabelsSuite is the Suite of tests for validating Upstream discovery behavior when watchLabels are enabled | ||
// This suite replaces the "upstream discovery" Context block from kube2e gateway tests | ||
type discoveryWatchlabelsSuite struct { | ||
suite.Suite | ||
|
||
ctx context.Context | ||
|
||
// testInstallation contains all the metadata/utilities necessary to execute a series of tests | ||
// against an installation of Gloo Gateway | ||
testInstallation *e2e.TestInstallation | ||
} | ||
|
||
func NewDiscoveryWatchlabelsSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.TestingSuite { | ||
return &discoveryWatchlabelsSuite{ | ||
ctx: ctx, | ||
testInstallation: testInst, | ||
} | ||
} | ||
|
||
func (s *discoveryWatchlabelsSuite) TestDiscoverUpstreamMatchingWatchLabels() { | ||
s.T().Cleanup(func() { | ||
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, serviceWithLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assertions.NoError(err, "can delete service") | ||
|
||
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, serviceWithoutLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assertions.NoError(err, "can delete service") | ||
|
||
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, serviceWithNoMatchingLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assertions.NoError(err, "can delete service") | ||
}) | ||
|
||
// add one service with labels matching our watchLabels | ||
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, serviceWithLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assert().NoError(err, "can apply service") | ||
|
||
// add one service without labels matching our watchLabels | ||
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, serviceWithoutLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assert().NoError(err, "can apply service") | ||
|
||
// add one service with a label matching our watchLabels but with an unwatched value | ||
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, serviceWithNoMatchingLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assert().NoError(err, "can apply service") | ||
|
||
// eventually an Upstream should be created for the Service with matching labels | ||
labeledUsName := kubernetes.UpstreamName(s.testInstallation.Metadata.InstallNamespace, "example-svc", 8000) | ||
s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( | ||
func() (resources.InputResource, error) { | ||
return s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, labeledUsName, clients.ReadOpts{Ctx: s.ctx}) | ||
}, | ||
core.Status_Accepted, | ||
defaults.GlooReporter, | ||
) | ||
|
||
// the Upstream should have DiscoveryMetadata labels matching the parent Service | ||
us, err := s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, labeledUsName, clients.ReadOpts{Ctx: s.ctx}) | ||
s.Assert().NoError(err, "can read upstream") | ||
|
||
s.Assert().Equal(map[string]string{ | ||
"watchedKey": "watchedValue", | ||
"bonusKey": "bonusValue", | ||
}, us.GetDiscoveryMetadata().GetLabels()) | ||
|
||
// no Upstream should be created for the Service that does not have the watchLabels | ||
noLabelsUsName := kubernetes.UpstreamName(s.testInstallation.Metadata.InstallNamespace, "example-svc-no-labels", 8000) | ||
s.testInstallation.Assertions.ConsistentlyObjectsNotExist( | ||
s.ctx, &v1.Upstream{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: noLabelsUsName, | ||
Namespace: s.testInstallation.Metadata.InstallNamespace, | ||
}, | ||
}, | ||
) | ||
|
||
// no Upstream should be created for the Service that has a watched label without a watched value | ||
noMatchingLabelsUsName := kubernetes.UpstreamName(s.testInstallation.Metadata.InstallNamespace, "example-svc-no-matching-labels", 8000) | ||
s.testInstallation.Assertions.ConsistentlyObjectsNotExist( | ||
s.ctx, &v1.Upstream{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: noMatchingLabelsUsName, | ||
Namespace: s.testInstallation.Metadata.InstallNamespace, | ||
}, | ||
}, | ||
) | ||
|
||
// modify the non-watched label on the labeled service | ||
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, serviceWithModifiedLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assert().NoError(err, "can re-apply service") | ||
|
||
// expect the Upstream's DiscoveryMeta to eventually match the modified labels from the parent Service | ||
s.testInstallation.Assertions.Gomega.Eventually(func() (map[string]string, error) { | ||
us, err = s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, labeledUsName, clients.ReadOpts{Ctx: s.ctx}) | ||
return us.GetDiscoveryMetadata().GetLabels(), err | ||
}).Should(gomega.Equal(map[string]string{ | ||
"watchedKey": "watchedValue", | ||
"bonusKey": "bonusValue-modified", | ||
})) | ||
} | ||
|
||
func (s *discoveryWatchlabelsSuite) TestDiscoverySpecPreserved() { | ||
s.T().Cleanup(func() { | ||
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, serviceWithLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assertions.NoError(err, "can delete service") | ||
}) | ||
|
||
// add one service with labels matching our watchLabels | ||
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, serviceWithLabelsManifest, "-n", s.testInstallation.Metadata.InstallNamespace) | ||
s.Assert().NoError(err, "can apply service") | ||
|
||
// eventually an Upstream should be created for the Service with matching labels | ||
labeledUsName := kubernetes.UpstreamName(s.testInstallation.Metadata.InstallNamespace, "example-svc", 8000) | ||
s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( | ||
func() (resources.InputResource, error) { | ||
return s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, labeledUsName, clients.ReadOpts{Ctx: s.ctx}) | ||
}, | ||
core.Status_Accepted, | ||
defaults.GlooReporter, | ||
) | ||
|
||
// the Upstream should have DiscoveryMetadata labels matching the parent Service | ||
us, err := s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, labeledUsName, clients.ReadOpts{Ctx: s.ctx}) | ||
s.Assert().NoError(err, "can read upstream") | ||
|
||
s.Assert().NotNil(us.GetKube()) | ||
s.Assert().Nil(us.GetKube().GetServiceSpec()) | ||
|
||
// modify the Upstream to have a ServiceSpec | ||
us.GetKube().ServiceSpec = &options.ServiceSpec{ | ||
PluginType: &options.ServiceSpec_GrpcJsonTranscoder{}, | ||
} | ||
updatedUs, err := s.testInstallation.ResourceClients.UpstreamClient().Write(us, clients.WriteOpts{Ctx: s.ctx, OverwriteExisting: true}) | ||
s.Assert().NoError(err, "can update upstream") | ||
s.Assert().NotNil(updatedUs.GetKube().GetServiceSpec()) | ||
|
||
// expect the Upstream to consistently have the modified Spec | ||
s.testInstallation.Assertions.Gomega.Consistently(func() (*options.ServiceSpec, error) { | ||
us, err := s.testInstallation.ResourceClients.UpstreamClient().Read(us.GetMetadata().GetNamespace(), us.GetMetadata().GetName(), clients.ReadOpts{Ctx: s.ctx}) | ||
return us.GetKube().GetServiceSpec(), err | ||
}).Should(gomega.Not(gomega.BeNil())) | ||
} |
14 changes: 14 additions & 0 deletions
14
test/kubernetes/e2e/features/discovery_watchlabels/testdata/service-with-labels.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
watchedKey: watchedValue | ||
bonusKey: bonusValue | ||
name: example-svc | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8000 | ||
targetPort: 8080 | ||
selector: | ||
selectorKey: selectorValue |
14 changes: 14 additions & 0 deletions
14
.../kubernetes/e2e/features/discovery_watchlabels/testdata/service-with-modified-labels.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
watchedKey: watchedValue | ||
bonusKey: bonusValue-modified | ||
name: example-svc | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8000 | ||
targetPort: 8080 | ||
selector: | ||
selectorKey: selectorValue |
13 changes: 13 additions & 0 deletions
13
...bernetes/e2e/features/discovery_watchlabels/testdata/service-with-no-matching-labels.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
watchedKey: unwatchedValue | ||
name: example-svc-no-matching-labels | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8000 | ||
targetPort: 8080 | ||
selector: | ||
selectorKey: selectorValue |
11 changes: 11 additions & 0 deletions
11
test/kubernetes/e2e/features/discovery_watchlabels/testdata/service-without-labels.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: example-svc-no-labels | ||
spec: | ||
ports: | ||
- name: http | ||
port: 8000 | ||
targetPort: 8080 | ||
selector: | ||
selectorKey: selectorValue |
14 changes: 14 additions & 0 deletions
14
test/kubernetes/e2e/features/discovery_watchlabels/types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package discovery_watchlabels | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/solo-io/skv2/codegen/util" | ||
) | ||
|
||
var ( | ||
serviceWithLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-labels.yaml") | ||
serviceWithModifiedLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-modified-labels.yaml") | ||
serviceWithoutLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-without-labels.yaml") | ||
serviceWithNoMatchingLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-no-matching-labels.yaml") | ||
) |
Oops, something went wrong.