Skip to content

Commit

Permalink
gateway provisioner: add flags to enable running provisioner out of c…
Browse files Browse the repository at this point in the history
…luster (#5686)

Adds --incluster and --kubeconfig flags to
the gateway provisioner to enable running
outside of the cluster.

Signed-off-by: gang.liu <[email protected]>
  • Loading branch information
izturn authored Oct 4, 2023
1 parent 7feb49e commit e6f33bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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.
26 changes: 23 additions & 3 deletions cmd/contour/gatewayprovisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
"fmt"
"os"

"github.com/alecthomas/kingpin/v2"
"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 +58,13 @@ func registerGatewayProvisioner(app *kingpin.Application) (*kingpin.CmdClause, *
Default(provisionerConfig.gatewayControllerName).
StringVar(&provisionerConfig.gatewayControllerName)

cmd.Flag("incluster", "Use in cluster configuration.").
Default("true").
BoolVar(&provisionerConfig.inCluster)
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 +104,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
kubeconfig string
}

func runGatewayProvisioner(config *gatewayProvisionerConfig) {
Expand All @@ -111,7 +124,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

0 comments on commit e6f33bf

Please sign in to comment.