Enforce import ordering and aliases (#216)

This change ensures import ordering and aliases is standardized.
Something that is extra important when working with Kuberentes apis that
have "standard" import aliases.

Signed-off-by: Philip Laine <philip.laine@gmail.com>
This commit is contained in:
Philip Laine
2026-04-30 13:39:11 +02:00
committed by GitHub
parent cae1ab796b
commit 74012deb27
35 changed files with 584 additions and 512 deletions
+10 -10
View File
@@ -11,7 +11,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
)
// nolint:unused
@@ -20,7 +20,7 @@ var nbgrouplog = logf.Log.WithName("nbgroup-resource")
// SetupNBGroupWebhookWithManager registers the webhook for NBGroup in the manager.
func SetupNBGroupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr, &netbirdiov1.NBGroup{}).
return ctrl.NewWebhookManagedBy(mgr, &nbv1.NBGroup{}).
WithValidator(&NBGroupCustomValidator{client: mgr.GetClient()}).
Complete()
}
@@ -31,25 +31,25 @@ type NBGroupCustomValidator struct {
client client.Client
}
var _ admission.Validator[*netbirdiov1.NBGroup] = &NBGroupCustomValidator{}
var _ admission.Validator[*nbv1.NBGroup] = &NBGroupCustomValidator{}
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type NBGroup.
func (v *NBGroupCustomValidator) ValidateCreate(ctx context.Context, group *netbirdiov1.NBGroup) (admission.Warnings, error) {
func (v *NBGroupCustomValidator) ValidateCreate(ctx context.Context, group *nbv1.NBGroup) (admission.Warnings, error) {
return nil, nil
}
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type NBGroup.
func (v *NBGroupCustomValidator) ValidateUpdate(ctx context.Context, old, new *netbirdiov1.NBGroup) (admission.Warnings, error) {
func (v *NBGroupCustomValidator) ValidateUpdate(ctx context.Context, old, new *nbv1.NBGroup) (admission.Warnings, error) {
return nil, nil
}
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type NBGroup.
func (v *NBGroupCustomValidator) ValidateDelete(ctx context.Context, nbgroup *netbirdiov1.NBGroup) (admission.Warnings, error) {
func (v *NBGroupCustomValidator) ValidateDelete(ctx context.Context, nbgroup *nbv1.NBGroup) (admission.Warnings, error) {
nbgrouplog.Info("Validation for NBGroup upon deletion", "name", nbgroup.GetName())
for _, o := range nbgroup.OwnerReferences {
if o.Kind == (&netbirdiov1.NBResource{}).Kind {
var nbResource netbirdiov1.NBResource
if o.Kind == (&nbv1.NBResource{}).Kind {
var nbResource nbv1.NBResource
err := v.client.Get(ctx, types.NamespacedName{Namespace: nbgroup.Namespace, Name: o.Name}, &nbResource)
if err != nil && !errors.IsNotFound(err) {
return nil, err
@@ -58,8 +58,8 @@ func (v *NBGroupCustomValidator) ValidateDelete(ctx context.Context, nbgroup *ne
return nil, fmt.Errorf("group attached to NBResource %s/%s", nbgroup.Namespace, o.Name)
}
}
if o.Kind == (&netbirdiov1.NBRoutingPeer{}).Kind {
var nbResource netbirdiov1.NBRoutingPeer
if o.Kind == (&nbv1.NBRoutingPeer{}).Kind {
var nbResource nbv1.NBRoutingPeer
err := v.client.Get(ctx, types.NamespacedName{Namespace: nbgroup.Namespace, Name: o.Name}, &nbResource)
if err != nil && !errors.IsNotFound(err) {
return nil, err
+28 -28
View File
@@ -4,22 +4,22 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
)
var _ = Describe("NBGroup Webhook", func() {
var (
obj *netbirdiov1.NBGroup
oldObj *netbirdiov1.NBGroup
obj *nbv1.NBGroup
oldObj *nbv1.NBGroup
validator NBGroupCustomValidator
)
BeforeEach(func() {
obj = &netbirdiov1.NBGroup{}
oldObj = &netbirdiov1.NBGroup{}
obj = &nbv1.NBGroup{}
oldObj = &nbv1.NBGroup{}
validator = NBGroupCustomValidator{
client: k8sClient,
}
@@ -40,8 +40,8 @@ var _ = Describe("NBGroup Webhook", func() {
})
When("There are no owners", func() {
It("should allow deletion", func() {
obj = &netbirdiov1.NBGroup{
ObjectMeta: v1.ObjectMeta{
obj = &nbv1.NBGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
OwnerReferences: nil,
@@ -52,13 +52,13 @@ var _ = Describe("NBGroup Webhook", func() {
})
When("There deleted owners", func() {
It("should allow deletion", func() {
obj = &netbirdiov1.NBGroup{
ObjectMeta: v1.ObjectMeta{
obj = &nbv1.NBGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
OwnerReferences: []v1.OwnerReference{
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: netbirdiov1.GroupVersion.Identifier(),
APIVersion: nbv1.GroupVersion.Identifier(),
Kind: "NBResource",
Name: "notexist",
UID: obj.UID,
@@ -71,12 +71,12 @@ var _ = Describe("NBGroup Webhook", func() {
})
When("NBResource owner exists", func() {
BeforeEach(func() {
nbResource := &netbirdiov1.NBResource{
ObjectMeta: v1.ObjectMeta{
nbResource := &nbv1.NBResource{
ObjectMeta: metav1.ObjectMeta{
Name: "isexist",
Namespace: "default",
},
Spec: netbirdiov1.NBResourceSpec{
Spec: nbv1.NBResourceSpec{
Name: "test1",
NetworkID: "test2",
Address: "test3",
@@ -86,13 +86,13 @@ var _ = Describe("NBGroup Webhook", func() {
Expect(k8sClient.Create(ctx, nbResource)).To(Succeed())
obj = &netbirdiov1.NBGroup{
ObjectMeta: v1.ObjectMeta{
obj = &nbv1.NBGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
OwnerReferences: []v1.OwnerReference{
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: netbirdiov1.GroupVersion.Identifier(),
APIVersion: nbv1.GroupVersion.Identifier(),
Kind: nbResource.Kind,
Name: nbResource.Name,
UID: nbResource.UID,
@@ -102,7 +102,7 @@ var _ = Describe("NBGroup Webhook", func() {
}
})
AfterEach(func() {
nbResource := &netbirdiov1.NBResource{}
nbResource := &nbv1.NBResource{}
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: "default", Name: "isexist"}, nbResource)
if !errors.IsNotFound(err) {
Expect(err).NotTo(HaveOccurred())
@@ -122,23 +122,23 @@ var _ = Describe("NBGroup Webhook", func() {
})
When("NBRoutingPeer owner exists", func() {
BeforeEach(func() {
nbrp := &netbirdiov1.NBRoutingPeer{
ObjectMeta: v1.ObjectMeta{
nbrp := &nbv1.NBRoutingPeer{
ObjectMeta: metav1.ObjectMeta{
Name: "isexist",
Namespace: "default",
},
Spec: netbirdiov1.NBRoutingPeerSpec{},
Spec: nbv1.NBRoutingPeerSpec{},
}
Expect(k8sClient.Create(ctx, nbrp)).To(Succeed())
obj = &netbirdiov1.NBGroup{
ObjectMeta: v1.ObjectMeta{
obj = &nbv1.NBGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
OwnerReferences: []v1.OwnerReference{
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: netbirdiov1.GroupVersion.Identifier(),
APIVersion: nbv1.GroupVersion.Identifier(),
Kind: nbrp.Kind,
Name: nbrp.Name,
UID: nbrp.UID,
@@ -148,7 +148,7 @@ var _ = Describe("NBGroup Webhook", func() {
}
})
AfterEach(func() {
nbrp := &netbirdiov1.NBRoutingPeer{}
nbrp := &nbv1.NBRoutingPeer{}
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: "default", Name: "isexist"}, nbrp)
if !errors.IsNotFound(err) {
Expect(err).NotTo(HaveOccurred())
+3 -3
View File
@@ -34,7 +34,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
"github.com/netbirdio/kubernetes-operator/internal/controller"
)
@@ -195,7 +195,7 @@ func (d *PodNetbirdInjector) legacyInjector(ctx context.Context, pod *corev1.Pod
podlog.Info("Defaulting for Pod", "name", pod.GetName())
// retrieve the NBSetupKey resource
var nbSetupKey netbirdiov1.NBSetupKey
var nbSetupKey nbv1.NBSetupKey
err := d.client.Get(ctx, types.NamespacedName{Namespace: pod.Namespace, Name: pod.Annotations[setupKeyAnnotation]}, &nbSetupKey)
if err != nil {
return err
@@ -204,7 +204,7 @@ func (d *PodNetbirdInjector) legacyInjector(ctx context.Context, pod *corev1.Pod
// ensure the NBSetupKey is ready.
ready := false
for _, c := range nbSetupKey.Status.Conditions {
if c.Type == netbirdiov1.NBSetupKeyReady {
if c.Type == nbv1.NBSetupKeyReady {
ready = c.Status == corev1.ConditionTrue
}
}
+8 -7
View File
@@ -19,12 +19,13 @@ package v1
import (
"context"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
)
var _ = Describe("Pod Webhook", func() {
@@ -82,12 +83,12 @@ var _ = Describe("Pod Webhook", func() {
When("NBSetupKey exists", Ordered, func() {
BeforeAll(func() {
sk := netbirdiov1.NBSetupKey{
sk := nbv1.NBSetupKey{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "test",
},
Spec: netbirdiov1.NBSetupKeySpec{
Spec: nbv1.NBSetupKeySpec{
SecretKeyRef: corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test",
@@ -107,10 +108,10 @@ var _ = Describe("Pod Webhook", func() {
err = k8sClient.Create(context.Background(), &sk)
Expect(err).NotTo(HaveOccurred())
sk.Status = netbirdiov1.NBSetupKeyStatus{
Conditions: []netbirdiov1.NBCondition{
sk.Status = nbv1.NBSetupKeyStatus{
Conditions: []nbv1.NBCondition{
{
Type: netbirdiov1.NBSetupKeyReady,
Type: nbv1.NBSetupKeyReady,
Status: corev1.ConditionTrue,
},
},
+4 -6
View File
@@ -28,9 +28,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
admissionv1 "k8s.io/api/admission/v1"
k8siov1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
@@ -41,9 +40,8 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
// +kubebuilder:scaffold:imports
)
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
@@ -70,13 +68,13 @@ var _ = BeforeSuite(func() {
var err error
scheme := apimachineryruntime.NewScheme()
err = k8siov1.AddToScheme(scheme)
err = corev1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
err = netbirdiov1.AddToScheme(scheme)
err = nbv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
err = nbv1alpha1.AddToScheme(scheme)