Skip to content
Permalink
Browse files

Merge pull request #1187 from Adirio/import-order

Imports ordering
  • Loading branch information
k8s-ci-robot committed Jan 7, 2020
2 parents 71e8a0b + 4e7ec4b commit 86dc861305a44b7830c27358b44efe6712cb1a8d
Showing with 110 additions and 107 deletions.
  1. +3 −1 cmd/go_version_test.go
  2. +1 −0 cmd/vendor_update.go
  3. +1 −1 docs/book/src/cronjob-tutorial/testdata/emptycontroller.go
  4. +1 −1 docs/book/src/cronjob-tutorial/testdata/emptymain.go
  5. +0 −2 docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go
  6. +1 −0 docs/book/src/cronjob-tutorial/testdata/project/main.go
  7. +4 −4 docs/book/src/migration/testdata/gopath/project-v1/cmd/manager/main.go
  8. +2 −3 docs/book/src/migration/testdata/gopath/project-v1/pkg/controller/cronjob/cronjob_controller.go
  9. +2 −2 .../src/migration/testdata/gopath/project-v1/pkg/controller/cronjob/cronjob_controller_suite_test.go
  10. +2 −2 ...n/testdata/gopath/project-v1/pkg/webhook/default_server/cronjob/mutating/create_update_webhook.go
  11. +2 −2 ...ta/gopath/project-v1/pkg/webhook/default_server/cronjob/mutating/cronjob_create_update_handler.go
  12. +2 −2 ...ration/testdata/gopath/project-v1/pkg/webhook/default_server/cronjob/validating/create_webhook.go
  13. +2 −3 ...estdata/gopath/project-v1/pkg/webhook/default_server/cronjob/validating/cronjob_create_handler.go
  14. +2 −2 ...estdata/gopath/project-v1/pkg/webhook/default_server/cronjob/validating/cronjob_update_handler.go
  15. +2 −2 ...ration/testdata/gopath/project-v1/pkg/webhook/default_server/cronjob/validating/update_webhook.go
  16. +0 −2 docs/book/src/multiversion-tutorial/testdata/project/api/v1/cronjob_webhook.go
  17. +1 −0 docs/book/src/multiversion-tutorial/testdata/project/main.go
  18. +1 −0 pkg/scaffold/project/project_test.go
  19. +13 −1 pkg/scaffold/scaffold.go
  20. +2 −4 pkg/scaffold/v1/controller/controller.go
  21. +0 −1 pkg/scaffold/v1/controller/controllersuitetest.go
  22. +0 −1 pkg/scaffold/v1/controller/controllertest.go
  23. +0 −1 pkg/scaffold/v1/crd/typestest.go
  24. +0 −1 pkg/scaffold/v1/crd/version_suitetest.go
  25. +0 −1 pkg/scaffold/v1/manager/cmd.go
  26. +1 −0 pkg/scaffold/v1/manager/manager_test.go
  27. +0 −1 pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go
  28. +1 −1 pkg/scaffold/v1/webhook/admissionbuilder.go
  29. +1 −3 pkg/scaffold/v1/webhook/admissionhandler.go
  30. +0 −1 pkg/scaffold/v1/webhook/server.go
  31. +1 −0 pkg/scaffold/v1/webhook/webhook_test.go
  32. +0 −2 pkg/scaffold/v2/controller.go
  33. +0 −3 pkg/scaffold/v2/controller_suitetest.go
  34. +0 −2 pkg/scaffold/v2/main.go
  35. +1 −0 pkg/scaffold/v2/prometheus/kustomize.go
  36. +3 −1 pkg/scaffold/v2/webhook/webhook.go
  37. +1 −0 plugins/addon/helpers.go
  38. +2 −1 test/e2e/v1/e2e_suite.go
  39. +2 −2 test/e2e/v2/e2e_suite.go
  40. +4 −4 testdata/gopath/src/project/cmd/manager/main.go
  41. +2 −2 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller.go
  42. +2 −2 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_suite_test.go
  43. +2 −2 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_test.go
  44. +2 −2 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller.go
  45. +2 −2 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_suite_test.go
  46. +2 −2 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_test.go
  47. +2 −2 testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go
  48. +2 −2 ...ta/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_suite_test.go
  49. +2 −2 testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_test.go
  50. +2 −2 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller.go
  51. +2 −2 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_suite_test.go
  52. +2 −2 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_test.go
  53. +2 −2 testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_suite_test.go
  54. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/create_update_webhook.go
  55. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/delete_webhook.go
  56. +2 −2 ...path/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_create_update_handler.go
  57. +2 −2 ...data/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_delete_handler.go
  58. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go
  59. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/update_webhook.go
  60. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/create_webhook.go
  61. +2 −2 testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/kraken_create_handler.go
  62. +1 −2 testdata/project-v2/controllers/namespace_controller.go
  63. +3 −2 testdata/project-v2/controllers/suite_test.go
  64. +3 −1 testdata/project-v2/main.go
