update linting
This commit is contained in:
		
							parent
							
								
									f0e29060b1
								
							
						
					
					
						commit
						7217046ef5
					
				
							
								
								
									
										14
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										14
									
								
								Makefile
								
								
								
								
							|  | @ -20,7 +20,7 @@ GITSTATUS = $(shell git status --porcelain || echo "no changes") | |||
| SOURCES = cmd/main.go | ||||
| VERSION ?= $(shell git describe --tags --always --dirty) | ||||
| DIRS := cmd pkg | ||||
| PKG := `go list ./... | grep -v /vendor/` | ||||
| PKG := `go list ./... | grep --invert-match /vendor/ | grep --invert-match /kubectl-pg` | ||||
| 
 | ||||
| ifeq ($(DEBUG),1) | ||||
| 	DOCKERFILE = DebugDockerfile | ||||
|  | @ -46,7 +46,7 @@ default: local | |||
| clean: | ||||
| 	rm -rf build scm-source.json | ||||
| 
 | ||||
| local: ${SOURCES} | ||||
| local: test ${SOURCES} | ||||
| 	hack/verify-codegen.sh | ||||
| 	CGO_ENABLED=${CGO_ENABLED} go build -o build/${BINARY} $(LOCAL_BUILD_FLAGS) -ldflags "$(LDFLAGS)" $^ | ||||
| 
 | ||||
|  | @ -60,7 +60,7 @@ docker-context: scm-source.json linux | |||
| 	mkdir -p docker/build/ | ||||
| 	cp build/linux/${BINARY} scm-source.json docker/build/ | ||||
| 
 | ||||
| docker: ${DOCKERDIR}/${DOCKERFILE} docker-context | ||||
| docker: test ${DOCKERDIR}/${DOCKERFILE} docker-context | ||||
| 	echo `(env)` | ||||
| 	echo "Tag ${TAG}" | ||||
| 	echo "Version ${VERSION}" | ||||
|  | @ -78,22 +78,24 @@ scm-source.json: .git | |||
| 	echo '{\n "url": "git:$(GITURL)",\n "revision": "$(GITHEAD)",\n "author": "$(USER)",\n "status": "$(GITSTATUS)"\n}' > scm-source.json | ||||
| 
 | ||||
| tools: | ||||
| 	@go get -u github.com/gordonklaus/ineffassign | ||||
| 	@go get -u honnef.co/go/tools/cmd/staticcheck | ||||
| 	@go get -u github.com/Masterminds/glide | ||||
| 
 | ||||
| fmt: | ||||
| 	@gofmt -l -w -s $(DIRS) | ||||
| 
 | ||||
| vet: | ||||
| vet: fmt | ||||
| 	@go vet $(PKG) | ||||
| 	@ineffassign kubectl-pg pkg | ||||
| 	@staticcheck $(PKG) | ||||
| 
 | ||||
| deps: | ||||
| 	@glide install --strip-vendor | ||||
| 
 | ||||
| test: | ||||
| test: vet | ||||
| 	hack/verify-codegen.sh | ||||
| 	@go test ./... | ||||
| 	@go test $(PKG) | ||||
| 
 | ||||
| e2e: docker # build operator image to be tested
 | ||||
