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

gateway-provisoner: add flags for enable run provisioner out of cluster #5686

Merged
merged 5 commits into from
Oct 4, 2023
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)
izturn marked this conversation as resolved.
Show resolved Hide resolved
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"`
izturn marked this conversation as resolved.
Show resolved Hide resolved
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