Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelogs/unreleased/5686-izturn-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add flags: `--incluster`, `--kubeconfig` for enable run the `gateway-provisioner` in or out of the cluster.
21 changes: 19 additions & 2 deletions cmd/contour/gatewayprovisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
"fmt"
"os"

"github.com/novln/docker-parser/distribution/reference"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/provisioner"
"github.com/projectcontour/contour/internal/provisioner/controller"
"github.com/projectcontour/contour/pkg/config"

"github.com/alecthomas/kingpin/v2"
"github.com/novln/docker-parser/distribution/reference"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -56,6 +57,11 @@ func registerGatewayProvisioner(app *kingpin.Application) (*kingpin.CmdClause, *
Default(provisionerConfig.gatewayControllerName).
StringVar(&provisionerConfig.gatewayControllerName)

cmd.Flag("incluster", "Use in cluster configuration.").BoolVar(&provisionerConfig.inCluster)
Comment thread
izturn marked this conversation as resolved.
Outdated
cmd.Flag("kubeconfig", "Path to kubeconfig (if not in running inside a cluster).").
PlaceHolder("/path/to/file").
StringVar(&provisionerConfig.kubeconfig)

cmd.Flag("leader-election-namespace", "The namespace in which the leader election resource will be created.").
Default(config.GetenvOr("CONTOUR_PROVISIONER_NAMESPACE", "projectcontour")).
StringVar(&provisionerConfig.leaderElectionNamespace)
Expand Down Expand Up @@ -95,6 +101,10 @@ type gatewayProvisionerConfig struct {
// gatewayControllerName defines the controller string that this gateway provisioner instance
// will process GatewayClasses and Gateways for.
gatewayControllerName string

// Kubernetes client parameters.
inCluster bool `yaml:"incluster,omitempty"`
Comment thread
izturn marked this conversation as resolved.
Outdated
kubeconfig string `yaml:"kubeconfig,omitempty"`
}

func runGatewayProvisioner(config *gatewayProvisionerConfig) {
Expand All @@ -111,7 +121,14 @@ func runGatewayProvisioner(config *gatewayProvisionerConfig) {
setupLog.Info("using contour", "image", config.contourImage)
setupLog.Info("using envoy", "image", config.envoyImage)

mgr, err := createManager(ctrl.GetConfigOrDie(), config)
// Establish k8s core client connection.
restConfig, err := k8s.NewRestConfig(config.kubeconfig, config.inCluster)
if err != nil {
setupLog.Error(err, "failed to create REST config for Kubernetes clients")
os.Exit(1)
}

mgr, err := createManager(restConfig, config)
if err != nil {
setupLog.Error(err, "failed to create contour gateway provisioner")
os.Exit(1)
Expand Down