Repository: jenkins-x/lighthouse
Pull request #966 (2020-08-24 15:20:41)

chore: remove Gerrit config
This PR removes Gerrit config

jenkins-x-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **hferentschik**
You can assign the PR to them by writing `/assign @hferentschik` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=jenkins-x%2Flighthouse).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/jenkins-x/lighthouse/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["hferentschik"]} -->

Patch:
diff --git a/charts/lighthouse/templates/config-cm.yaml b/charts/lighthouse/templates/config-cm.yaml
index 749f7a1e..c9cc42e0 100644
--- a/charts/lighthouse/templates/config-cm.yaml
+++ b/charts/lighthouse/templates/config-cm.yaml
@@ -19,7 +19,6 @@ data:
     branch-protection:
       orgs: {}
       protect-tested-repos: true
-    gerrit: {}
     github:
       LinkURL: null
     owners_dir_excludes:
diff --git a/cmd/foghorn/main.go b/cmd/foghorn/main.go
index 1f62674a..01867b57 100644
--- a/cmd/foghorn/main.go
+++ b/cmd/foghorn/main.go
@@ -5,11 +5,11 @@ import (
 	"os"
 
 	lighthousev1alpha1 "github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
-	"github.com/jenkins-x/lighthouse/pkg/clients"
 	"github.com/jenkins-x/lighthouse/pkg/foghorn"
 	"github.com/jenkins-x/lighthouse/pkg/logrusutil"
 	"github.com/sirupsen/logrus"
 	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/client-go/tools/clientcmd"
 	ctrl "sigs.k8s.io/controller-runtime"
 )
 
@@ -46,7 +46,7 @@ func main() {
 		logrus.WithError(err).Fatal("Invalid options")
 	}
 
-	cfg, err := clients.GetConfig("", "")
+	cfg, err := clientcmd.BuildConfigFromFlags("", "")
 	if err != nil {
 		logrus.WithError(err).Fatal("Could not create kubeconfig")
 	}
