Skip to content

Commit 1ed290e

Browse files
committed
Add updates so functional tests pass
1 parent d74a78d commit 1ed290e

16 files changed

+265
-178
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
145145
return Data{}, fmt.Errorf("failed to collect cluster information: %w", err)
146146
}
147147

148-
graphResourceCount, err := collectGraphResourceCount(g, c.cfg.ConfigurationGetter)
149-
if err != nil {
150-
return Data{}, fmt.Errorf("failed to collect NGF resource counts: %w", err)
151-
}
148+
graphResourceCount := collectGraphResourceCount(g, c.cfg.ConfigurationGetter)
152149

153150
replicaSet, err := getPodReplicaSet(ctx, c.cfg.K8sClientReader, c.cfg.PodNSName)
154151
if err != nil {
@@ -193,13 +190,16 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
193190
func collectGraphResourceCount(
194191
g *graph.Graph,
195192
configurationGetter ConfigurationGetter,
196-
) (NGFResourceCounts, error) {
193+
) NGFResourceCounts {
197194
ngfResourceCounts := NGFResourceCounts{}
198195
cfg := configurationGetter.GetLatestConfiguration()
199196

200-
if cfg == nil {
201-
return ngfResourceCounts, errors.New("latest configuration cannot be nil")
202-
}
197+
// might need to change this and make this optional, if cfg is nil then we can't report on upstream count but
198+
// we can do everything else.
199+
200+
// if cfg == nil {
201+
// return ngfResourceCounts, errors.New("latest configuration cannot be nil")
202+
//}
203203

204204
ngfResourceCounts.GatewayClassCount = int64(len(g.IgnoredGatewayClasses))
205205
if g.GatewayClass != nil {
@@ -219,9 +219,11 @@ func collectGraphResourceCount(
219219
ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets))
220220
ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices))
221221

222-
for _, upstream := range cfg.Upstreams {
223-
if upstream.ErrorMsg == "" {
224-
ngfResourceCounts.EndpointCount += int64(len(upstream.Endpoints))
222+
if cfg != nil {
223+
for _, upstream := range cfg.Upstreams {
224+
if upstream.ErrorMsg == "" {
225+
ngfResourceCounts.EndpointCount += int64(len(upstream.Endpoints))
226+
}
225227
}
226228
}
227229

@@ -249,7 +251,7 @@ func collectGraphResourceCount(
249251
ngfResourceCounts.NginxProxyCount = int64(len(g.ReferencedNginxProxies))
250252
ngfResourceCounts.SnippetsFilterCount = int64(len(g.SnippetsFilters))
251253

252-
return ngfResourceCounts, nil
254+
return ngfResourceCounts
253255
}
254256

255257
type RouteCounts struct {

internal/mode/static/telemetry/collector_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,6 @@ var _ = Describe("Collector", Ordered, func() {
728728
_, err := dataCollector.Collect(ctx)
729729
Expect(err).To(MatchError(expectedError))
730730
})
731-
732-
It("should error on nil latest configuration", func(ctx SpecContext) {
733-
expectedError := errors.New("latest configuration cannot be nil")
734-
fakeConfigurationGetter.GetLatestConfigurationReturns(nil)
735-
736-
_, err := dataCollector.Collect(ctx)
737-
Expect(err).To(MatchError(expectedError))
738-
})
739731
})
740732
})
741733
})

tests/framework/collector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func InstallCollector() ([]byte, error) {
2828
return output, err
2929
}
3030

