Skip to content

Commit 0edc138

Browse files
authored
Merge branch 'change/control-data-plane-split' into docs/update-accessing-nginx-containers
2 parents 9829eb1 + e2115c3 commit 0edc138

29 files changed

+1019
-635
lines changed

apis/v1alpha2/nginxproxy_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ type ServiceSpec struct {
517517
// +optional
518518
LoadBalancerIP *string `json:"loadBalancerIP,omitempty"`
519519

520+
// LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
521+
// Requires service type to be LoadBalancer.
522+
//
523+
// +optional
524+
LoadBalancerClass *string `json:"loadBalancerClass,omitempty"`
525+
520526
// Annotations contain any Service-specific annotations.
521527
//
522528
// +optional

apis/v1alpha2/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/nginx-gateway-fabric/values.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ nginx:
427427
# -- The static IP address for the load balancer. Requires nginx.service.type set to LoadBalancer.
428428
# loadBalancerIP: ""
429429

430+
# -- LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
431+
# Requires nginx.service.type set to LoadBalancer.
432+
# loadBalancerClass: ""
433+
430434
# -- The IP ranges (CIDR) that are allowed to access the load balancer. Requires nginx.service.type set to LoadBalancer.
431435
# loadBalancerSourceRanges: []
432436

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,11 @@ spec:
34823482
- Cluster
34833483
- Local
34843484
type: string
3485+
loadBalancerClass:
3486+
description: |-
3487+
LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
3488+
Requires service type to be LoadBalancer.
3489+
type: string
34853490
loadBalancerIP:
34863491
description: LoadBalancerIP is a static IP address for the
34873492
load balancer. Requires service type to be LoadBalancer.

deploy/crds.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -4067,6 +4067,11 @@ spec:
40674067
- Cluster
40684068
- Local
40694069
type: string
4070+
loadBalancerClass:
4071+
description: |-
4072+
LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
4073+
Requires service type to be LoadBalancer.
4074+
type: string
40704075
loadBalancerIP:
40714076
description: LoadBalancerIP is a static IP address for the
40724077
load balancer. Requires service type to be LoadBalancer.

internal/mode/static/handler.go

+35-75
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,21 @@ type objectFilter struct {
109109
// (3) Updating control plane configuration.
110110
// (4) Tracks the NGINX Plus usage reporting Secret (if applicable).
111111
type eventHandlerImpl struct {
112-
// latestConfiguration is the latest Configuration generation.
113-
latestConfiguration *dataplane.Configuration
112+
// latestConfigurations are the latest Configuration generation for each Gateway tree.
113+
latestConfigurations map[types.NamespacedName]*dataplane.Configuration
114114

115115
// objectFilters contains all created objectFilters, with the key being a filterKey
116116
objectFilters map[filterKey]objectFilter
117117

118118
cfg eventHandlerConfig
119119
lock sync.Mutex
120-
121-
// version is the current version number of the nginx config.
122-
version int
123120
}
124121

125122
// newEventHandlerImpl creates a new eventHandlerImpl.
126123
func newEventHandlerImpl(cfg eventHandlerConfig) *eventHandlerImpl {
127124
handler := &eventHandlerImpl{
128-
cfg: cfg,
125+
cfg: cfg,
126+
latestConfigurations: make(map[types.NamespacedName]*dataplane.Configuration),
129127
}
130128

131129
handler.objectFilters = map[filterKey]objectFilter{
@@ -158,28 +156,23 @@ func (h *eventHandlerImpl) HandleEventBatch(ctx context.Context, logger logr.Log
158156
h.parseAndCaptureEvent(ctx, logger, event)
159157
}
160158

161-
changeType, gr := h.cfg.processor.Process()
159+
gr := h.cfg.processor.Process()
162160

163161
// Once we've processed resources on startup and built our first graph, mark the Pod as ready.
164162
if !h.cfg.graphBuiltHealthChecker.ready {
165163
h.cfg.graphBuiltHealthChecker.setAsReady()
166164
}
167165

168-
h.sendNginxConfig(ctx, logger, gr, changeType)
166+
h.sendNginxConfig(ctx, logger, gr)
169167
}
170168

171169
// enable is called when the pod becomes leader to ensure the provisioner has
172170
// the latest configuration.
173171
func (h *eventHandlerImpl) enable(ctx context.Context) {
174-
h.sendNginxConfig(ctx, h.cfg.logger, h.cfg.processor.GetLatestGraph(), state.ClusterStateChange)
172+
h.sendNginxConfig(ctx, h.cfg.logger, h.cfg.processor.GetLatestGraph())
175173
}
176174

177-
func (h *eventHandlerImpl) sendNginxConfig(
178-
ctx context.Context,
179-
logger logr.Logger,
180-
gr *graph.Graph,
181-
changeType state.ChangeType,
182-
) {
175+
func (h *eventHandlerImpl) sendNginxConfig(ctx context.Context, logger logr.Logger, gr *graph.Graph) {
183176
if gr == nil {
184177
return
185178
}
@@ -215,68 +208,30 @@ func (h *eventHandlerImpl) sendNginxConfig(
215208
panic("expected deployment, got nil")
216209
}
217210

218-
configApplied := h.processStateAndBuildConfig(ctx, logger, gr, gw, changeType, deployment)
219-
220-
configErr := deployment.GetLatestConfigError()
221-
upstreamErr := deployment.GetLatestUpstreamError()
222-
err := errors.Join(configErr, upstreamErr)
223-
224-
if configApplied || err != nil {
225-
obj := &status.QueueObject{
226-
UpdateType: status.UpdateAll,
227-
Error: err,
228-
Deployment: gw.DeploymentName,
229-
}
230-
h.cfg.statusQueue.Enqueue(obj)
231-
}
232-
}
233-
}
234-
235-
func (h *eventHandlerImpl) processStateAndBuildConfig(
236-
ctx context.Context,
237-
logger logr.Logger,
238-
gr *graph.Graph,
239-
currentGateway *graph.Gateway,
240-
changeType state.ChangeType,
241-
deployment *agent.Deployment,
242-
) bool {
243-
var configApplied bool
244-
switch changeType {
245-
case state.EndpointsOnlyChange:
246-
h.version++
247-
cfg := dataplane.BuildConfiguration(ctx, gr, currentGateway, h.cfg.serviceResolver, h.version, h.cfg.plus)
211+
cfg := dataplane.BuildConfiguration(ctx, gr, gw, h.cfg.serviceResolver, h.cfg.plus)
248212
depCtx, getErr := h.getDeploymentContext(ctx)
249213
if getErr != nil {
250214
logger.Error(getErr, "error getting deployment context for usage reporting")
251215
}
252216
cfg.DeploymentContext = depCtx
253217

254-
h.setLatestConfiguration(&cfg)
218+
h.setLatestConfiguration(gw, &cfg)
255219

256220
deployment.FileLock.Lock()
257-
if h.cfg.plus {
258-
configApplied = h.cfg.nginxUpdater.UpdateUpstreamServers(deployment, cfg)
259-
} else {
260-
configApplied = h.updateNginxConf(deployment, cfg)
261-
}
221+
h.updateNginxConf(deployment, cfg)
262222
deployment.FileLock.Unlock()
263-
case state.ClusterStateChange:
264-
h.version++
265-
cfg := dataplane.BuildConfiguration(ctx, gr, currentGateway, h.cfg.serviceResolver, h.version, h.cfg.plus)
266-
depCtx, getErr := h.getDeploymentContext(ctx)
267-
if getErr != nil {
268-
logger.Error(getErr, "error getting deployment context for usage reporting")
269-
}
270-
cfg.DeploymentContext = depCtx
271223

272-
h.setLatestConfiguration(&cfg)
224+
configErr := deployment.GetLatestConfigError()
225+
upstreamErr := deployment.GetLatestUpstreamError()
226+
err := errors.Join(configErr, upstreamErr)
273227

274-
deployment.FileLock.Lock()
275-
configApplied = h.updateNginxConf(deployment, cfg)
276-
deployment.FileLock.Unlock()
228+
obj := &status.QueueObject{
229+
UpdateType: status.UpdateAll,
230+
Error: err,
231+
Deployment: gw.DeploymentName,
232+
}
233+
h.cfg.statusQueue.Enqueue(obj)
277234
}
278-
279-
return configApplied
280235
}
281236

282237
func (h *eventHandlerImpl) waitForStatusUpdates(ctx context.Context) {
@@ -451,16 +406,14 @@ func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr
451406
func (h *eventHandlerImpl) updateNginxConf(
452407
deployment *agent.Deployment,
453408
conf dataplane.Configuration,
454-
) bool {
409+
) {
455410
files := h.cfg.generator.Generate(conf)
456-
applied := h.cfg.nginxUpdater.UpdateConfig(deployment, files)
411+
h.cfg.nginxUpdater.UpdateConfig(deployment, files)
457412

458413
// If using NGINX Plus, update upstream servers using the API.
459414
if h.cfg.plus {
460415
h.cfg.nginxUpdater.UpdateUpstreamServers(deployment, conf)
461416
}
462-
463-
return applied
464417
}
465418

466419
// updateControlPlaneAndSetStatus updates the control plane configuration and then sets the status
@@ -570,21 +523,28 @@ func (h *eventHandlerImpl) getDeploymentContext(ctx context.Context) (dataplane.
570523
}
571524

572525
// GetLatestConfiguration gets the latest configuration.
573-
func (h *eventHandlerImpl) GetLatestConfiguration() *dataplane.Configuration {
526+
func (h *eventHandlerImpl) GetLatestConfiguration() []*dataplane.Configuration {
574527
h.lock.Lock()
575528
defer h.lock.Unlock()
576529

577-
return h.latestConfiguration
530+
configs := make([]*dataplane.Configuration, 0, len(h.latestConfigurations))
531+
for _, cfg := range h.latestConfigurations {
532+
configs = append(configs, cfg)
533+
}
534+
535+
return configs
578536
}
579537

580538
// setLatestConfiguration sets the latest configuration.
581-
// TODO(sberman): once we support multiple Gateways, this will likely have to be a map
582-
// of all configurations.
583-
func (h *eventHandlerImpl) setLatestConfiguration(cfg *dataplane.Configuration) {
539+
func (h *eventHandlerImpl) setLatestConfiguration(gateway *graph.Gateway, cfg *dataplane.Configuration) {
540+
if gateway == nil || gateway.Source == nil {
541+
return
542+
}
543+
584544
h.lock.Lock()
585545
defer h.lock.Unlock()
586546

587-
h.latestConfiguration = cfg
547+
h.latestConfigurations[client.ObjectKeyFromObject(gateway.Source)] = cfg
588548
}
589549

590550
func objectFilterKey(obj client.Object, nsName types.NamespacedName) filterKey {

0 commit comments

Comments
 (0)