From f6d8540861e3d77b4c54323b3df6ae72279c0e5d Mon Sep 17 00:00:00 2001 From: Vasil Averyanau Date: Thu, 9 Jan 2025 13:34:38 +0100 Subject: [PATCH] refactor: avoids failing agent if cloudmeta svc can't be created --- pkg/cmd/agent/metadata.go | 14 +++++++------- pkg/cmd/agent/server.go | 5 +---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/agent/metadata.go b/pkg/cmd/agent/metadata.go index 712319a20..91929c942 100644 --- a/pkg/cmd/agent/metadata.go +++ b/pkg/cmd/agent/metadata.go @@ -14,12 +14,7 @@ import ( "github.com/scylladb/scylla-manager/v3/swagger/gen/agent/models" ) -func newMetadataHandler(logger log.Logger) (http.HandlerFunc, error) { - metaSvc, err := cloudmeta.NewCloudMeta(logger) - if err != nil { - return nil, errors.Wrap(err, "NewCloudMeta") - } - +func newMetadataHandler(logger log.Logger) http.HandlerFunc { var ( m sync.Mutex loaded bool @@ -34,6 +29,11 @@ func newMetadataHandler(logger log.Logger) (http.HandlerFunc, error) { return metadata, nil } + metaSvc, err := cloudmeta.NewCloudMeta(logger) + if err != nil { + return cloudmeta.InstanceMetadata{}, errors.Wrap(err, "NewCloudMeta") + } + metadata, err = metaSvc.GetInstanceMetadata(context.Background()) if err != nil { return cloudmeta.InstanceMetadata{}, err @@ -57,5 +57,5 @@ func newMetadataHandler(logger log.Logger) (http.HandlerFunc, error) { CloudProvider: string(instanceMeta.CloudProvider), InstanceType: instanceMeta.InstanceType, }) - }, nil + } } diff --git a/pkg/cmd/agent/server.go b/pkg/cmd/agent/server.go index e52398306..c9713f5a9 100644 --- a/pkg/cmd/agent/server.go +++ b/pkg/cmd/agent/server.go @@ -160,10 +160,7 @@ func (s *server) makeServers(ctx context.Context) error { if err != nil { return errors.Wrapf(err, "tls") } - cloudMeta, err := newMetadataHandler(s.logger.Named("metadata")) - if err != nil { - return errors.Wrap(err, "newMetadataHandler") - } + cloudMeta := newMetadataHandler(s.logger.Named("metadata")) s.httpsServer = &http.Server{ Addr: s.config.HTTPS, TLSConfig: tlsConfig,