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

add missing tests for external traffic policy gateway params #10562

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/v1.19.0-beta3/add-missing-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NON_USER_FACING
description: >
Add missing e2e suite test for checking gateway param eternal traffic policy
26 changes: 26 additions & 0 deletions pkg/utils/kubeutils/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kubeutils

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)

// GetService gets the service from the provided name/namespace
func GetService(
ctx context.Context,
kubeClient *kubernetes.Clientset,
serviceName string,
serviceNamespace string,
) (*corev1.Service, error) {

service, err := kubeClient.CoreV1().Services(serviceNamespace).Get(ctx, serviceName, metav1.GetOptions{})
if err != nil {
return nil, err
}

return service, nil
}
4 changes: 4 additions & 0 deletions test/kubernetes/e2e/features/deployer/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func (s *testingSuite) TestProvisionResourcesUpdatedWithValidParameters() {
s.patchGatewayParameters(gwParamsDefault.ObjectMeta, func(parameters *v1alpha1.GatewayParameters) {
parameters.Spec.Kube.Service.ExternalTrafficPolicy = ptr.To(corev1.ServiceExternalTrafficPolicyLocal)
})

// the GatewayParameters modification should cause the deployer to re-run and update the
// service to have ExternalTrafficPolicy = Local
s.testInstallation.Assertions.EventuallyExternalTrafficPolicy(s.ctx, *proxyService, gomega.Equal(corev1.ServiceExternalTrafficPolicyLocal))
}

func (s *testingSuite) TestProvisionResourcesNotUpdatedWithInvalidParameters() {
Expand Down
23 changes: 23 additions & 0 deletions test/kubernetes/testutils/assertions/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package assertions

import (
"context"
"time"

. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
"github.com/solo-io/gloo/pkg/utils/kubeutils"
corev1 "k8s.io/api/core/v1"
)

func (p *Provider) EventuallyExternalTrafficPolicy(ctx context.Context, service corev1.Service, externalTrafficPolicyMatcher types.GomegaMatcher) {
p.Gomega.Eventually(func(innerG Gomega) {
service, err := kubeutils.GetService(ctx, p.clusterContext.Clientset, service.Name, service.Namespace)
innerG.Expect(err).NotTo(HaveOccurred(), "can get service")
innerG.Expect(service.Spec.ExternalTrafficPolicy).To(externalTrafficPolicyMatcher, "externalTrafficPolicy to match")
}).
WithContext(ctx).
WithTimeout(time.Second * 30).
WithPolling(time.Millisecond * 200).
Should(Succeed())
}