Skip to content

Commit

Permalink
Merge pull request #50 from tdomnesc/equinix-logger
Browse files Browse the repository at this point in the history
METAL-1061 bring logging into Equinix provider for internal errors
  • Loading branch information
openshift-merge-bot[bot] authored Jul 15, 2024
2 parents 7ec3aed + 05c4b74 commit 68a7e73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/ciresource_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/providers/equinix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"sync"

"github.com/go-logr/logr"
"github.com/google/uuid"
"github.com/packethost/packngo"
)
Expand All @@ -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: "",
Expand All @@ -52,6 +54,7 @@ func EquinixProviderFactory(providerInfo string, secretData map[string][]byte) (
return &equinixProvider{
config: config,
client: client,
logger: logger,
}, nil
}

Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/providers/providersFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 68a7e73

Please sign in to comment.