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

[provider] refactoring kubernetes provider to single reconciler #702

Merged
merged 26 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa66419
refactoring kubernetes provider to single reconciler
chauhanshubham Nov 6, 2022
cd1d76b
fix
chauhanshubham Nov 12, 2022
a5f2e59
enqueue svc/dep for owning gateways
chauhanshubham Nov 12, 2022
ef921c8
refactor2.0
chauhanshubham Nov 20, 2022
a9cc473
reconcile if svc is not present, updates
chauhanshubham Nov 20, 2022
5ad712d
update subscriber for gapi objs
chauhanshubham Nov 20, 2022
a25e884
remove tests of old functions
chauhanshubham Nov 20, 2022
215c43e
uncomment refgrant conformance tests
chauhanshubham Nov 21, 2022
2de5687
fix reconciliation logic around returning non nil errors
chauhanshubham Nov 21, 2022
0201c64
deepcopy
chauhanshubham Nov 21, 2022
25c045c
few updates
chauhanshubham Nov 21, 2022
db41511
testfix conformance failure fixes
chauhanshubham Nov 22, 2022
5480e4a
return err and requeue on failed class update
chauhanshubham Nov 22, 2022
0711567
addressed review comments - 1
chauhanshubham Nov 30, 2022
d120c23
lintfix
chauhanshubham Nov 30, 2022
4ce9fd0
secret filter
chauhanshubham Nov 30, 2022
3f725dd
lint
chauhanshubham Nov 30, 2022
eecaf96
additions
chauhanshubham Dec 1, 2022
5ccf77c
always get
chauhanshubham Dec 1, 2022
89e2c07
service filter
chauhanshubham Dec 2, 2022
17f5447
eventual check
chauhanshubham Dec 2, 2022
d7feaf2
Adds Gateway Deletion Support to Controller
danehans Dec 2, 2022
b910b06
Merge pull request #1 from danehans/provider-refactor-fix-gw-delete
chauhanshubham Dec 2, 2022
772bca7
updates
chauhanshubham Dec 2, 2022
3bb2362
lastleg
chauhanshubham Dec 3, 2022
c7f4cd5
gtw list len check for secret predicate
chauhanshubham Dec 5, 2022
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
9 changes: 1 addition & 8 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,9 @@ func setupRunners(cfg *config.Server) error {
// Wait until done
<-ctx.Done()
// Close messages
pResources.GatewayClasses.Close()
pResources.Gateways.Close()
pResources.HTTPRoutes.Close()
pResources.Services.Close()
pResources.Secrets.Close()
pResources.ReferenceGrants.Close()
pResources.Namespaces.Close()
pResources.GatewayAPIResources.Close()
pResources.GatewayStatuses.Close()
pResources.HTTPRouteStatuses.Close()
pResources.TLSRoutes.Close()
pResources.TLSRouteStatuses.Close()
xdsIR.Close()
infraIR.Close()
Expand Down
49 changes: 49 additions & 0 deletions internal/gatewayapi/helpers_v1alpha2.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,55 @@ func DowngradeRouteParentStatuses(routeParentStatuses []v1beta1.RouteParentStatu
return res
}

// UpgradeBackendRef converts v1alpha2.BackendRef to v1beta1.BackendRef
func UpgradeBackendRef(old v1alpha2.BackendRef) v1beta1.BackendRef {
upgraded := v1beta1.BackendRef{}

if old.Group != nil {
upgraded.Group = GroupPtr(string(*old.Group))
}

if old.Kind != nil {
upgraded.Kind = KindPtr(string(*old.Kind))
}

if old.Namespace != nil {
upgraded.Namespace = NamespacePtr(string(*old.Namespace))
}

upgraded.Name = v1beta1.ObjectName(old.Name)

if old.Port != nil {
upgraded.Port = PortNumPtr(int32(*old.Port))
}

return upgraded
}

func DowngradeBackendRef(old v1beta1.BackendRef) v1alpha2.BackendRef {
downgraded := v1alpha2.BackendRef{}

if old.Group != nil {
downgraded.Group = GroupPtrV1Alpha2(string(*old.Group))
}

if old.Kind != nil {
downgraded.Kind = KindPtrV1Alpha2(string(*old.Kind))
}

if old.Namespace != nil {
downgraded.Namespace = NamespacePtrV1Alpha2(string(*old.Namespace))
}

downgraded.Name = v1alpha2.ObjectName(old.Name)

if old.Port != nil {
downgraded.Port = PortNumPtrV1Alpha2(int(*old.Port))
}

return downgraded
}

func NamespaceDerefOrAlpha(namespace *v1alpha2.Namespace, defaultNamespace string) string {
if namespace != nil && *namespace != "" {
return string(*namespace)
Expand Down
56 changes: 12 additions & 44 deletions internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,20 @@ func (r *Runner) Start(ctx context.Context) error {
}

func (r *Runner) subscribeAndTranslate(ctx context.Context) {
// Subscribe to resources
gatewayClassesCh := r.ProviderResources.GatewayClasses.Subscribe(ctx)
gatewaysCh := r.ProviderResources.Gateways.Subscribe(ctx)
secretsCh := r.ProviderResources.Secrets.Subscribe(ctx)
refGrantsCh := r.ProviderResources.ReferenceGrants.Subscribe(ctx)
httpRoutesCh := r.ProviderResources.HTTPRoutes.Subscribe(ctx)
tlsRoutesCh := r.ProviderResources.TLSRoutes.Subscribe(ctx)
servicesCh := r.ProviderResources.Services.Subscribe(ctx)
namespacesCh := r.ProviderResources.Namespaces.Subscribe(ctx)

for ctx.Err() == nil {
var in gatewayapi.Resources
// Receive subscribed resource notifications
select {
case <-gatewayClassesCh:
case <-gatewaysCh:
case <-secretsCh:
case <-refGrantsCh:
case <-httpRoutesCh:
case <-tlsRoutesCh:
case <-servicesCh:
case <-namespacesCh:
}
r.Logger.Info("received a notification")
// Load all resources required for translation
in.Gateways = r.ProviderResources.GetGateways()
in.Secrets = r.ProviderResources.GetSecrets()
in.ReferenceGrants = r.ProviderResources.GetReferenceGrants()
in.HTTPRoutes = r.ProviderResources.GetHTTPRoutes()
in.TLSRoutes = r.ProviderResources.GetTLSRoutes()
in.Services = r.ProviderResources.GetServices()
in.Namespaces = r.ProviderResources.GetNamespaces()
gatewayClasses := r.ProviderResources.GetGatewayClasses()
// Fetch the first gateway class since there should be only 1
// gateway class linked to this controller
switch {
case gatewayClasses == nil:
// Envoy Gateway startup.
continue
default:
message.HandleSubscription(r.ProviderResources.GatewayAPIResources.Subscribe(ctx),
func(update message.Update[string, *gatewayapi.Resources]) {
val := update.Value

if update.Delete || val == nil {
return
}

// Translate and publish IRs.
t := &gatewayapi.Translator{
GatewayClassName: v1beta1.ObjectName(gatewayClasses[0].GetName()),
GatewayClassName: v1beta1.ObjectName(update.Key),
}
// Translate to IR
result := t.Translate(&in)
result := t.Translate(val)

yamlXdsIR, _ := yaml.Marshal(&result.XdsIR)
r.Logger.WithValues("output", "xds-ir").Info(string(yamlXdsIR))
Expand Down Expand Up @@ -143,8 +111,8 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) {
key := utils.NamespacedName(tlsRoute)
r.ProviderResources.TLSRouteStatuses.Store(key, tlsRoute)
}
}
}
},
)
r.Logger.Info("shutting down")
}

Expand Down
4 changes: 1 addition & 3 deletions internal/gatewayapi/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/types"

"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/ir"
Expand Down Expand Up @@ -45,8 +44,7 @@ func TestRunner(t *testing.T) {
// TODO: pass valid provider resources

// Delete gateway from the map.
key := types.NamespacedName{Namespace: "test", Name: "test"}
pResources.Gateways.Delete(key)
pResources.GatewayAPIResources.Delete("test")
require.Eventually(t, func() bool {
out := xdsIR.LoadAll()
if out == nil {
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type InfraIRMap map[string]*ir.Infra

// Resources holds the Gateway API and related
// resources that the translators needs as inputs.
// +k8s:deepcopy-gen=true
type Resources struct {
Gateways []*v1beta1.Gateway
HTTPRoutes []*v1beta1.HTTPRoute
Expand Down
109 changes: 109 additions & 0 deletions internal/gatewayapi/zz_generated.deepcopy.go

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

Loading