| 	cd e2e; make tools test clean | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ $ $GOPATH/src/github.com/zalando/postgres-operator/kubectl-pg  go install | |||
| # This will place the kubectl-pg binary in your $GOPATH/bin | ||||
| ``` | ||||
| 
 | ||||
| ### Before using the kubectl pg plugin make sure to set KUBECONFIG env varibale | ||||
| ### Before using the kubectl pg plugin make sure to set KUBECONFIG env variable | ||||
| 
 | ||||
| Ideally KUBECONFIG is found in $HOME/.kube/config else specify the KUBECONFIG path here. | ||||
| 
 | ||||
|  | @ -117,7 +117,7 @@ Note: -p represents psql prompt | |||
| 
 | ||||
| ```kubectl pg logs -c CLUSTER``` #Fetches the logs of a random pod. Not master | ||||
| ```kubectl pg logs -c CLUSTER -m``` #Fetches the logs of master | ||||
| ```kubectl pg logs -c CLUSTER -r 2``` #Fecthes the logs of specified replica | ||||
| ```kubectl pg logs -c CLUSTER -r 2``` #Fetches the logs of specified replica | ||||
| 
 | ||||
| ## Development | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,11 +25,12 @@ package cmd | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 
 | ||||
| 	"github.com/spf13/cobra" | ||||
| 	PostgresqlLister "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	"log" | ||||
| ) | ||||
| 
 | ||||
| // addDbCmd represents the addDb command
 | ||||
|  | @ -69,7 +70,7 @@ func addDb(dbName string, dbOwner string, clusterName string) { | |||
| 
 | ||||
| 	var dbOwnerExists bool | ||||
| 	dbUsers := postgresql.Spec.Users | ||||
| 	for key, _ := range dbUsers { | ||||
| 	for key := range dbUsers { | ||||
| 		if key == dbOwner { | ||||
| 			dbOwnerExists = true | ||||
| 		} | ||||
|  |  | |||
|  | @ -24,12 +24,13 @@ package cmd | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"log" | ||||
| 
 | ||||
| 	"github.com/spf13/cobra" | ||||
| 	v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" | ||||
| 	PostgresqlLister "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1" | ||||
| 	"io/ioutil" | ||||
| 	"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme" | ||||
| 	"log" | ||||
| ) | ||||
| 
 | ||||
| // createCmd kubectl pg create.
 | ||||
|  | @ -50,6 +51,9 @@ kubectl pg create -f cluster-manifest.yaml | |||
| func create(fileName string) { | ||||
| 	config := getConfig() | ||||
| 	postgresConfig, err := PostgresqlLister.NewForConfig(config) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	ymlFile, err := ioutil.ReadFile(fileName) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
|  |  | |||
|  | @ -25,20 +25,21 @@ package cmd | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/spf13/cobra" | ||||
| 	PostgresqlLister "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1" | ||||
| 	"k8s.io/apimachinery/pkg/api/resource" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	"log" | ||||
| 	"strconv" | ||||
| ) | ||||
| 
 | ||||
| // extVolumeCmd represents the extVolume command
 | ||||
| var extVolumeCmd = &cobra.Command{ | ||||
| 	Use:   "ext-volume", | ||||
| 	Short: "Increases the volume size of a given Postgres cluster", | ||||
| 	Long:  `Extends the volume of the postgres cluster. But volume cannot be shrinked.`, | ||||
| 	Long:  `Extends the volume of the postgres cluster. But volume cannot be shrunk.`, | ||||
| 	Run: func(cmd *cobra.Command, args []string) { | ||||
| 		clusterName, _ := cmd.Flags().GetString("cluster") | ||||
| 		if len(args) > 0 { | ||||
|  | @ -98,7 +99,7 @@ func extVolume(increasedVolumeSize string, clusterName string) { | |||
| 	} else if newSize.Value() == oldSize.Value() { | ||||
| 		fmt.Println("volume already has the desired size.") | ||||
| 	} else { | ||||
| 		fmt.Printf("volume %s size cannot be shrinked.\n", postgresql.Spec.Volume.Size) | ||||
| 		fmt.Printf("volume %s size cannot be shrunk.\n", postgresql.Spec.Volume.Size) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,6 +25,9 @@ package cmd | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/spf13/cobra" | ||||
| 	PostgresqlLister "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1" | ||||
| 	v1 "k8s.io/api/apps/v1" | ||||
|  | @ -32,8 +35,6 @@ import ( | |||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	"k8s.io/client-go/kubernetes" | ||||
| 	"k8s.io/client-go/rest" | ||||
| 	"log" | ||||
| 	"strconv" | ||||
| ) | ||||
| 
 | ||||
| // scaleCmd represents the scale command
 | ||||
|  | @ -44,6 +45,9 @@ var scaleCmd = &cobra.Command{ | |||
| Scaling to 0 leads to down time.`, | ||||
| 	Run: func(cmd *cobra.Command, args []string) { | ||||
| 		clusterName, err := cmd.Flags().GetString("cluster") | ||||
| 		if err != nil { | ||||
| 			log.Fatal(err) | ||||
| 		} | ||||
| 		namespace, err := cmd.Flags().GetString("namespace") | ||||
| 		if err != nil { | ||||
| 			log.Fatal(err) | ||||
|  |  | |||
|  | @ -24,13 +24,14 @@ package cmd | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"log" | ||||
| 
 | ||||
| 	"github.com/spf13/cobra" | ||||
| 	v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" | ||||
| 	PostgresqlLister "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/typed/acid.zalan.do/v1" | ||||
| 	"io/ioutil" | ||||
| 	"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"log" | ||||
| ) | ||||
| 
 | ||||
| // updateCmd represents kubectl pg update
 | ||||
|  | @ -55,6 +56,9 @@ kubectl pg update -f cluster-manifest.yaml | |||
| func updatePgResources(fileName string) { | ||||
| 	config := getConfig() | ||||
| 	postgresConfig, err := PostgresqlLister.NewForConfig(config) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	ymlFile, err := ioutil.ReadFile(fileName) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
|  |  | |||
|  | @ -21,48 +21,48 @@ const ( | |||
| 
 | ||||
| // PostgresCRDResourceColumns definition of AdditionalPrinterColumns for postgresql CRD
 | ||||
| var PostgresCRDResourceColumns = []apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Team", | ||||
| 		Type:        "string", | ||||
| 		Description: "Team responsible for Postgres cluster", | ||||
| 		JSONPath:    ".spec.teamId", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Version", | ||||
| 		Type:        "string", | ||||
| 		Description: "PostgreSQL version", | ||||
| 		JSONPath:    ".spec.postgresql.version", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Pods", | ||||
| 		Type:        "integer", | ||||
| 		Description: "Number of Pods per Postgres cluster", | ||||
| 		JSONPath:    ".spec.numberOfInstances", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Volume", | ||||
| 		Type:        "string", | ||||
| 		Description: "Size of the bound volume", | ||||
| 		JSONPath:    ".spec.volume.size", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "CPU-Request", | ||||
| 		Type:        "string", | ||||
| 		Description: "Requested CPU for Postgres containers", | ||||
| 		JSONPath:    ".spec.resources.requests.cpu", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Memory-Request", | ||||
| 		Type:        "string", | ||||
| 		Description: "Requested memory for Postgres containers", | ||||
| 		JSONPath:    ".spec.resources.requests.memory", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:     "Age", | ||||
| 		Type:     "date", | ||||
| 		JSONPath: ".metadata.creationTimestamp", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Status", | ||||
| 		Type:        "string", | ||||
| 		Description: "Current sync status of postgresql resource", | ||||
|  | @ -72,31 +72,31 @@ var PostgresCRDResourceColumns = []apiextv1beta1.CustomResourceColumnDefinition{ | |||
| 
 | ||||
| // OperatorConfigCRDResourceColumns definition of AdditionalPrinterColumns for OperatorConfiguration CRD
 | ||||
| var OperatorConfigCRDResourceColumns = []apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Image", | ||||
| 		Type:        "string", | ||||
| 		Description: "Spilo image to be used for Pods", | ||||
| 		JSONPath:    ".configuration.docker_image", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Cluster-Label", | ||||
| 		Type:        "string", | ||||
| 		Description: "Label for K8s resources created by operator", | ||||
| 		JSONPath:    ".configuration.kubernetes.cluster_name_label", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Service-Account", | ||||
| 		Type:        "string", | ||||
| 		Description: "Name of service account to be used", | ||||
| 		JSONPath:    ".configuration.kubernetes.pod_service_account_name", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:        "Min-Instances", | ||||
| 		Type:        "integer", | ||||
| 		Description: "Minimum number of instances per Postgres cluster", | ||||
| 		JSONPath:    ".configuration.min_instances", | ||||
| 	}, | ||||
| 	apiextv1beta1.CustomResourceColumnDefinition{ | ||||
| 	{ | ||||
| 		Name:     "Age", | ||||
| 		Type:     "date", | ||||
| 		JSONPath: ".metadata.creationTimestamp", | ||||
|  |  | |||
|  | @ -81,7 +81,7 @@ func (ps *PostgresStatus) UnmarshalJSON(data []byte) error { | |||
| 	if err != nil { | ||||
| 		metaErr := json.Unmarshal(data, &status) | ||||
| 		if metaErr != nil { | ||||
| 			return fmt.Errorf("Could not parse status: %v; err %v", string(data), metaErr) | ||||
| 			return fmt.Errorf("could not parse status: %v; err %v", string(data), metaErr) | ||||
| 		} | ||||
| 		tmp.PostgresClusterStatus = status | ||||
| 	} | ||||
|  |  | |||
|  | @ -45,7 +45,7 @@ type KubernetesMetaConfiguration struct { | |||
| 	PodServiceAccountDefinition            string                `json:"pod_service_account_definition,omitempty"` | ||||
| 	PodServiceAccountRoleBindingDefinition string                `json:"pod_service_account_role_binding_definition,omitempty"` | ||||
| 	PodTerminateGracePeriod                Duration              `json:"pod_terminate_grace_period,omitempty"` | ||||
| 	SpiloPrivileged                        bool                  `json:"spilo_privileged,omitemty"` | ||||
| 	SpiloPrivileged                        bool                  `json:"spilo_privileged,omitempty"` | ||||
| 	SpiloFSGroup                           *int64                `json:"spilo_fsgroup,omitempty"` | ||||
| 	WatchedNamespace                       string                `json:"watched_namespace,omitempty"` | ||||
| 	PDBNameFormat                          config.StringTemplate `json:"pdb_name_format,omitempty"` | ||||
|  |  | |||
|  | @ -842,7 +842,7 @@ func (c *Cluster) initHumanUsers() error { | |||
| 	for _, postgresSuperuserTeam := range c.OpConfig.PostgresSuperuserTeams { | ||||
| 		err := c.initTeamMembers(postgresSuperuserTeam, true) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("Cannot create a team %q of Postgres superusers: %v", postgresSuperuserTeam, err) | ||||
| 			return fmt.Errorf("cannot create a team %q of Postgres superusers: %v", postgresSuperuserTeam, err) | ||||
| 		} | ||||
| 		if postgresSuperuserTeam == c.Spec.TeamID { | ||||
| 			clusterIsOwnedBySuperuserTeam = true | ||||
|  | @ -856,7 +856,7 @@ func (c *Cluster) initHumanUsers() error { | |||
| 
 | ||||
| 	err := c.initTeamMembers(c.Spec.TeamID, false) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("Cannot create a team %q of admins owning the PG cluster: %v", c.Spec.TeamID, err) | ||||
| 		return fmt.Errorf("cannot create a team %q of admins owning the PG cluster: %v", c.Spec.TeamID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
|  |  | |||
|  | @ -174,6 +174,7 @@ PatroniInitDBParams: | |||
| 	for _, k := range initdbOptionNames { | ||||
| 		v := patroni.InitDB[k] | ||||
| 		for i, defaultParam := range config.Bootstrap.Initdb { | ||||
| 			//lint:ignore S1034 looks like false positive: defaultParam.(type) cannot be used outside of type switch
 | ||||
| 			switch defaultParam.(type) { | ||||
| 			case map[string]string: | ||||
| 				{ | ||||
|  | @ -1308,11 +1309,11 @@ func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) | |||
| 			c.logger.Info(msg, description.S3WalPath) | ||||
| 
 | ||||
| 			envs := []v1.EnvVar{ | ||||
| 				v1.EnvVar{ | ||||
| 				{ | ||||
| 					Name:  "CLONE_WAL_S3_BUCKET", | ||||
| 					Value: c.OpConfig.WALES3Bucket, | ||||
| 				}, | ||||
| 				v1.EnvVar{ | ||||
| 				{ | ||||
| 					Name:  "CLONE_WAL_BUCKET_SCOPE_SUFFIX", | ||||
| 					Value: getBucketScopeSuffix(description.UID), | ||||
| 				}, | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ import ( | |||
| 	"sync" | ||||
| 
 | ||||
| 	"github.com/sirupsen/logrus" | ||||
| 	"k8s.io/api/core/v1" | ||||
| 	v1 "k8s.io/api/core/v1" | ||||
| 	rbacv1beta1 "k8s.io/api/rbac/v1beta1" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
|  | @ -176,7 +176,7 @@ func (c *Controller) initPodServiceAccount() { | |||
| 
 | ||||
| 	switch { | ||||
| 	case err != nil: | ||||
| 		panic(fmt.Errorf("Unable to parse pod service account definition from the operator config map: %v", err)) | ||||
| 		panic(fmt.Errorf("unable to parse pod service account definition from the operator config map: %v", err)) | ||||
| 	case groupVersionKind.Kind != "ServiceAccount": | ||||
| 		panic(fmt.Errorf("pod service account definition in the operator config map defines another type of resource: %v", groupVersionKind.Kind)) | ||||
| 	default: | ||||
|  | @ -224,7 +224,7 @@ func (c *Controller) initRoleBinding() { | |||
| 
 | ||||
| 	switch { | ||||
| 	case err != nil: | ||||
| 		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)) | ||||
| 		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 definition in the operator config map defines another type of resource: %v", groupVersionKind.Kind)) | ||||
| 	default: | ||||
|  |  | |||
|  | @ -133,6 +133,7 @@ var requestsURLtc = []struct { | |||
| }{ | ||||
| 	{ | ||||
| 		"coffee://localhost/", | ||||
| 		//lint:ignore ST1005 formatting matches the value returned by Teams API
 | ||||
| 		fmt.Errorf(`Get coffee://localhost/teams/acid: unsupported protocol scheme "coffee"`), | ||||
| 	}, | ||||
| 	{ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue