Skip to content

Support multiple commands in gateway binary #656

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 7 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 7 additions & 7 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ func createRootCommand() *cobra.Command {
return rootCmd
}

func createControlPlaneCommand() *cobra.Command {
func createStaticModeCommand() *cobra.Command {
return &cobra.Command{
Use: "control-plane",
Short: "Start the control plane",
Use: "static-mode",
Short: "Configure NGINX in the scope of a single Gateway resource",
RunE: func(cmd *cobra.Command, args []string) error {
logger := zap.New()
logger.Info("Starting NGINX Kubernetes Gateway Control Plane",
logger.Info("Starting NGINX Kubernetes Gateway in static mode",
"version", version,
"commit", commit,
"date", date,
Expand All @@ -116,10 +116,10 @@ func createControlPlaneCommand() *cobra.Command {
}
}

func createProvisionerCommand() *cobra.Command {
func createProvisionerModeCommand() *cobra.Command {
return &cobra.Command{
Use: "provisioner",
Short: "Start the provisioner",
Use: "provisioner-mode",
Short: "Provision an NGINX Gateway Deployment per Gateway resource configured in the static mode",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
logger := zap.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRootCmdFlagValidation(t *testing.T) {
expectedErrPrefix: `required flag(s) "gateway-ctlr-name" not set`,
},
{
name: "gateway-ctrl-name is set to empty string",
name: "gateway-ctlr-name is set to empty string",
args: []string{
"--gateway-ctlr-name=",
"--gatewayclass=nginx",
Expand Down
7 changes: 4 additions & 3 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ var (
func main() {
rootCmd := createRootCommand()

rootCmd.AddCommand(createControlPlaneCommand())
p := createProvisionerCommand()
rootCmd.AddCommand(p)
rootCmd.AddCommand(
createStaticModeCommand(),
createProvisionerModeCommand(),
)

if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
// nolint:lll
// Regex from: https://github.com/kubernetes-sigs/gateway-api/blob/v0.6.2/apis/v1beta1/shared_types.go#L495
// Regex from: https://github.com/kubernetes-sigs/gateway-api/blob/v0.7.0/apis/v1beta1/shared_types.go#L495
controllerNameRegex = `^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$` //nolint:lll
)

Expand Down
2 changes: 1 addition & 1 deletion deploy/manifests/nginx-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
fieldRef:
fieldPath: status.podIP
args:
- control-plane
- static-mode
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
- --gatewayclass=nginx
- image: nginx:1.23
Expand Down
10 changes: 7 additions & 3 deletions docs/cli-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

This document describes the commands available in the `gateway` binary of `nginx-kubernetes-gateway` container.

## Control Plane
## Static Mode

This command starts the control plane.
This command configures NGINX in the scope of a single Gateway resource. In case of multiple Gateway resources created
in the cluster, NGINX Kubernetes Gateway will use a deterministic conflict resolution strategy: it will choose the
oldest resource by creation timestamp. If the timestamps are equal, NGINX Kubernetes Gateway will choose the resource
that appears first in alphabetical order by “{namespace}/{name}”. We might support multiple Gateway resources. Please
share your use case with us if you're interested in that support.

Usage:

```
gateway control-plane [flags]
gateway static-mode [flags]
```

Flags:
Expand Down
6 changes: 4 additions & 2 deletions docs/gateway-api-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ For a description of each field, visit the [Gateway API documentation](https://g
> Status: Partially supported.

NGINX Kubernetes Gateway supports only a single GatewayClass resource configured via `--gatewayclass` flag
of the [control-plane](./cli-help.md#control-plane) command.
of the [static-mode](./cli-help.md#static-mode) command.

Fields:
* `spec`
Expand All @@ -49,7 +49,9 @@ Fields:

> Status: Partially supported.

NGINX Kubernetes Gateway supports only a single Gateway resource. The Gateway resource must reference NGINX Kubernetes Gateway's corresponding GatewayClass. In case of multiple Gateway resources created in the cluster, NGINX Kubernetes Gateway will use a deterministic conflict resolution strategy: it will choose the oldest resource by creation timestamp. If the timestamps are equal, NGINX Kubernetes Gateway will choose the resource that appears first in alphabetical order by “{namespace}/{name}”. We might support multiple Gateway resources. Please share your use case with us if you're interested in that support.
NGINX Kubernetes Gateway supports only a single Gateway resource. The Gateway resource must reference NGINX Kubernetes Gateway's corresponding GatewayClass.
In case of multiple Gateway resources created in the cluster, NGINX Kubernetes Gateway will use a deterministic conflict resolution strategy.
See [static-mode](./cli-help.md#static-mode) command for more info.

Fields:
* `spec`
Expand Down