-
Notifications
You must be signed in to change notification settings - Fork 118
Adding Gateway Controller #5
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
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
kind: Gateway | ||
metadata: | ||
name: gateway | ||
namespace: nginx-gateway | ||
labels: | ||
domain: k8s-gateway.nginx.org | ||
spec: | ||
gatewayClassName: nginx | ||
f5yacobucci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
listeners: | ||
- name: my-listener | ||
hostname: example.com | ||
port: 8080 | ||
protocol: HTTP |
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,10 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/go-logr/logr" | ||
) | ||
|
||
type Config struct { | ||
GatewayCtlrName string | ||
Logger logr.Logger | ||
} |
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,50 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nginxinc/nginx-gateway-kubernetes/internal/config" | ||
gw "github.com/nginxinc/nginx-gateway-kubernetes/internal/implementations/gateway" | ||
gc "github.com/nginxinc/nginx-gateway-kubernetes/internal/implementations/gatewayclass" | ||
"github.com/nginxinc/nginx-gateway-kubernetes/pkg/sdk" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctlr "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
) | ||
|
||
var ( | ||
scheme = runtime.NewScheme() | ||
) | ||
|
||
func init() { | ||
_ = gatewayv1alpha2.AddToScheme(scheme) | ||
} | ||
|
||
func Start(conf config.Config) error { | ||
logger := conf.Logger | ||
|
||
options := manager.Options{ | ||
Scheme: scheme, | ||
} | ||
|
||
mgr, err := manager.New(ctlr.GetConfigOrDie(), options) | ||
if err != nil { | ||
return fmt.Errorf("cannot build runtime manager: %w", err) | ||
} | ||
|
||
err = sdk.RegisterGatewayController(mgr, gw.NewGatewayImplementation(conf)) | ||
if err != nil { | ||
return fmt.Errorf("cannot register gateway implementation: %w", err) | ||
} | ||
err = sdk.RegisterGatewayClassController(mgr, gc.NewGatewayClassImplementation(conf)) | ||
if err != nil { | ||
return fmt.Errorf("cannot reguster gatewayclass implementation: %w", err) | ||
} | ||
|
||
ctx := ctlr.SetupSignalHandler() | ||
|
||
logger.Info("Starting manager") | ||
return mgr.Start(ctx) | ||
} |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
package implementation | ||
|
||
import ( | ||
"github.com/go-logr/logr" | ||
"github.com/nginxinc/nginx-gateway-kubernetes/internal/config" | ||
"github.com/nginxinc/nginx-gateway-kubernetes/pkg/sdk" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
) | ||
|
||
type gatewayImplementation struct { | ||
conf config.Config | ||
} | ||
|
||
func NewGatewayImplementation(conf config.Config) sdk.GatewayImpl { | ||
return &gatewayImplementation{ | ||
conf: conf, | ||
} | ||
} | ||
|
||
func (impl *gatewayImplementation) Logger() logr.Logger { | ||
return impl.conf.Logger | ||
} | ||
|
||
func (impl *gatewayImplementation) ControllerName() string { | ||
return impl.conf.GatewayCtlrName | ||
} | ||
|
||
func (impl *gatewayImplementation) Upsert(gw *v1alpha2.Gateway) { | ||
if gw.Name == impl.ControllerName() { | ||
impl.Logger().Info("Found correct Gateway resource", | ||
"name", gw.Name, | ||
) | ||
return | ||
} | ||
} | ||
|
||
func (impl *gatewayImplementation) Remove(key string) { | ||
impl.Logger().Info("Gateway resource was removed", | ||
"name", key, | ||
) | ||
} |
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,43 @@ | ||
package implementation | ||
|
||
import ( | ||
"github.com/nginxinc/nginx-gateway-kubernetes/internal/config" | ||
"github.com/nginxinc/nginx-gateway-kubernetes/pkg/sdk" | ||
|
||
"github.com/go-logr/logr" | ||
"sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
) | ||
|
||
type gatewayClassImplementation struct { | ||
conf config.Config | ||
} | ||
|
||
func NewGatewayClassImplementation(conf config.Config) sdk.GatewayClassImpl { | ||
return &gatewayClassImplementation{ | ||
conf: conf, | ||
} | ||
} | ||
|
||
func (impl *gatewayClassImplementation) Logger() logr.Logger { | ||
return impl.conf.Logger | ||
} | ||
|
||
func (impl *gatewayClassImplementation) ControllerName() string { | ||
return impl.conf.GatewayCtlrName | ||
} | ||
|
||
func (impl *gatewayClassImplementation) Upsert(gc *v1alpha2.GatewayClass) { | ||
if string(gc.Spec.ControllerName) != impl.ControllerName() { | ||
impl.Logger().Info("Wrong ControllerName in the GatewayClass resource", | ||
"expected", impl.ControllerName(), | ||
"got", gc.Spec.ControllerName) | ||
return | ||
} | ||
|
||
impl.Logger().Info("Processing GatewayClass resource", | ||
"name", gc.Name) | ||
} | ||
func (impl *gatewayClassImplementation) Remove(key string) { | ||
impl.Logger().Info("GatewayClass resource was removed", | ||
"name", key) | ||
} |
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.