Skip to content

Commit

Permalink
refactor: avoids failing agent if cloudmeta svc can't be created
Browse files Browse the repository at this point in the history
  • Loading branch information
VAveryanov8 committed Jan 9, 2025
1 parent 03a63e4 commit f6d8540
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions pkg/cmd/agent/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -57,5 +57,5 @@ func newMetadataHandler(logger log.Logger) (http.HandlerFunc, error) {
CloudProvider: string(instanceMeta.CloudProvider),
InstanceType: instanceMeta.InstanceType,
})
}, nil
}
}
5 changes: 1 addition & 4 deletions pkg/cmd/agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f6d8540

Please sign in to comment.