Skip to content

Commit

Permalink
chore: use consistent naming for imports
Browse files Browse the repository at this point in the history
Imports should be consistently named so future changes are more readable and easier to understand.

Signed-off-by: Gerard de Leeuw <[email protected]>
Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
lion7 authored and smira committed Mar 31, 2022
1 parent 8985a04 commit 15f6730
Show file tree
Hide file tree
Showing 25 changed files with 218 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
"github.com/talos-systems/sidero/app/caps-controller-manager/pkg/constants"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
)

var ErrNoServersInServerClass = errors.New("no servers available in serverclass")
Expand Down Expand Up @@ -265,7 +265,7 @@ func (r *MetalMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
Complete(r)
}

func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logger logr.Logger, classRef *corev1.ObjectReference, metalMachine *infrav1.MetalMachine) (*metalv1alpha1.Server, error) {
func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logger logr.Logger, classRef *corev1.ObjectReference, metalMachine *infrav1.MetalMachine) (*metalv1.Server, error) {
// First, check if there is already existing serverBinding for this metalmachine
var serverBindingList infrav1.ServerBindingList

Expand All @@ -276,7 +276,7 @@ func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logge
for _, serverBinding := range serverBindingList.Items {
if serverBinding.Spec.MetalMachineRef.Namespace == metalMachine.Namespace && serverBinding.Spec.MetalMachineRef.Name == metalMachine.Name {
// found existing serverBinding for this metalMachine
var server metalv1alpha1.Server
var server metalv1.Server

if err := r.Get(ctx, types.NamespacedName{Namespace: serverBinding.Namespace, Name: serverBinding.Name}, &server); err != nil {
return nil, err
Expand All @@ -302,7 +302,7 @@ func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logge
// NB: we added this loop to double check that an available server isn't "in use" because
// we saw raciness between server selection and it being removed from the ServersAvailable list.
for _, availServer := range serverClassResource.Status.ServersAvailable {
serverObj := &metalv1alpha1.Server{}
serverObj := &metalv1.Server{}

namespacedName := types.NamespacedName{
Namespace: "",
Expand Down Expand Up @@ -408,7 +408,7 @@ func (r *MetalMachineReconciler) patchProviderID(ctx context.Context, cluster *c
}

// createServerBinding updates a server to mark it as "in use" via ServerBinding resource.
func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, serverClass *metalv1alpha1.ServerClass, serverObj *metalv1alpha1.Server, metalMachine *infrav1.MetalMachine) error {
func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, serverClass *metalv1.ServerClass, serverObj *metalv1.Server, metalMachine *infrav1.MetalMachine) error {
serverRef, err := reference.GetReference(r.Scheme, serverObj)
if err != nil {
return err
Expand Down Expand Up @@ -445,8 +445,8 @@ func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, server
return err
}

func (r *MetalMachineReconciler) fetchServerClass(ctx context.Context, classRef *corev1.ObjectReference) (*metalv1alpha1.ServerClass, error) {
serverClassResource := &metalv1alpha1.ServerClass{}
func (r *MetalMachineReconciler) fetchServerClass(ctx context.Context, classRef *corev1.ObjectReference) (*metalv1.ServerClass, error) {
serverClassResource := &metalv1.ServerClass{}

namespacedName := types.NamespacedName{
Namespace: classRef.Namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
)

// ServerBindingReconciler reconciles a ServerBinding object.
Expand Down Expand Up @@ -75,7 +75,7 @@ func (r *ServerBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
}()

var server metalv1alpha1.Server
var server metalv1.Server

err = r.Get(ctx, req.NamespacedName, &server)
if err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *ServerBindingReconciler) reconcileTransition(ctx context.Context, logge
return ctrl.Result{}, nil
}

var server metalv1alpha1.Server
var server metalv1.Server

if err = r.Get(ctx, req.NamespacedName, &server); err != nil {
if apierrors.IsNotFound(err) {
Expand Down
10 changes: 5 additions & 5 deletions app/sidero-controller-manager/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/talos-systems/go-blockdevice/blockdevice"
"github.com/talos-systems/go-blockdevice/blockdevice/util/disk"
debug "github.com/talos-systems/go-debug"
kmsg "github.com/talos-systems/go-kmsg"
"github.com/talos-systems/go-debug"
"github.com/talos-systems/go-kmsg"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"github.com/talos-systems/go-smbios/smbios"
Expand All @@ -30,7 +30,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
"github.com/talos-systems/sidero/app/sidero-controller-manager/internal/api"
"github.com/talos-systems/sidero/app/sidero-controller-manager/internal/power/ipmi"
"github.com/talos-systems/sidero/app/sidero-controller-manager/pkg/constants"
Expand Down Expand Up @@ -404,7 +404,7 @@ func attemptBMCIP(ctx context.Context, client api.AgentClient, s *smbios.SMBIOS)
bmcInfo := &api.BMCInfo{}

// Create "open" client
bmcSpec := v1alpha1.BMC{
bmcSpec := metalv1.BMC{
Interface: "open",
}

Expand Down Expand Up @@ -466,7 +466,7 @@ func attemptBMCUserSetup(ctx context.Context, client api.AgentClient, s *smbios.
bmcInfo := &api.BMCInfo{}

// Create "open" client
bmcSpec := v1alpha1.BMC{
bmcSpec := metalv1.BMC{
Interface: "open",
}

Expand Down
24 changes: 12 additions & 12 deletions app/sidero-controller-manager/controllers/environment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
"github.com/talos-systems/sidero/app/sidero-controller-manager/pkg/constants"
)

Expand All @@ -48,15 +48,15 @@ func (r *EnvironmentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
//nolint:godox
// TODO: We probably should use admission webhooks instead (or in additional) to prevent
// unwanted edits instead of "fixing" the resource after the fact.
if req.Name == metalv1alpha1.EnvironmentDefault {
if req.Name == metalv1.EnvironmentDefault {
if err := ReconcileEnvironmentDefault(ctx, r.Client, r.TalosRelease, r.APIEndpoint, r.APIPort); err != nil {
return ctrl.Result{}, err
}

// do not return; re-reconcile it to update status
} //nolint:wsl

var env metalv1alpha1.Environment
var env metalv1.Environment

if err := r.Get(ctx, req.NamespacedName, &env); err != nil {
l.Error(err, "failed fetching resource")
Expand All @@ -72,15 +72,15 @@ func (r *EnvironmentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

var (
conditions = []metalv1alpha1.AssetCondition{}
conditions = []metalv1.AssetCondition{}
wg sync.WaitGroup
mu sync.Mutex
result *multierror.Error
)

for _, assetTask := range []struct {
BaseName string
Asset metalv1alpha1.Asset
Asset metalv1.Asset
}{
{
BaseName: constants.KernelAsset,
Expand All @@ -101,7 +101,7 @@ func (r *EnvironmentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
status = "True"
}

condition := metalv1alpha1.AssetCondition{
condition := metalv1.AssetCondition{
Asset: assetTask.Asset,
Status: status,
Type: "Ready",
Expand Down Expand Up @@ -183,15 +183,15 @@ func (r *EnvironmentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// ReconcileEnvironmentDefault ensures that Environment "default" exist.
func ReconcileEnvironmentDefault(ctx context.Context, c client.Client, talosRelease, apiEndpoint string, apiPort uint16) error {
key := types.NamespacedName{
Name: metalv1alpha1.EnvironmentDefault,
Name: metalv1.EnvironmentDefault,
}

env := metalv1alpha1.Environment{}
env := metalv1.Environment{}
err := c.Get(ctx, key, &env)

if apierrors.IsNotFound(err) {
env.Name = metalv1alpha1.EnvironmentDefault
env.Spec = *metalv1alpha1.EnvironmentDefaultSpec(talosRelease, apiEndpoint, apiPort)
env.Name = metalv1.EnvironmentDefault
env.Spec = *metalv1.EnvironmentDefaultSpec(talosRelease, apiEndpoint, apiPort)

err = c.Create(ctx, &env)
}
Expand All @@ -206,11 +206,11 @@ func (r *EnvironmentReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M

return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&metalv1alpha1.Environment{}).
For(&metalv1.Environment{}).
Complete(r)
}

func save(ctx context.Context, asset metalv1alpha1.Asset, file string) error {
func save(ctx context.Context, asset metalv1.Asset, file string) error {
url := asset.URL

if url == "" {
Expand Down
20 changes: 10 additions & 10 deletions app/sidero-controller-manager/controllers/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
"github.com/talos-systems/sidero/app/sidero-controller-manager/internal/power"
"github.com/talos-systems/sidero/app/sidero-controller-manager/internal/power/metal"
"github.com/talos-systems/sidero/app/sidero-controller-manager/pkg/constants"
Expand Down Expand Up @@ -65,7 +65,7 @@ type ServerReconciler struct {
func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("server", req.NamespacedName)

s := metalv1alpha1.Server{}
s := metalv1.Server{}

if err := r.APIReader.Get(ctx, req.NamespacedName, &s); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
s.Status.Ready = ready

if err := patchHelper.Patch(ctx, &s, patch.WithOwnedConditions{
Conditions: []clusterv1.ConditionType{metalv1alpha1.ConditionPowerCycle, metalv1alpha1.ConditionPXEBooted},
Conditions: []clusterv1.ConditionType{metalv1.ConditionPowerCycle, metalv1.ConditionPXEBooted},
}); err != nil {
return result, errors.WithStack(err)
}
Expand All @@ -127,7 +127,7 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

s.Status.InUse = false

conditions.Delete(&s, metalv1alpha1.ConditionPXEBooted)
conditions.Delete(&s, metalv1.ConditionPXEBooted)
} else {
s.Status.InUse = true
s.Status.IsClean = false
Expand All @@ -138,7 +138,7 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

// Talos installation was successful, so mark the server as PXE booted.
if conditions.IsTrue(serverBinding, infrav1.TalosInstalledCondition) {
conditions.MarkTrue(serverBinding, metalv1alpha1.ConditionPXEBooted)
conditions.MarkTrue(serverBinding, metalv1.ConditionPXEBooted)
}
}
}
Expand Down Expand Up @@ -232,9 +232,9 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
//
// we check LastTransitionTime to see if the server is in the wiping state for too long and
// it's time to retry the IPMI sequence
if conditions.Has(&s, metalv1alpha1.ConditionPowerCycle) &&
conditions.IsFalse(&s, metalv1alpha1.ConditionPowerCycle) &&
time.Since(conditions.GetLastTransitionTime(&s, metalv1alpha1.ConditionPowerCycle).Time) < r.RebootTimeout {
if conditions.Has(&s, metalv1.ConditionPowerCycle) &&
conditions.IsFalse(&s, metalv1.ConditionPowerCycle) &&
time.Since(conditions.GetLastTransitionTime(&s, metalv1.ConditionPowerCycle).Time) < r.RebootTimeout {
// already powercycled, reboot/heartbeat timeout not elapsed, wait more
return f(false, ctrl.Result{RequeueAfter: r.RebootTimeout / 3})
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (r *ServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

// make sure message is updated in case condition was already set to make sure LastTransitionTime will be updated
conditions.MarkFalse(&s, metalv1alpha1.ConditionPowerCycle, "InProgress", clusterv1.ConditionSeverityInfo, fmt.Sprintf("Server power cycled for wiping at %s.", time.Now().Format(time.RFC3339)))
conditions.MarkFalse(&s, metalv1.ConditionPowerCycle, "InProgress", clusterv1.ConditionSeverityInfo, fmt.Sprintf("Server power cycled for wiping at %s.", time.Now().Format(time.RFC3339)))
}

// requeue to check for wipe timeout
Expand Down Expand Up @@ -354,7 +354,7 @@ func (r *ServerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manage

return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&metalv1alpha1.Server{}).
For(&metalv1.Server{}).
Watches(
&source.Kind{Type: &infrav1.ServerBinding{}},
handler.EnqueueRequestsFromMapFunc(mapRequests),
Expand Down
28 changes: 14 additions & 14 deletions app/sidero-controller-manager/controllers/serverclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
)

// ServerClassReconciler reconciles a ServerClass object.
Expand All @@ -42,15 +42,15 @@ func (r *ServerClassReconciler) Reconcile(ctx context.Context, req ctrl.Request)
//nolint:godox
// TODO: We probably should use admission webhooks instead (or in additional) to prevent
// unwanted edits instead of "fixing" the resource after the fact.
if req.Name == metalv1alpha1.ServerClassAny {
if req.Name == metalv1.ServerClassAny {
if err := ReconcileServerClassAny(ctx, r.Client); err != nil {
return ctrl.Result{}, err
}

// do not return; re-reconcile it to update status
} //nolint:wsl

sc := metalv1alpha1.ServerClass{}
sc := metalv1.ServerClass{}

if err := r.Get(ctx, req.NamespacedName, &sc); err != nil {
l.Error(err, "failed fetching resource")
Expand All @@ -62,15 +62,15 @@ func (r *ServerClassReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}

sl := &metalv1alpha1.ServerList{}
sl := &metalv1.ServerList{}

if err := r.List(ctx, sl); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to get serverclass: %w", err)
}

results, err := metalv1alpha1.FilterServers(sl.Items,
metalv1alpha1.AcceptedServerFilter,
metalv1alpha1.NotCordonedServerFilter,
results, err := metalv1.FilterServers(sl.Items,
metalv1.AcceptedServerFilter,
metalv1.NotCordonedServerFilter,
sc.SelectorFilter(),
sc.QualifiersFilter(),
)
Expand Down Expand Up @@ -103,15 +103,15 @@ func (r *ServerClassReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// ReconcileServerClassAny ensures that ServerClass "any" exist and is in desired state.
func ReconcileServerClassAny(ctx context.Context, c client.Client) error {
key := types.NamespacedName{
Name: metalv1alpha1.ServerClassAny,
Name: metalv1.ServerClassAny,
}

sc := metalv1alpha1.ServerClass{}
sc := metalv1.ServerClass{}
err := c.Get(ctx, key, &sc)

switch {
case apierrors.IsNotFound(err):
sc.Name = metalv1alpha1.ServerClassAny
sc.Name = metalv1.ServerClassAny

return c.Create(ctx, &sc)

Expand All @@ -121,7 +121,7 @@ func ReconcileServerClassAny(ctx context.Context, c client.Client) error {
return err
}

sc.Spec.Qualifiers = metalv1alpha1.Qualifiers{}
sc.Spec.Qualifiers = metalv1.Qualifiers{}

return patchHelper.Patch(ctx, &sc)

Expand All @@ -137,7 +137,7 @@ func (r *ServerClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
mapRequests := func(a client.Object) []reconcile.Request {
reqList := []reconcile.Request{}

scList := &metalv1alpha1.ServerClassList{}
scList := &metalv1.ServerClassList{}

if err := r.List(ctx, scList); err != nil {
return reqList
Expand All @@ -160,9 +160,9 @@ func (r *ServerClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M

return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&metalv1alpha1.ServerClass{}).
For(&metalv1.ServerClass{}).
Watches(
&source.Kind{Type: &metalv1alpha1.Server{}},
&source.Kind{Type: &metalv1.Server{}},
handler.EnqueueRequestsFromMapFunc(mapRequests),
).
Complete(r)
Expand Down
Loading

0 comments on commit 15f6730

Please sign in to comment.