diff --git a/cmd/gc/main.go b/cmd/gc/main.go
index f6dadcef..1dec2274 100644
--- a/cmd/gc/main.go
+++ b/cmd/gc/main.go
@@ -9,10 +9,10 @@ import (
 	"github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
 	clientset "github.com/jenkins-x/lighthouse/pkg/client/clientset/versioned"
 	lhclient "github.com/jenkins-x/lighthouse/pkg/client/clientset/versioned/typed/lighthouse/v1alpha1"
-	"github.com/jenkins-x/lighthouse/pkg/clients"
 	"github.com/jenkins-x/lighthouse/pkg/logrusutil"
 	"github.com/sirupsen/logrus"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/client-go/tools/clientcmd"
 )
 
 type options struct {
@@ -48,7 +48,7 @@ func main() {
 		logrus.WithError(err).Fatal("Invalid options")
 	}
 
-	cfg, err := clients.GetConfig("", "")
+	cfg, err := clientcmd.BuildConfigFromFlags("", "")
 	if err != nil {
 		logrus.WithError(err).Fatal("Could not create kubeconfig")
 	}
diff --git a/cmd/tektoncontroller/main.go b/cmd/tektoncontroller/main.go
index 82c1c477..ffb2dc2e 100644
--- a/cmd/tektoncontroller/main.go
+++ b/cmd/tektoncontroller/main.go
@@ -5,13 +5,13 @@ import (
 	"os"
 
 	lighthousev1alpha1 "github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
-	"github.com/jenkins-x/lighthouse/pkg/clients"
 	tektonengine "github.com/jenkins-x/lighthouse/pkg/engines/tekton"
 	"github.com/jenkins-x/lighthouse/pkg/interrupts"
 	"github.com/jenkins-x/lighthouse/pkg/logrusutil"
 	"github.com/sirupsen/logrus"
 	pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
 	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/client-go/tools/clientcmd"
 	ctrl "sigs.k8s.io/controller-runtime"
 )
 
@@ -52,7 +52,7 @@ func main() {
 		logrus.WithError(err).Fatal("Invalid options")
 	}
 
-	cfg, err := clients.GetConfig("", "")
+	cfg, err := clientcmd.BuildConfigFromFlags("", "")
 	if err != nil {
 		logrus.WithError(err).Fatal("Could not create kubeconfig")
 	}
diff --git a/config.yaml b/config.yaml
index fef13faf..4f7442d8 100644
--- a/config.yaml
+++ b/config.yaml
@@ -21,7 +21,6 @@ branch-protection:
             contexts:
               - pr-build
   protect-tested-repos: true
-gerrit: {}
 owners_dir_blacklist:
   default: null
   repos: null
diff --git a/docs/config/Lighthouse config.md b/docs/config/Lighthouse config.md
index 9a3303a4..528e5a9f 100644
--- a/docs/config/Lighthouse config.md
+++ b/docs/config/Lighthouse config.md
@@ -8,7 +8,6 @@
 - [ContextPolicy](#ContextPolicy)
 - [Controller](#Controller)
 - [Cookie](#Cookie)
-- [Gerrit](#Gerrit)
 - [GitHubOptions](#GitHubOptions)
 - [GithubOAuthConfig](#GithubOAuthConfig)
 - [JenkinsOperator](#JenkinsOperator)
@@ -123,16 +122,6 @@ Cookie holds the secret returned from github that authenticates the user who aut
 |---|---|---|---|---|
 | Secret | `secret` | string | No |  |
 
-## Gerrit
-
-Gerrit is config for the gerrit controller.
-
-| Variable Name | Stanza | Type | Required | Description |
-|---|---|---|---|---|
-| TickIntervalString | `tick_interval` | string | No | TickInterval is how often we do a sync with binded gerrit instance |
-| TickInterval | `-` | time.Duration | Yes |  |
-| RateLimit | `ratelimit` | int | No | RateLimit defines how many changes to query per gerrit API call<br />default is 5 |
-
 ## GitHubOptions
 
 GitHubOptions allows users to control how prow applications display GitHub website links.
@@ -415,7 +404,6 @@ ProwConfig is config for all prow controllers
 | Plank | `plank` | [Plank](#Plank) | No |  |
 | BranchProtection | `branch-protection` | [BranchProtection](#BranchProtection) | No |  |
 | Orgs | `orgs` | map[string]org.Config | No |  |
-| Gerrit | `gerrit` | [Gerrit](#Gerrit) | No |  |
 | JenkinsOperators | `jenkins_operators` | [][JenkinsOperator](#JenkinsOperator) | No | TODO: Move this out of the main config. |
 | LighthouseJobNamespace | `prowjob_namespace` | string | No | LighthouseJobNamespace is the namespace in the cluster that prow<br />components will use for looking up LighthouseJobs. The namespace<br />needs to exist and will not be created by prow.<br />Defaults to "default". |
 | PodNamespace | `pod_namespace` | string | No | PodNamespace is the namespace in the cluster that prow<br />components will use for looking up Pods owned by LighthouseJobs.<br />The namespace needs to exist and will not be created by prow.<br />Defaults to "default". |
diff --git a/pkg/clients/clients.go b/pkg/clients/clients.go
index f050b0fa..69145b96 100644
--- a/pkg/clients/clients.go
+++ b/pkg/clients/clients.go
@@ -1,11 +1,6 @@
 package clients
 
 import (
-	"fmt"
-	"os"
-	"os/user"
-	"path/filepath"
-
 	clientset "github.com/jenkins-x/lighthouse/pkg/client/clientset/versioned"
 	"github.com/pkg/errors"
 	"k8s.io/client-go/rest"
@@ -20,7 +15,7 @@ import (
 
 // GetAPIClients returns the tekton, kube, and Lighthouse clients and the kubeconfig used to create them
 func GetAPIClients() (tektonclient.Interface, kubeclient.Interface, clientset.Interface, *rest.Config, error) {
-	kubeCfg, err := GetConfig("", "")
+	kubeCfg, err := clientcmd.BuildConfigFromFlags("", "")
 	if err != nil {
 		return nil, nil, nil, nil, errors.Wrap(err, "unable to get kubeconfig")
 	}
@@ -42,31 +37,3 @@ func GetAPIClients() (tektonclient.Interface, kubeclient.Interface, clientset.In
 
 	return tektonClient, kubeClient, lhClient, kubeCfg, nil
 }
-
-// GetConfig returns a rest.Config to be used for kubernetes client creation.
-// It does so in the following order:
-//   1. Use the passed kubeconfig/masterURL.
-//   2. Fallback to the KUBECONFIG environment variable.
-//   3. Fallback to in-cluster config.
-//   4. Fallback to the ~/.kube/config.
-func GetConfig(masterURL, kubeconfig string) (*rest.Config, error) {
-	if kubeconfig == "" {
-		kubeconfig = os.Getenv("KUBECONFIG")
-	}
-	// If we have an explicit indication of where the kubernetes config lives, read that.
-	if kubeconfig != "" {
-		return clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
-	}
-	// If not, try the in-cluster config.
-	if c, err := rest.InClusterConfig(); err == nil {
-		return c, nil
-	}
-	// If no in-cluster config, try the default location in the user's home directory.
-	if usr, err := user.Current(); err == nil {
-		if c, err := clientcmd.BuildConfigFromFlags("", filepath.Join(usr.HomeDir, ".kube", "config")); err == nil {
-			return c, nil
-		}
-	}
-
-	return nil, fmt.Errorf("could not create a valid kubeconfig")
-}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index cb7bf2ba..1558e13d 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -75,7 +75,6 @@ type ProwConfig struct {
 	Plank            Plank                 `json:"plank,omitempty"`
 	BranchProtection BranchProtection      `json:"branch-protection,omitempty"`
 	Orgs             map[string]org.Config `json:"orgs,omitempty"`
-	Gerrit           Gerrit                `json:"gerrit,omitempty"`
 
 	// TODO: Move this out of the main config.
 	JenkinsOperators []JenkinsOperator `json:"jenkins_operators,omitempty"`
@@ -198,16 +197,6 @@ type Plank struct {
 	ReportTemplate *template.Template `json:"-"`
 }
 
-// Gerrit is config for the gerrit controller.
-type Gerrit struct {
-	// TickInterval is how often we do a sync with binded gerrit instance
-	TickIntervalString string        `json:"tick_interval,omitempty"`
-	TickInterval       time.Duration `json:"-"`
-	// RateLimit defines how many changes to query per gerrit API call
-	// default is 5
-	RateLimit int `json:"ratelimit,omitempty"`
-}
-
 // JenkinsOperator is config for the jenkins-operator controller.
 type JenkinsOperator struct {
 	Controller `json:",inline"`
@@ -721,20 +710,6 @@ func parseProwConfig(c *Config) error {
 	}
 	c.Plank.ReportTemplate = reportTmpl
 
-	if c.Gerrit.TickIntervalString == "" {
-		c.Gerrit.TickInterval = time.Minute
-	} else {
-		tickInterval, err := time.ParseDuration(c.Gerrit.TickIntervalString)
-		if err != nil {
-			return fmt.Errorf("cannot parse duration for c.gerrit.tick_interval: %v", err)
-		}
-		c.Gerrit.TickInterval = tickInterval
-	}
-
-	if c.Gerrit.RateLimit == 0 {
-		c.Gerrit.RateLimit = 5
-	}
-
 	for i := range c.JenkinsOperators {
 		if err := ValidateController(&c.JenkinsOperators[i].Controller); err != nil {
 			return fmt.Errorf("validating jenkins_operators config: %v", err)


Test patch:
diff --git a/pkg/foghorn/controller_test.go b/pkg/foghorn/controller_test.go
index e85ebd95..a182a7d4 100644
--- a/pkg/foghorn/controller_test.go
+++ b/pkg/foghorn/controller_test.go
@@ -47,7 +47,6 @@ func TestReconcile(t *testing.T) {
 			Plank:                  config.Plank{},
 			BranchProtection:       config.BranchProtection{},
 			Orgs:                   nil,
-			Gerrit:                 config.Gerrit{},
 			JenkinsOperators:       nil,
 			LighthouseJobNamespace: "",
 			PodNamespace:           "",
diff --git a/pkg/repoconfig/merge/test_data/simple/expected-config.yaml b/pkg/repoconfig/merge/test_data/simple/expected-config.yaml
index 6ea8420a..ebe9c82e 100644
--- a/pkg/repoconfig/merge/test_data/simple/expected-config.yaml
+++ b/pkg/repoconfig/merge/test_data/simple/expected-config.yaml
@@ -6,7 +6,6 @@ branch-protection:
           required_status_checks:
             contexts:
             - lint
-gerrit: {}
 github:
   LinkURL: null
 owners_dir_blacklist:
diff --git a/pkg/repoconfig/merge/test_data/simple/source-config.yaml b/pkg/repoconfig/merge/test_data/simple/source-config.yaml
index 19456fe0..b60e2d51 100644
--- a/pkg/repoconfig/merge/test_data/simple/source-config.yaml
+++ b/pkg/repoconfig/merge/test_data/simple/source-config.yaml
@@ -1,5 +1,4 @@
 branch-protection: {}
-gerrit: {}
 github:
   LinkURL: null
 owners_dir_blacklist:
diff --git a/pkg/webhook/test_data/test_config.yaml b/pkg/webhook/test_data/test_config.yaml
index 819ec71d..addde5ff 100644
--- a/pkg/webhook/test_data/test_config.yaml
+++ b/pkg/webhook/test_data/test_config.yaml
@@ -65,7 +65,6 @@ branch-protection:
             contexts:
             - pr-build
   protect-tested-repos: true
-gerrit: {}
 owners_dir_excludes:
   default: null
   repos: null
diff --git a/test/e2e/test_data/example-config.tmpl.yml b/test/e2e/test_data/example-config.tmpl.yml
index 20b9b373..6a4a092c 100644
--- a/test/e2e/test_data/example-config.tmpl.yml
+++ b/test/e2e/test_data/example-config.tmpl.yml
@@ -7,7 +7,6 @@ branch-protection:
             contexts:
             - pr-build
   protect-tested-repos: true
-gerrit: {}
 github:
   LinkURL: null
 owners_dir_excludes: