From 05c4b749ab51f716574ac7bc11f5146d5350e911 Mon Sep 17 00:00:00 2001 From: Tudor Domnescu Date: Tue, 25 Jun 2024 13:20:17 +0200 Subject: [PATCH] equinix: bring logging into provider for internal errors --- controllers/ciresource_fsm.go | 2 +- pkg/providers/equinix.go | 6 +++++- pkg/providers/providersFactory.go | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/ciresource_fsm.go b/controllers/ciresource_fsm.go index 0bc33be..29e91d2 100644 --- a/controllers/ciresource_fsm.go +++ b/controllers/ciresource_fsm.go @@ -328,7 +328,7 @@ func (f *CIResourceFSM) BeforeAnyState(before CIResourceFSMHandler) { func (f *CIResourceFSM) Process(cir *ofcirv1.CIResource, cipool *ofcirv1.CIPool, cipoolSecret *v1.Secret) (bool, bool, time.Duration, error) { - provider, err := providers.NewProvider(cipool, cipoolSecret) + provider, err := providers.NewProvider(cipool, cipoolSecret, f.logger) if err != nil { return false, false, time.Duration(0), fmt.Errorf("error in provider factory: %w", err) } diff --git a/pkg/providers/equinix.go b/pkg/providers/equinix.go index c816fe4..4beac2c 100644 --- a/pkg/providers/equinix.go +++ b/pkg/providers/equinix.go @@ -6,6 +6,7 @@ import ( "strings" "sync" + "github.com/go-logr/logr" "github.com/google/uuid" "github.com/packethost/packngo" ) @@ -28,9 +29,10 @@ type equinixProviderConfig struct { type equinixProvider struct { config equinixProviderConfig client *packngo.Client + logger logr.Logger } -func EquinixProviderFactory(providerInfo string, secretData map[string][]byte) (Provider, error) { +func EquinixProviderFactory(providerInfo string, secretData map[string][]byte, logger logr.Logger) (Provider, error) { config := equinixProviderConfig{ ProjectID: "", Token: "", @@ -52,6 +54,7 @@ func EquinixProviderFactory(providerInfo string, secretData map[string][]byte) ( return &equinixProvider{ config: config, client: client, + logger: logger, }, nil } @@ -91,6 +94,7 @@ func (p *equinixProvider) Acquire(poolSize int, poolName string, poolType string device, _, err := p.client.Devices.Create(&cr) if err != nil { + p.logger.Error(err, "error creating device, trying next metro", "hostname", resourceName, "metro", metro) continue } diff --git a/pkg/providers/providersFactory.go b/pkg/providers/providersFactory.go index b27e788..a841c0a 100644 --- a/pkg/providers/providersFactory.go +++ b/pkg/providers/providersFactory.go @@ -3,6 +3,7 @@ package providers import ( "fmt" + "github.com/go-logr/logr" ofcirv1 "github.com/openshift/ofcir/api/v1" v1 "k8s.io/api/core/v1" ) @@ -17,7 +18,7 @@ const ( ProviderIbmcloud ProviderType = "ibmcloud" ) -func NewProvider(pool *ofcirv1.CIPool, poolSecret *v1.Secret) (Provider, error) { +func NewProvider(pool *ofcirv1.CIPool, poolSecret *v1.Secret, logger logr.Logger) (Provider, error) { switch ProviderType(pool.Spec.Provider) { case ProviderDummy: @@ -27,7 +28,7 @@ func NewProvider(pool *ofcirv1.CIPool, poolSecret *v1.Secret) (Provider, error) case ProviderIronic: return IronicProviderFactory(pool.Spec.ProviderInfo, poolSecret.Data) case ProviderEquinix: - return EquinixProviderFactory(pool.Spec.ProviderInfo, poolSecret.Data) + return EquinixProviderFactory(pool.Spec.ProviderInfo, poolSecret.Data, logger) case ProviderIbmcloud: return IbmcloudProviderFactory(pool.Spec.ProviderInfo, poolSecret.Data) default: