mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 16:12:07 +02:00
Linter-induced code refactoring, run round 2. (#360)
Run more linters in the gometalinter, i.e. deadcode, megacheck, nakedret, dup. More consistent code formatting, remove two dead functions, eliminate naked a bunch of naked returns, refactor a few functions to avoid code duplication.
This commit is contained in:
@@ -169,7 +169,7 @@ func (c *Controller) initPodServiceAccount() {
|
||||
func (c *Controller) initRoleBinding() {
|
||||
|
||||
// service account on its own lacks any rights starting with k8s v1.8
|
||||
// operator binds it to the cluster role with sufficient priviliges
|
||||
// operator binds it to the cluster role with sufficient privileges
|
||||
// we assume the role is created by the k8s administrator
|
||||
if c.opConfig.PodServiceAccountRoleBindingDefinition == "" {
|
||||
c.opConfig.PodServiceAccountRoleBindingDefinition = `
|
||||
@@ -199,9 +199,9 @@ func (c *Controller) initRoleBinding() {
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
panic(fmt.Errorf("Unable to parse the definiton of the role binding for the pod service account definiton from the operator config map: %v", err))
|
||||
panic(fmt.Errorf("Unable to parse the definition of the role binding for the pod service account definition from the operator config map: %v", err))
|
||||
case groupVersionKind.Kind != "RoleBinding":
|
||||
panic(fmt.Errorf("role binding definiton in the operator config map defines another type of resource: %v", groupVersionKind.Kind))
|
||||
panic(fmt.Errorf("role binding definition in the operator config map defines another type of resource: %v", groupVersionKind.Kind))
|
||||
default:
|
||||
c.PodServiceAccountRoleBinding = obj.(*rbacv1beta1.RoleBinding)
|
||||
c.PodServiceAccountRoleBinding.Namespace = ""
|
||||
|
||||
+15
-30
@@ -40,19 +40,9 @@ func (c *Controller) dispatchPodEvent(clusterName spec.NamespacedName, event spe
|
||||
}
|
||||
|
||||
func (c *Controller) podAdd(obj interface{}) {
|
||||
pod, ok := obj.(*v1.Pod)
|
||||
if !ok {
|
||||
return
|
||||
if pod, ok := obj.(*v1.Pod); ok {
|
||||
c.preparePodEventForDispatch(pod, nil, spec.EventAdd)
|
||||
}
|
||||
|
||||
podEvent := spec.PodEvent{
|
||||
PodName: util.NameFromMeta(pod.ObjectMeta),
|
||||
CurPod: pod,
|
||||
EventType: spec.EventAdd,
|
||||
ResourceVersion: pod.ResourceVersion,
|
||||
}
|
||||
|
||||
c.dispatchPodEvent(c.podClusterName(pod), podEvent)
|
||||
}
|
||||
|
||||
func (c *Controller) podUpdate(prev, cur interface{}) {
|
||||
@@ -66,29 +56,24 @@ func (c *Controller) podUpdate(prev, cur interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
c.preparePodEventForDispatch(curPod, prevPod, spec.EventUpdate)
|
||||
}
|
||||
|
||||
func (c *Controller) podDelete(obj interface{}) {
|
||||
|
||||
if pod, ok := obj.(*v1.Pod); ok {
|
||||
c.preparePodEventForDispatch(pod, nil, spec.EventDelete)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) preparePodEventForDispatch(curPod, prevPod *v1.Pod, event spec.EventType) {
|
||||
podEvent := spec.PodEvent{
|
||||
PodName: util.NameFromMeta(curPod.ObjectMeta),
|
||||
PrevPod: prevPod,
|
||||
CurPod: curPod,
|
||||
EventType: spec.EventUpdate,
|
||||
PrevPod: prevPod,
|
||||
EventType: event,
|
||||
ResourceVersion: curPod.ResourceVersion,
|
||||
}
|
||||
|
||||
c.dispatchPodEvent(c.podClusterName(curPod), podEvent)
|
||||
}
|
||||
|
||||
func (c *Controller) podDelete(obj interface{}) {
|
||||
pod, ok := obj.(*v1.Pod)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
podEvent := spec.PodEvent{
|
||||
PodName: util.NameFromMeta(pod.ObjectMeta),
|
||||
CurPod: pod,
|
||||
EventType: spec.EventDelete,
|
||||
ResourceVersion: pod.ResourceVersion,
|
||||
}
|
||||
|
||||
c.dispatchPodEvent(c.podClusterName(pod), podEvent)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@@ -130,7 +131,9 @@ type crdDecoder struct {
|
||||
}
|
||||
|
||||
func (d *crdDecoder) Close() {
|
||||
d.close()
|
||||
if err := d.close(); err != nil {
|
||||
fmt.Printf("error when closing CRDDecorer: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *crdDecoder) Decode() (action watch.EventType, object runtime.Object, err error) {
|
||||
@@ -526,7 +529,6 @@ func (c *Controller) submitRBACCredentials(event spec.ClusterEvent) error {
|
||||
if err := c.createRoleBindings(namespace); err != nil {
|
||||
return fmt.Errorf("could not create role binding %v : %v", c.PodServiceAccountRoleBinding.Name, err)
|
||||
}
|
||||
|
||||
c.namespacesWithDefinedRBAC.Store(namespace, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user