Skip to content
Closed
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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/nginxinc/nginx-gateway-fabric

go 1.22.0
go 1.22.6

require (
github.com/go-kit/log v0.2.1
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.9.0
github.com/nginxinc/nginx-plus-go-client v1.3.0
github.com/nginxinc/nginx-plus-go-client/v2 v2.0.1
github.com/nginxinc/nginx-prometheus-exporter v1.3.0
github.com/nginxinc/telemetry-exporter v0.1.2
github.com/onsi/ginkgo/v2 v2.20.2
Expand Down Expand Up @@ -60,6 +60,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nginxinc/nginx-plus-go-client v1.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nginxinc/nginx-plus-go-client v1.3.0 h1:q/aeT4B5k0KLwWlefoBzfLfraBBvIKLuDg+lLFWAo4I=
github.com/nginxinc/nginx-plus-go-client v1.3.0/go.mod h1:n8OFLzrJulJ2fur28Cwa1Qp5DZNS2VicLV+Adt30LQ4=
github.com/nginxinc/nginx-plus-go-client v1.2.2 h1:sl7HqNDDZq2EVu0eQQVoZ6PKYGa4h2dB/Qr5Ib0YKGw=
github.com/nginxinc/nginx-plus-go-client v1.2.2/go.mod h1:n8OFLzrJulJ2fur28Cwa1Qp5DZNS2VicLV+Adt30LQ4=
github.com/nginxinc/nginx-plus-go-client/v2 v2.0.1 h1:5VVK38bnELMDWnwfF6dSv57ResXh9AUzeDa72ENj94o=
github.com/nginxinc/nginx-plus-go-client/v2 v2.0.1/go.mod h1:He+1izxYxVVO5/C9ZTukwOpvkAx5eS19nRQgKXDhX5I=
github.com/nginxinc/nginx-prometheus-exporter v1.3.0 h1:1JtdxsZH0Uwhu1nL/j/QyOXytP5V5j68AEo2X+DFWb0=
github.com/nginxinc/nginx-prometheus-exporter v1.3.0/go.mod h1:hXoH+X6aIKSyQuO6QTIiPKH3eZyxqy/wW8GYiE3dflU=
github.com/nginxinc/telemetry-exporter v0.1.2 h1:97vUGhQYgQ2KEsXKCBmr5gqfuujJCKPHwdg5HKoANUs=
Expand Down
4 changes: 2 additions & 2 deletions internal/mode/static/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/go-logr/logr"
ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -349,7 +349,7 @@ func (h *eventHandlerImpl) updateUpstreamServers(
}
var upstreams []upstream

prevUpstreams, err := h.cfg.nginxRuntimeMgr.GetUpstreams()
prevUpstreams, err := h.cfg.nginxRuntimeMgr.GetUpstreams(context.TODO())
if err != nil {
logger.Error(err, "failed to get upstreams from API, reloading configuration instead")
return reload()
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"context"
"errors"

ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap"
Expand All @@ -27,7 +27,7 @@
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/configfakes"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file/filefakes"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes"

Check failure on line 30 in internal/mode/static/handler_test.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

could not import github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes (-: # github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/dataplane"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/metrics/collectors/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"fmt"

"github.com/go-kit/log"
"github.com/nginxinc/nginx-plus-go-client/client"
"github.com/nginxinc/nginx-plus-go-client/v2/client"
prometheusClient "github.com/nginxinc/nginx-prometheus-exporter/client"
nginxCollector "github.com/nginxinc/nginx-prometheus-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -37,7 +37,7 @@
panic(fmt.Sprintf("expected *client.NginxClient, got %T", plusClient))
}
collector := nginxCollector.NewNginxPlusCollector(
nc,

Check failure on line 40 in internal/mode/static/metrics/collectors/nginx.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

cannot use nc (variable of type *"github.com/nginxinc/nginx-plus-go-client/v2/client".NginxClient) as *"github.com/nginxinc/nginx-plus-go-client/client".NginxClient value in argument to nginxCollector.NewNginxPlusCollector (typecheck)

Check failure on line 40 in internal/mode/static/metrics/collectors/nginx.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

cannot use nc (variable of type *"github.com/nginxinc/nginx-plus-go-client/v2/client".NginxClient) as *"github.com/nginxinc/nginx-plus-go-client/client".NginxClient value in argument to nginxCollector.NewNginxPlusCollector) (typecheck)
metrics.Namespace,
nginxCollector.VariableLabelNames{},
constLabels,
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/nginx/config/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"fmt"

ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"

"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/resolver"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/nginx/config/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"testing"

ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"
. "github.com/onsi/gomega"

"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/resolver"
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/nginx/runtime/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net"
"net/http"

"github.com/nginxinc/nginx-plus-go-client/client"
"github.com/nginxinc/nginx-plus-go-client/v2/client"
)

const (
Expand Down
13 changes: 7 additions & 6 deletions internal/mode/static/nginx/runtime/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/go-logr/logr"
ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"
"k8s.io/apimachinery/pkg/util/wait"
)

Expand All @@ -38,6 +38,7 @@ var childProcPathFmt = "/proc/%[1]v/task/%[1]v/children"

type NginxPlusClient interface {
UpdateHTTPServers(
ctx context.Context,
upstream string,
servers []ngxclient.UpstreamServer,
) (
Expand All @@ -46,7 +47,7 @@ type NginxPlusClient interface {
updated []ngxclient.UpstreamServer,
err error,
)
GetUpstreams() (*ngxclient.Upstreams, error)
GetUpstreams(ctx context.Context) (*ngxclient.Upstreams, error)
}

//counterfeiter:generate . Manager
Expand All @@ -62,7 +63,7 @@ type Manager interface {
UpdateHTTPServers(string, []ngxclient.UpstreamServer) error
// GetUpstreams uses the NGINX Plus API to get the upstreams.
// Only usable if running NGINX Plus.
GetUpstreams() (ngxclient.Upstreams, error)
GetUpstreams(ctx context.Context) (ngxclient.Upstreams, error)
}

// MetricsCollector is an interface for the metrics of the NGINX runtime manager.
Expand Down Expand Up @@ -150,7 +151,7 @@ func (m *ManagerImpl) UpdateHTTPServers(upstream string, servers []ngxclient.Ups
panic("cannot update HTTP upstream servers: NGINX Plus not enabled")
}

added, deleted, updated, err := m.ngxPlusClient.UpdateHTTPServers(upstream, servers)
added, deleted, updated, err := m.ngxPlusClient.UpdateHTTPServers(context.TODO(), upstream, servers)
m.logger.V(1).Info("Added upstream servers", "count", len(added))
m.logger.V(1).Info("Deleted upstream servers", "count", len(deleted))
m.logger.V(1).Info("Updated upstream servers", "count", len(updated))
Expand All @@ -160,12 +161,12 @@ func (m *ManagerImpl) UpdateHTTPServers(upstream string, servers []ngxclient.Ups

// GetUpstreams uses the NGINX Plus API to get the upstreams.
// Only usable if running NGINX Plus.
func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error) {
func (m *ManagerImpl) GetUpstreams(ctx context.Context) (ngxclient.Upstreams, error) {
if !m.IsPlus() {
panic("cannot get HTTP upstream servers: NGINX Plus not enabled")
}

upstreams, err := m.ngxPlusClient.GetUpstreams()
upstreams, err := m.ngxPlusClient.GetUpstreams(ctx)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/mode/static/nginx/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"testing"
"time"

ngxclient "github.com/nginxinc/nginx-plus-go-client/client"
ngxclient "github.com/nginxinc/nginx-plus-go-client/v2/client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes"

Check failure on line 17 in internal/mode/static/nginx/runtime/manager_test.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

could not import github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes (-: # github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime/runtimefakes [github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime.test]
)

var _ = Describe("NGINX Runtime Manager", func() {
Expand Down Expand Up @@ -151,7 +151,7 @@
})

It("returns no upstreams from NGINX Plus API when upstreams are nil", func() {
upstreams, err := manager.GetUpstreams()
upstreams, err := manager.GetUpstreams(context.Background())

Expect(err).To(HaveOccurred())
Expect(upstreams).To(BeEmpty())
Expand Down Expand Up @@ -179,7 +179,7 @@

ngxPlusClient.GetUpstreamsReturns(&expUpstreams, nil)

upstreams, err := manager.GetUpstreams()
upstreams, err := manager.GetUpstreams(context.Background())

Expect(err).NotTo(HaveOccurred())
Expect(expUpstreams).To(Equal(upstreams))
Expand All @@ -188,7 +188,7 @@
It("returns an error when GetUpstreams fails", func() {
ngxPlusClient.GetUpstreamsReturns(nil, errors.New("failed to get upstreams"))

upstreams, err := manager.GetUpstreams()
upstreams, err := manager.GetUpstreams(context.Background())

Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("failed to get upstreams"))
Expand All @@ -213,7 +213,7 @@

It("should panic when fetching HTTP upstream servers", func() {
upstreams := func() {
_, err = manager.GetUpstreams()
_, err = manager.GetUpstreams(context.Background())
}

Expect(upstreams).To(Panic())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nginxinc/nginx-gateway-fabric/tests

go 1.22.2
go 1.22.6

require (
github.com/nginxinc/nginx-gateway-fabric v0.0.0
Expand Down
Loading