31+
if output, err := exec.Command(
32+
"helm",
33+
"repo",
34+
"update",
35+
).CombinedOutput(); err != nil {
36+
return output, fmt.Errorf("failed to update helm repos: %w; output: %s", err, string(output))
37+
}
38+
3139
args := []string{
3240
"install",
3341
collectorChartReleaseName,

tests/framework/crossplane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func injectCrossplaneContainer(
203203
func createCrossplaneExecutor(
204204
k8sClient kubernetes.Interface,
205205
k8sConfig *rest.Config,
206-
ngfPodName,
206+
nginxPodName,
207207
namespace string,
208208
) (remotecommand.Executor, error) {
209209
cmd := []string{"./crossplane", "/etc/nginx/nginx.conf"}
@@ -217,7 +217,7 @@ func createCrossplaneExecutor(
217217
req := k8sClient.CoreV1().RESTClient().Post().
218218
Resource("pods").
219219
SubResource("exec").
220-
Name(ngfPodName).
220+
Name(nginxPodName).
221221
Namespace(namespace).
222222
VersionedParams(opts, scheme.ParameterCodec)
223223

tests/framework/portforward.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ func PortForward(config *rest.Config, namespace, podName string, ports []string,
5252
for {
5353
if err := forward(); err != nil {
5454
slog.Error("error forwarding ports", "error", err)
55-
slog.Info("retrying port forward in 100ms...")
55+
slog.Info("retrying port forward in 1s...")
5656
}
5757

5858
select {
5959
case <-stopCh:
6060
return
61-
case <-time.After(100 * time.Millisecond):
61+
case <-time.After(1 * time.Second):
6262
// retrying
6363
}
6464
}

tests/framework/resourcemanager.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,40 @@ func GetReadyNGFPodNames(
719719
return nil, errors.New("unable to find NGF Pod(s)")
720720
}
721721

722+
// GetReadyNginxPodNames returns the name(s) of the Nginx Pod(s).
723+
func GetReadyNginxPodNames(
724+
k8sClient client.Client,
725+
namespace string,
726+
timeout time.Duration,
727+
) ([]string, error) {
728+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
729+
defer cancel()
730+
731+
var podList core.PodList
732+
if err := k8sClient.List(
733+
ctx,
734+
&podList,
735+
client.InNamespace(namespace),
736+
client.HasLabels{"gateway.networking.k8s.io/gateway-name"},
737+
); err != nil {
738+
return nil, fmt.Errorf("error getting list of Nginx Pods: %w", err)
739+
}
740+
741+
if len(podList.Items) > 0 {
742+
var names []string
743+
for _, pod := range podList.Items {
744+
for _, cond := range pod.Status.Conditions {
745+
if cond.Type == core.PodReady && cond.Status == core.ConditionTrue {
746+
names = append(names, pod.Name)
747+
}
748+
}
749+
}
750+
return names, nil
751+
}
752+
753+
return nil, errors.New("unable to find NGF Pod(s)")
754+
}
755+
722756
func countNumberOfReadyParents(parents []v1.RouteParentStatus) int {
723757
readyCount := 0
724758

@@ -760,7 +794,7 @@ func (rm *ResourceManager) WaitForAppsToBeReadyWithCtxWithPodCount(
760794
return rm.waitForGatewaysToBeReady(ctx, namespace)
761795
}
762796

763-
// WaitForPodsToBeReady waits for all Pods in the specified namespace to be ready or
797+
// WaitForPodsToBeReadyWithCount waits for all Pods in the specified namespace to be ready or
764798
// until the provided context is canceled.
765799
func (rm *ResourceManager) WaitForPodsToBeReadyWithCount(ctx context.Context, namespace string, count int) error {
766800
return wait.PollUntilContextCancel(
@@ -817,17 +851,17 @@ func (rm *ResourceManager) WaitForGatewayObservedGeneration(
817851
}
818852

819853
// GetNginxConfig uses crossplane to get the nginx configuration and convert it to JSON.
820-
func (rm *ResourceManager) GetNginxConfig(ngfPodName, namespace string) (*Payload, error) {
854+
func (rm *ResourceManager) GetNginxConfig(nginxPodName, namespace string) (*Payload, error) {
821855
if err := injectCrossplaneContainer(
822856
rm.ClientGoClient,
823857
rm.TimeoutConfig.UpdateTimeout,
824-
ngfPodName,
858+
nginxPodName,
825859
namespace,
826860
); err != nil {
827861
return nil, err
828862
}
829863

830-
exec, err := createCrossplaneExecutor(rm.ClientGoClient, rm.K8sConfig, ngfPodName, namespace)
864+
exec, err := createCrossplaneExecutor(rm.ClientGoClient, rm.K8sConfig, nginxPodName, namespace)
831865
if err != nil {
832866
return nil, err
833867
}

tests/suite/advanced_routing_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ var _ = Describe("AdvancedRouting", Ordered, Label("functional", "routing"), fun
3939
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
4040
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
4141
Expect(resourceManager.WaitForAppsToBeReady(namespace)).To(Succeed())
42+
43+
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, namespace, timeoutConfig.GetTimeout)
44+
Expect(err).ToNot(HaveOccurred())
45+
Expect(nginxPodNames).To(HaveLen(1))
46+
47+
setUpPortForward(nginxPodNames[0], namespace)
4248
})
4349

4450
AfterAll(func() {
51+
cleanUpPortForward()
52+
4553
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
4654
Expect(resourceManager.DeleteNamespace(namespace)).To(Succeed())
4755
})

tests/suite/client_settings_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var _ = Describe("ClientSettingsPolicy", Ordered, Label("functional", "cspolicy"
3232
}
3333

3434
namespace = "clientsettings"
35+
36+
nginxPodName string
3537
)
3638

3739
BeforeAll(func() {
@@ -44,9 +46,19 @@ var _ = Describe("ClientSettingsPolicy", Ordered, Label("functional", "cspolicy"
4446
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
4547
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
4648
Expect(resourceManager.WaitForAppsToBeReady(namespace)).To(Succeed())
49+
50+
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, namespace, timeoutConfig.GetTimeout)
51+
Expect(err).ToNot(HaveOccurred())
52+
Expect(nginxPodNames).To(HaveLen(1))
53+
54+
nginxPodName = nginxPodNames[0]
55+
56+
setUpPortForward(nginxPodName, namespace)
4757
})
4858

4959
AfterAll(func() {
60+
cleanUpPortForward()
61+
5062
Expect(resourceManager.DeleteNamespace(namespace)).To(Succeed())
5163
})
5264

@@ -96,13 +108,8 @@ var _ = Describe("ClientSettingsPolicy", Ordered, Label("functional", "cspolicy"
96108
filePrefix := fmt.Sprintf("/etc/nginx/includes/ClientSettingsPolicy_%s", namespace)
97109

98110
BeforeAll(func() {
99-
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
100-
Expect(err).ToNot(HaveOccurred())
101-
Expect(podNames).To(HaveLen(1))
102-
103-
ngfPodName := podNames[0]
104-
105-
conf, err = resourceManager.GetNginxConfig(ngfPodName, ngfNamespace)
111+
var err error
112+
conf, err = resourceManager.GetNginxConfig(nginxPodName, namespace)
106113
Expect(err).ToNot(HaveOccurred())
107114
})
108115

tests/suite/dataplane_perf_test.go

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,60 @@ import (
1818
)
1919

2020
var _ = Describe("Dataplane performance", Ordered, Label("nfr", "performance"), func() {
21-
files := []string{
22-
"dp-perf/coffee.yaml",
23-
"dp-perf/gateway.yaml",
24-
"dp-perf/cafe-routes.yaml",
25-
}
26-
27-
var ns core.Namespace
28-
29-
var addr string
30-
targetURL := "http://cafe.example.com"
31-
var outFile *os.File
32-
33-
t1 := framework.Target{
34-
Method: "GET",
35-
URL: fmt.Sprintf("%s%s", targetURL, "/latte"),
36-
}
37-
t2 := framework.Target{
38-
Method: "GET",
39-
URL: fmt.Sprintf("%s%s", targetURL, "/coffee"),
40-
Header: http.Header{"version": []string{"v2"}},
41-
}
42-
t3 := framework.Target{
43-
Method: "GET",
44-
URL: fmt.Sprintf("%s%s", targetURL, "/coffee?TEST=v2"),
45-
}
46-
t4 := framework.Target{
47-
Method: "GET",
48-
URL: fmt.Sprintf("%s%s", targetURL, "/tea"),
49-
}
50-
t5 := framework.Target{
51-
Method: "POST",
52-
URL: fmt.Sprintf("%s%s", targetURL, "/tea"),
53-
}
21+
var (
22+
files = []string{
23+
"dp-perf/coffee.yaml",
24+
"dp-perf/gateway.yaml",
25+
"dp-perf/cafe-routes.yaml",
26+
}
27+
28+
namespace = "dp-perf"
29+
30+
targetURL = "http://cafe.example.com"
31+
32+
t1 = framework.Target{
33+
Method: "GET",
34+
URL: fmt.Sprintf("%s%s", targetURL, "/latte"),
35+
}
36+
t2 = framework.Target{
37+
Method: "GET",
38+
URL: fmt.Sprintf("%s%s", targetURL, "/coffee"),
39+
Header: http.Header{"version": []string{"v2"}},
40+
}
41+
t3 = framework.Target{
42+
Method: "GET",
43+
URL: fmt.Sprintf("%s%s", targetURL, "/coffee?TEST=v2"),
44+
}
45+
t4 = framework.Target{
46+
Method: "GET",
47+
URL: fmt.Sprintf("%s%s", targetURL, "/tea"),
48+
}
49+
t5 = framework.Target{
50+
Method: "POST",
51+
URL: fmt.Sprintf("%s%s", targetURL, "/tea"),
52+
}
53+
54+
outFile *os.File
55+
addr string
56+
)
5457

5558
BeforeAll(func() {
56-
ns = core.Namespace{
59+
ns := core.Namespace{
5760
ObjectMeta: metav1.ObjectMeta{
58-
Name: "dp-perf",
61+
Name: namespace,
5962
},
6063
}
6164

6265
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
6366
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
6467
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
6568

69+
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, namespace, timeoutConfig.GetTimeout)
70+
Expect(err).ToNot(HaveOccurred())
71+
Expect(nginxPodNames).To(HaveLen(1))
72+
73+
setUpPortForward(nginxPodNames[0], namespace)
74+
6675
port := ":80"
6776
if portFwdPort != 0 {
6877
port = fmt.Sprintf(":%s", strconv.Itoa(portFwdPort))
@@ -79,8 +88,10 @@ var _ = Describe("Dataplane performance", Ordered, Label("nfr", "performance"),
7988
})
8089

8190
AfterAll(func() {
82-
Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed())
83-
Expect(resourceManager.DeleteNamespace(ns.Name)).To(Succeed())
91+
cleanUpPortForward()
92+
93+
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
94+
Expect(resourceManager.DeleteNamespace(namespace)).To(Succeed())
8495
outFile.Close()
8596
})
8697

tests/suite/manifests/tracing/nginxproxy.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)