@@ -16,7 +16,9 @@ limitations under the License.

package main

import "testing"
import (
"testing"
)

func TestCheckGoVersion(t *testing.T) {

@@ -20,6 +20,7 @@ import (
"log"

"github.com/spf13/cobra"

"sigs.k8s.io/kubebuilder/pkg/model"
"sigs.k8s.io/kubebuilder/pkg/scaffold"
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
@@ -23,9 +23,9 @@ package controllers

import (
"context"
"k8s.io/apimachinery/pkg/runtime"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

@@ -29,11 +29,11 @@ import (
"flag"
"fmt"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"

"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)
@@ -18,13 +18,11 @@ package v1

import (
"github.com/robfig/cron"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
validationutils "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"

ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -25,6 +25,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

batchv1 "tutorial.kubebuilder.io/project/api/v1"
"tutorial.kubebuilder.io/project/controllers"
// +kubebuilder:scaffold:imports
@@ -20,15 +20,15 @@ import (
"flag"
"os"

"project/pkg/apis"
"project/pkg/controller"
"project/pkg/webhook"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"project/pkg/apis"
"project/pkg/controller"
"project/pkg/webhook"
)

func main() {
@@ -23,9 +23,6 @@ import (
"time"

"github.com/robfig/cron"

batchv1 "project/pkg/apis/batch/v1"

kbatch "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -37,6 +34,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"

batchv1 "project/pkg/apis/batch/v1"
)

var log = logf.Log.WithName("controller")
@@ -23,14 +23,14 @@ import (
"sync"
"testing"

"project/pkg/apis"

"github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"project/pkg/apis"
)

var cfg *rest.Config
@@ -17,10 +17,10 @@ limitations under the License.
package mutating

import (
batchv1 "project/pkg/apis/batch/v1"

admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -20,11 +20,11 @@ import (
"context"
"net/http"

batchv1 "project/pkg/apis/batch/v1"

"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/types"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -17,10 +17,10 @@ limitations under the License.
package validating

import (
batchv1 "project/pkg/apis/batch/v1"

admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -21,16 +21,15 @@ import (
"net/http"

"github.com/robfig/cron"

batchv1 "project/pkg/apis/batch/v1"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
validationutils "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/types"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -20,11 +20,11 @@ import (
"context"
"net/http"

batchv1 "project/pkg/apis/batch/v1"

"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/types"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -17,10 +17,10 @@ limitations under the License.
package validating

import (
batchv1 "project/pkg/apis/batch/v1"

admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"

batchv1 "project/pkg/apis/batch/v1"
)

func init() {
@@ -18,13 +18,11 @@ package v1

import (
"github.com/robfig/cron"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
validationutils "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"

ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -26,6 +26,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

batchv1 "tutorial.kubebuilder.io/project/api/v1"
batchv2 "tutorial.kubebuilder.io/project/api/v2"
"tutorial.kubebuilder.io/project/controllers"
@@ -27,6 +27,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"sigs.k8s.io/kubebuilder/pkg/model"
"sigs.k8s.io/kubebuilder/pkg/scaffold"
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
@@ -28,12 +28,20 @@ import (
"text/template"

"golang.org/x/tools/imports"

"sigs.k8s.io/kubebuilder/pkg/model"
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
"sigs.k8s.io/kubebuilder/pkg/scaffold/project"
"sigs.k8s.io/yaml"
)

var options = imports.Options{
Comments: true,
TabIndent: true,
TabWidth: 8,
FormatOnly: true,
}

// Scaffold writes Templates to scaffold new files
type Scaffold struct {
// BoilerplatePath is the path to the boilerplate file
@@ -181,6 +189,10 @@ func (s *Scaffold) Execute(u *model.Universe, options input.Options, files ...in
if err := s.defaultOptions(&options); err != nil {
return err
}

// Set the repo as the local prefix so that it knows how to group imports
imports.LocalPrefix = s.Project.Repo

for _, f := range files {
m, err := s.buildFileModel(f)
if err != nil {
@@ -289,7 +301,7 @@ func (s *Scaffold) doTemplate(i input.Input, e input.File) ([]byte, error) {

// gofmt the imports
if filepath.Ext(i.Path) == ".go" {
b, err = imports.Process(i.Path, b, nil)
b, err = imports.Process(i.Path, b, &options)
if err != nil {
fmt.Printf("%s\n", out.Bytes())
return nil, err
@@ -24,6 +24,7 @@ import (
"strings"

"github.com/gobuffalo/flect"

"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
"sigs.k8s.io/kubebuilder/pkg/scaffold/resource"
)
@@ -103,14 +104,11 @@ package {{ lower .Resource.Kind }}
import (
{{ if .Resource.CreateExampleReconcileBody }} "context"
"log"
"reflect"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -126,9 +124,9 @@ import (
var log = logf.Log.WithName("{{ lower .Resource.Kind }}-controller")
{{ else }} "context"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -52,7 +52,6 @@ import (
"path/filepath"
"sync"
"testing"
"github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
@@ -73,7 +73,6 @@ package {{ lower .Resource.Kind }}
import (
"testing"
"time"
"github.com/onsi/gomega"
"golang.org/x/net/context"
{{ if .Resource.CreateExampleReconcileBody -}}
@@ -57,7 +57,6 @@ package {{ .Resource.Version }}
import (
"testing"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -58,7 +58,6 @@ import (
"os"
"path/filepath"
"testing"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -45,7 +45,6 @@ package main
import (
"flag"
"os"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -22,6 +22,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"sigs.k8s.io/kubebuilder/pkg/model"
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
"sigs.k8s.io/kubebuilder/pkg/scaffold/scaffoldtest"
@@ -55,7 +55,6 @@ package {{ .Server }}server
import (
"fmt"
"{{ .Repo }}/pkg/webhook/{{ .Server }}_server/{{ lower .Resource.Kind }}/{{ .Type }}"
)
@@ -77,9 +77,9 @@ const admissionWebhookBuilderTemplate = `{{ .Boilerplate }}
package {{ .Type }}
import (
{{ .Resource.Group}}{{ .Resource.Version }} "{{ .ResourcePackage }}/{{ .Resource.Group}}/{{ .Resource.Version }}"
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"
{{ .Resource.Group}}{{ .Resource.Version }} "{{ .ResourcePackage }}/{{ .Resource.Group}}/{{ .Resource.Version }}"
)
func init() {
@@ -78,12 +78,10 @@ package {{ .Type }}
import (
"context"
"net/http"
{{ .Resource.Group}}{{ .Resource.Version }} "{{ .ResourcePackage }}/{{ .Resource.Group}}/{{ .Resource.Version }}"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/types"
{{ .Resource.Group}}{{ .Resource.Version }} "{{ .ResourcePackage }}/{{ .Resource.Group}}/{{ .Resource.Version }}"
)
func init() {

0 comments on commit 86dc861

Please sign in to comment.
You can’t perform that action at this time.