kumahq / kuma

🐻 The multi-zone service mesh for containers, Kubernetes and VMs. Built with Envoy. CNCF Sandbox Project.
https://kuma.io/install
Apache License 2.0
3.55k stars 326 forks source link

importas rule for all `k8s.io/api` imports #2811

Open lahabana opened 2 years ago

lahabana commented 2 years ago

Summary

We currently don't good import rules for this. It would simplify readability if these were standardised.

jpeach commented 2 years ago

IMHO, not all imports, just common or conventional ones. I don't think that we should go down the path of always requiring import aliases everywhere :)

lahabana commented 2 years ago

Yes I was thing metav1/corev1/appv1 something like this.

github-actions[bot] commented 2 years ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

github-actions[bot] commented 2 years ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

github-actions[bot] commented 2 years ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

github-actions[bot] commented 2 years ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

github-actions[bot] commented 2 years ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

github-actions[bot] commented 1 year ago

This issue was inactive for 30 days it will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant please comment on it promptly or attend the next triage meeting.

afzal442 commented 1 year ago

Any clue here how to approach here?

lahabana commented 1 year ago

Just a matter at adding some entries there: https://github.com/kumahq/kuma/blob/master/.golangci.yml#L25-L42

Looking at it we're not talking about a LOT of them:

➜  kuma git:(fix5005) git grep k8s.io/api  | grep '\.go'  | sed -E 's/[^"]+"(.+)"/\1/g' | sort | uniq -c | sort
   1 k8s.io/api/batch/v1
   1 k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1
   1 k8s.io/apimachinery/pkg/fields
   1 k8s.io/apimachinery/pkg/runtime/serializer/json
   1 k8s.io/apimachinery/pkg/selection
   1 k8s.io/apimachinery/pkg/util/yaml
   1 k8s.io/apimachinery/pkg/version
   2 k8s.io/apimachinery/pkg/watch
   3 k8s.io/api/authentication/v1
   3 k8s.io/apimachinery/pkg/apis/meta/v1/unstructured
   4 k8s.io/api/apps/v1
   4 k8s.io/apimachinery/pkg/api/resource
   4 k8s.io/apimachinery/pkg/labels
   7 k8s.io/apimachinery/pkg/runtime/serializer
   9 k8s.io/apimachinery/pkg/util/intstr
  11 k8s.io/apimachinery/pkg/api/meta
  12 k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
  16 k8s.io/api/admission/v1
  16 k8s.io/apimachinery/pkg/runtime/schema
  30 k8s.io/apimachinery/pkg/api/errors
  38 k8s.io/apimachinery/pkg/types
  42 k8s.io/apimachinery/pkg/runtime
  59 k8s.io/api/core/v1
  81 k8s.io/apimachinery/pkg/apis/meta/v1

But for example if you take the most commonly used it's imported as metav1/kube_meta/v1 adding these in the linter would force always using the same alias:

➜  kuma git:(fix5005) git grep k8s.io/api  | grep '\.go'  | grep k8s.io/apimachinery/pkg/apis/meta/v1
app/cni/pkg/cni/kubernetes.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
app/kuma-cp/cmd/run_test.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
app/kumactl/cmd/install/install_crds.go:    v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/bootstrap/k8s/cache/informer_cache.go:  "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
pkg/plugins/bootstrap/k8s/cache/internal/deleg_map.go:  "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
pkg/plugins/bootstrap/k8s/cache/internal/informers_map.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/bootstrap/k8s/plugin.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/common/k8s/composite_validator_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/config/k8s/store.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/config/k8s/store_test.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/policies/donothingpolicy/k8s/v1alpha1/zz_generated.types.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/policies/meshaccesslog/k8s/v1alpha1/zz_generated.types.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/policies/meshtrafficpermission/k8s/v1alpha1/zz_generated.types.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/events/listener.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/k8s_suite_test.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/circuitbreaker_types_test.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/container_patch.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/dataplane_insight_types_test.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/dataplane_types_test.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/externalservice_types_test.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/healthcheck_types_test.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/mesh_gateway_config.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/mesh_gateway_instance.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/mesh_types_test.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/proxytemplate_types_test.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/retry_types_test.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/trafficroute_types_test.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/zone_insight_types_test.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/zz_generated.deepcopy.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/zz_generated.mesh.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/api/v1alpha1/zz_generated.system.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/pkg/model/resources.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/test/api/sample/v1alpha1/sample_types.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/native/test/api/sample/v1alpha1/sample_types_helpers.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/store.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/resources/k8s/store_test.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/apis/k8s.cni.cncf.io/v1/types.go:import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/configmap_controller_test.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gateway_converter.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gateway_instance_controller.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/attachment/attachment.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/attachment/attachment_test.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/common/reconcile.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/gateway_class_controller.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/gateway_controller.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/gateway_conversion.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/gateway_conversion_test.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/gateway_status.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/http_route_controller.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/http_route_conversion.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/gatewayapi/policy/policy_test.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/namespace_controller.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/namespace_controller_test.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/pod_controller.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/pod_controller_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/pod_converter_test.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/pod_status_controller_test.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/service_controller_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/controllers/util/controlled.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/util/util.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/util/util_test.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/defaulter_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/gatewayapi_multizone_validator_test.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/injector/injector_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/owner_reference_mutator_test.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/secret_validator_test.go:  kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/validation.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/validation_test.go:    kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/runtime/k8s/webhooks/webhook_suite_test.go: kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/secrets/k8s/store.go:   kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/plugins/secrets/k8s/store_test.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkg/transparentproxy/kubernetes/kubernetes_test.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/e2e_env/kubernetes/gateway/utils.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/deployments/externalservice/kubernetes.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/deployments/kic/kubernetes.go:   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/deployments/observability/kubernetes.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/deployments/testserver/kubernetes.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/k8s.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/k8s_cluster.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/k8s_controlplane.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
test/framework/k8s_controlplane.go: "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
test/framework/setup.go:    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
tools/policy-gen/protoc-gen-kumapolicy/crd.go:  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
tools/resource-gen/main.go: metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
github-actions[bot] commented 1 year ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 1 year ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 1 year ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 9 months ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 6 months ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 3 months ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.

github-actions[bot] commented 4 days ago

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed. If you think this issue is still relevant, please comment on it or attend the next triage meeting.