Skip to content

Commit

Permalink
fix: use default time servers in time API if none are configured
Browse files Browse the repository at this point in the history
This fixes simple bug:

```
$ talosctl -n 172.20.0.2 time
error fetching time: 1 error occurred:
	* 172.20.0.2: rpc error: code = Unknown desc = no time servers configured
```

After the change:

```
$ talosctl -n 172.20.0.2 time
NODE         NTP-SERVER     NODE-TIME                                 NTP-SERVER-TIME
172.20.0.2   pool.ntp.org   2021-12-10 14:25:38.871656717 +0000 UTC   2021-12-10 14:25:38.92119139 +0000 UTC
```

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
(cherry picked from commit ec641f7)
  • Loading branch information
smira committed Dec 13, 2021
1 parent c60e153 commit e69eaca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

timeapi "github.com/talos-systems/talos/pkg/machinery/api/time"
"github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/constants"
)

// ConfigProvider defines an interface sufficient for the TimeServer.
Expand All @@ -40,7 +41,7 @@ func (r *TimeServer) Time(ctx context.Context, in *emptypb.Empty) (reply *timeap
timeServers := r.ConfigProvider.Config().Machine().Time().Servers()

if len(timeServers) == 0 {
return nil, fmt.Errorf("no time servers configured")
timeServers = []string{constants.DefaultNTPServer}
}

return r.TimeCheck(ctx, &timeapi.TimeRequest{
Expand Down
36 changes: 36 additions & 0 deletions internal/integration/cli/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//go:build integration_cli
// +build integration_cli

package cli

import (
"regexp"

"github.com/talos-systems/talos/internal/integration/base"
)

// TimeSuite verifies dmesg command.
type TimeSuite struct {
base.CLISuite
}

// SuiteName ...
func (suite *TimeSuite) SuiteName() string {
return "cli.TimeSuite"
}

// TestDefault runs default time check.
func (suite *TimeSuite) TestDefault() {
suite.RunCLI([]string{"time", "--nodes", suite.RandomDiscoveredNode()},
base.StdoutShouldMatch(regexp.MustCompile(`NTP-SERVER`)),
base.StdoutShouldMatch(regexp.MustCompile(`UTC`)),
)
}

func init() {
allSuites = append(allSuites, new(TimeSuite))
}

0 comments on commit e69eaca

Please sign in to comment.