Repository navigation
fix: preserve shared GatewayProxy resources when deleting Gateways #495
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
Open
AlinsRan
wants to merge
8
commits into
master
Choose a base branch
from
fix/conformance-core-backends
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
15105db
fix: preserve shared GatewayProxy resources when deleting Gateways
AlinsRan 1b32830
fix: reconcile attached routes when a Gateway is deleted
AlinsRan cd3f45a
test: wait for data plane updates and pod termination
AlinsRan 66938e9
fix: resolve surviving route parents after Gateway deletion
AlinsRan a4b8e7d
fix: clear GatewayProxy plugins once its last Gateway is gone
AlinsRan 6f1e335
chore: narrow the route parent lock and extend the pod termination wait
AlinsRan 01c3195
fix: push evicted Gateway plugins after an API7EE Gateway deletion
AlinsRan 3e6283c
fix: consume API7EE sync notifications when periodic sync is disabled
AlinsRan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
|
|
||
| "github.com/apache/apisix-ingress-controller/internal/controller/config" | ||
| ) | ||
|
|
||
| type resolvedParentClass struct { | ||
| gatewayUID types.UID | ||
| class *gatewayv1.GatewayClass | ||
| } | ||
|
|
||
| type routeParentOwnership struct { | ||
| uid types.UID | ||
| parents map[client.ObjectKey]resolvedParentClass | ||
| } | ||
|
|
||
| // routeParentResolver remembers ownership only for parents previously resolved | ||
| // for this route. A never-resolved sibling must not prevent deletion cleanup. | ||
| // Like the provider's desired configuration, this state is rebuilt on startup. | ||
| type routeParentResolver struct { | ||
| mu sync.Mutex | ||
| parents map[client.ObjectKey]routeParentOwnership | ||
| } | ||
|
|
||
| func (r *routeParentResolver) Forget(key client.ObjectKey) { | ||
| r.mu.Lock() | ||
| defer r.mu.Unlock() | ||
| delete(r.parents, key) | ||
| } | ||
|
|
||
| func (r *routeParentResolver) Resolve(ctx context.Context, cli client.Client, log logr.Logger, route client.Object, refs []gatewayv1.ParentReference) ([]RouteParentRefContext, error) { | ||
| // controller-runtime never reconciles one route concurrently, so the lock only | ||
| // guards the map, not the parent lookups between the read and the write. | ||
| routeKey := client.ObjectKeyFromObject(route) | ||
| r.mu.Lock() | ||
| previous := r.parents[routeKey].parents | ||
| if r.parents[routeKey].uid != route.GetUID() { | ||
| previous = nil | ||
| } | ||
| r.mu.Unlock() | ||
| next := make(map[client.ObjectKey]resolvedParentClass) | ||
| gateways, err := parseRouteParentRefs(ctx, cli, log, route, refs, func(gw *gatewayv1.Gateway) (*gatewayv1.GatewayClass, error) { | ||
| key := client.ObjectKeyFromObject(gw) | ||
| gc := &gatewayv1.GatewayClass{} | ||
| if err := cli.Get(ctx, client.ObjectKey{Name: string(gw.Spec.GatewayClassName)}, gc); err != nil { | ||
| if client.IgnoreNotFound(err) != nil { | ||
| return nil, err | ||
| } | ||
| known, ok := previous[key] | ||
| if !ok || known.gatewayUID != gw.UID || known.class.Name != string(gw.Spec.GatewayClassName) { | ||
| return nil, nil | ||
| } | ||
| // Keep resolving the surviving Gateway's current listeners without | ||
| // retaining configuration belonging to a different, deleted parent. | ||
| gc = known.class | ||
| } | ||
| if string(gc.Spec.ControllerName) == config.ControllerConfig.ControllerName { | ||
| next[key] = resolvedParentClass{gatewayUID: gw.UID, class: gc} | ||
| } | ||
| return gc, nil | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| r.mu.Lock() | ||
| defer r.mu.Unlock() | ||
| if len(next) == 0 { | ||
| delete(r.parents, routeKey) | ||
| } else { | ||
| if r.parents == nil { | ||
| r.parents = make(map[client.ObjectKey]routeParentOwnership) | ||
| } | ||
| r.parents[routeKey] = routeParentOwnership{uid: route.GetUID(), parents: next} | ||
| } | ||
| return gateways, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.