Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move networkd, timed APIs to machined, remove routerd
This moves implementation of the user-facing APIs to the machined, and as now all the APIs are implemented by machined, remove routerd and adjust apid to proxy to machined. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
- Loading branch information
Showing
29 changed files
with
378 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ policies: | |
- timed | ||
- talosctl | ||
- trustd | ||
- routerd | ||
- talosctl | ||
- kernel | ||
- security | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
internal/app/machined/internal/server/v1alpha1/v1alpha1_time.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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/. | ||
|
||
package runtime | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/beevik/ntp" | ||
"github.com/golang/protobuf/ptypes/empty" | ||
"google.golang.org/grpc" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
|
||
timeapi "github.com/talos-systems/talos/pkg/machinery/api/time" | ||
"github.com/talos-systems/talos/pkg/machinery/config" | ||
) | ||
|
||
// ConfigProvider defines an interface sufficient for the TimeServer. | ||
type ConfigProvider interface { | ||
Config() config.Provider | ||
} | ||
|
||
// TimeServer implements TimeService API. | ||
type TimeServer struct { | ||
timeapi.UnimplementedTimeServiceServer | ||
|
||
ConfigProvider ConfigProvider | ||
} | ||
|
||
// Register implements the factory.Registrator interface. | ||
func (r *TimeServer) Register(s *grpc.Server) { | ||
timeapi.RegisterTimeServiceServer(s, r) | ||
} | ||
|
||
// Time issues a query to the configured ntp server and displays the results. | ||
func (r *TimeServer) Time(ctx context.Context, in *empty.Empty) (reply *timeapi.TimeResponse, err error) { | ||
timeServers := r.ConfigProvider.Config().Machine().Time().Servers() | ||
|
||
if len(timeServers) == 0 { | ||
return nil, fmt.Errorf("no time servers configured") | ||
} | ||
|
||
return r.TimeCheck(ctx, &timeapi.TimeRequest{ | ||
Server: timeServers[0], | ||
}) | ||
} | ||
|
||
// TimeCheck issues a query to the specified ntp server and displays the results. | ||
func (r *TimeServer) TimeCheck(ctx context.Context, in *timeapi.TimeRequest) (reply *timeapi.TimeResponse, err error) { | ||
rt, err := ntp.Query(in.Server) | ||
if err != nil { | ||
return nil, fmt.Errorf("error querying NTP server %q: %w", in.Server, err) | ||
} | ||
|
||
if err = rt.Validate(); err != nil { | ||
return nil, fmt.Errorf("error validating NTP response: %w", err) | ||
} | ||
|
||
return &timeapi.TimeResponse{ | ||
Messages: []*timeapi.Time{ | ||
{ | ||
Server: in.Server, | ||
Localtime: timestamppb.New(time.Now()), | ||
Remotetime: timestamppb.New(rt.Time), | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.