chore: drop deprecated stuff for Talos 1.5
* drop old resources API, which was deprecated long time ago * use bootstrapped event in `talosctl get --watch` to better align columns in the table output Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
parent
61cad86731
commit
bb02dd263c
@ -219,8 +219,6 @@ COPY ./api/time/time.proto /api/time/time.proto
|
|||||||
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size time/time.proto
|
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size time/time.proto
|
||||||
COPY ./api/cluster/cluster.proto /api/cluster/cluster.proto
|
COPY ./api/cluster/cluster.proto /api/cluster/cluster.proto
|
||||||
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size cluster/cluster.proto
|
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size cluster/cluster.proto
|
||||||
COPY ./api/resource/resource.proto /api/resource/resource.proto
|
|
||||||
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size resource/resource.proto
|
|
||||||
COPY ./api/resource/config/config.proto /api/resource/config/config.proto
|
COPY ./api/resource/config/config.proto /api/resource/config/config.proto
|
||||||
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size resource/config/config.proto
|
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size resource/config/config.proto
|
||||||
COPY ./api/resource/network/device_config.proto /api/resource/network/device_config.proto
|
COPY ./api/resource/network/device_config.proto /api/resource/network/device_config.proto
|
||||||
@ -899,7 +897,6 @@ RUN protoc \
|
|||||||
/protos/resource/definitions/**/*.proto \
|
/protos/resource/definitions/**/*.proto \
|
||||||
/protos/inspect/*.proto \
|
/protos/inspect/*.proto \
|
||||||
/protos/machine/*.proto \
|
/protos/machine/*.proto \
|
||||||
/protos/resource/*.proto \
|
|
||||||
/protos/security/*.proto \
|
/protos/security/*.proto \
|
||||||
/protos/storage/*.proto \
|
/protos/storage/*.proto \
|
||||||
/protos/time/*.proto
|
/protos/time/*.proto
|
||||||
|
Binary file not shown.
@ -1,97 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package resource;
|
|
||||||
|
|
||||||
option go_package = "github.com/siderolabs/talos/pkg/machinery/api/resource";
|
|
||||||
|
|
||||||
import "common/common.proto";
|
|
||||||
import "google/protobuf/timestamp.proto";
|
|
||||||
|
|
||||||
// The resource service definition.
|
|
||||||
//
|
|
||||||
// ResourceService provides user-facing API for the Talos resources.
|
|
||||||
service ResourceService {
|
|
||||||
option (common.remove_deprecated_service) = "v1.5";
|
|
||||||
option deprecated = true;
|
|
||||||
rpc Get(GetRequest) returns (GetResponse);
|
|
||||||
rpc List(ListRequest) returns (stream ListResponse);
|
|
||||||
rpc Watch(WatchRequest) returns (stream WatchResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
// common resource definition
|
|
||||||
|
|
||||||
message Resource {
|
|
||||||
Metadata metadata = 1;
|
|
||||||
Spec spec = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Metadata {
|
|
||||||
string namespace = 1;
|
|
||||||
string type = 2;
|
|
||||||
string id = 3;
|
|
||||||
string version = 4;
|
|
||||||
string owner = 7;
|
|
||||||
string phase = 5;
|
|
||||||
google.protobuf.Timestamp created = 8;
|
|
||||||
google.protobuf.Timestamp updated = 9;
|
|
||||||
repeated string finalizers = 6;
|
|
||||||
map<string, string> labels = 10;
|
|
||||||
map<string, string> annotations = 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Spec {
|
|
||||||
bytes yaml = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rpc Get
|
|
||||||
message GetRequest {
|
|
||||||
string namespace = 1;
|
|
||||||
string type = 2;
|
|
||||||
string id = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The GetResponse message contains the Resource returned.
|
|
||||||
message Get {
|
|
||||||
common.Metadata metadata = 1;
|
|
||||||
Resource definition = 2;
|
|
||||||
Resource resource = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetResponse {
|
|
||||||
repeated Get messages = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rpc List
|
|
||||||
// The ListResponse message contains the Resource returned.
|
|
||||||
message ListRequest {
|
|
||||||
string namespace = 1;
|
|
||||||
string type = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ListResponse {
|
|
||||||
common.Metadata metadata = 1;
|
|
||||||
Resource definition = 2;
|
|
||||||
Resource resource = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rpc Watch
|
|
||||||
// The WatchResponse message contains the Resource returned.
|
|
||||||
message WatchRequest {
|
|
||||||
string namespace = 1;
|
|
||||||
string type = 2;
|
|
||||||
string id = 3;
|
|
||||||
uint32 tail_events = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EventType {
|
|
||||||
CREATED = 0;
|
|
||||||
UPDATED = 1;
|
|
||||||
DESTROYED = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message WatchResponse {
|
|
||||||
common.Metadata metadata = 1;
|
|
||||||
EventType event_type = 2;
|
|
||||||
Resource definition = 3;
|
|
||||||
Resource resource = 4;
|
|
||||||
}
|
|
@ -140,6 +140,8 @@ func getResources(args []string) func(ctx context.Context, c *client.Client) err
|
|||||||
go aggregateEvents(ctx, aggregatedCh, watchCh, node)
|
go aggregateEvents(ctx, aggregatedCh, watchCh, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bootstrapped bool
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var nev nodeAndEvent
|
var nev nodeAndEvent
|
||||||
|
|
||||||
@ -154,7 +156,12 @@ func getResources(args []string) func(ctx context.Context, c *client.Client) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nev.ev.Type == state.Bootstrapped {
|
if nev.ev.Type == state.Bootstrapped {
|
||||||
// TODO: in Talos 1.4, use Bootstrapped event to determine whether it's time to flush the first line
|
bootstrapped = true
|
||||||
|
|
||||||
|
if err = out.Flush(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,8 +174,10 @@ func getResources(args []string) func(ctx context.Context, c *client.Client) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = out.Flush(); err != nil {
|
if bootstrapped {
|
||||||
return err
|
if err = out.Flush(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,8 +131,6 @@ func apidMain() error {
|
|||||||
"/machine.MachineService/Logs",
|
"/machine.MachineService/Logs",
|
||||||
"/machine.MachineService/PacketCapture",
|
"/machine.MachineService/PacketCapture",
|
||||||
"/machine.MachineService/Read",
|
"/machine.MachineService/Read",
|
||||||
"/resource.ResourceService/List",
|
|
||||||
"/resource.ResourceService/Watch",
|
|
||||||
"/os.OSService/Dmesg",
|
"/os.OSService/Dmesg",
|
||||||
"/cluster.ClusterService/HealthCheck",
|
"/cluster.ClusterService/HealthCheck",
|
||||||
} {
|
} {
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/security"
|
"github.com/siderolabs/talos/pkg/machinery/api/security"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/time"
|
"github.com/siderolabs/talos/pkg/machinery/api/time"
|
||||||
@ -211,7 +210,6 @@ func TestAPIIdiosyncrasies(t *testing.T) {
|
|||||||
cluster.File_cluster_cluster_proto.Services(),
|
cluster.File_cluster_cluster_proto.Services(),
|
||||||
inspect.File_inspect_inspect_proto.Services(),
|
inspect.File_inspect_inspect_proto.Services(),
|
||||||
machine.File_machine_machine_proto.Services(),
|
machine.File_machine_machine_proto.Services(),
|
||||||
resource.File_resource_resource_proto.Services(),
|
|
||||||
// security.File_security_security_proto.Services() is different
|
// security.File_security_security_proto.Services() is different
|
||||||
storage.File_storage_storage_proto.Services(),
|
storage.File_storage_storage_proto.Services(),
|
||||||
time.File_time_time_proto.Services(),
|
time.File_time_time_proto.Services(),
|
||||||
@ -361,7 +359,6 @@ func TestDeprecatedAPIs(t *testing.T) {
|
|||||||
cluster.File_cluster_cluster_proto,
|
cluster.File_cluster_cluster_proto,
|
||||||
inspect.File_inspect_inspect_proto,
|
inspect.File_inspect_inspect_proto,
|
||||||
machine.File_machine_machine_proto,
|
machine.File_machine_machine_proto,
|
||||||
resource.File_resource_resource_proto,
|
|
||||||
security.File_security_security_proto,
|
security.File_security_security_proto,
|
||||||
storage.File_storage_storage_proto,
|
storage.File_storage_storage_proto,
|
||||||
time.File_time_time_proto,
|
time.File_time_time_proto,
|
||||||
|
@ -76,7 +76,6 @@ import (
|
|||||||
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
||||||
timeapi "github.com/siderolabs/talos/pkg/machinery/api/time"
|
timeapi "github.com/siderolabs/talos/pkg/machinery/api/time"
|
||||||
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
|
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
|
||||||
@ -148,7 +147,6 @@ func (s *Server) Register(obj *grpc.Server) {
|
|||||||
|
|
||||||
machine.RegisterMachineServiceServer(obj, s)
|
machine.RegisterMachineServiceServer(obj, s)
|
||||||
cluster.RegisterClusterServiceServer(obj, s)
|
cluster.RegisterClusterServiceServer(obj, s)
|
||||||
resource.RegisterResourceServiceServer(obj, &resources.Server{Resources: resourceState}) //nolint:staticcheck
|
|
||||||
cosiv1alpha1.RegisterStateServer(obj, server.NewState(resourceState))
|
cosiv1alpha1.RegisterStateServer(obj, server.NewState(resourceState))
|
||||||
inspect.RegisterInspectServiceServer(obj, &InspectServer{server: s})
|
inspect.RegisterInspectServiceServer(obj, &InspectServer{server: s})
|
||||||
storage.RegisterStorageServiceServer(obj, &storaged.Server{Controller: s.Controller})
|
storage.RegisterStorageServiceServer(obj, &storaged.Server{Controller: s.Controller})
|
||||||
|
@ -85,15 +85,12 @@ var rules = map[string]role.Set{
|
|||||||
"/machine.MachineService/Version": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/machine.MachineService/Version": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
||||||
|
|
||||||
// per-type authorization is handled by the service itself
|
// per-type authorization is handled by the service itself
|
||||||
"/resource.ResourceService/Get": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/cosi.resource.State/Create": role.MakeSet(role.Admin),
|
||||||
"/resource.ResourceService/List": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/cosi.resource.State/Destroy": role.MakeSet(role.Admin),
|
||||||
"/resource.ResourceService/Watch": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/cosi.resource.State/Get": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
||||||
"/cosi.resource.State/Create": role.MakeSet(role.Admin),
|
"/cosi.resource.State/List": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
||||||
"/cosi.resource.State/Destroy": role.MakeSet(role.Admin),
|
"/cosi.resource.State/Update": role.MakeSet(role.Admin),
|
||||||
"/cosi.resource.State/Get": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/cosi.resource.State/Watch": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
||||||
"/cosi.resource.State/List": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
|
||||||
"/cosi.resource.State/Update": role.MakeSet(role.Admin),
|
|
||||||
"/cosi.resource.State/Watch": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
|
||||||
|
|
||||||
"/storage.StorageService/Disks": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
"/storage.StorageService/Disks": role.MakeSet(role.Admin, role.Operator, role.Reader),
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/siderolabs/talos/pkg/machinery/api/cluster"
|
"github.com/siderolabs/talos/pkg/machinery/api/cluster"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
"github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/time"
|
"github.com/siderolabs/talos/pkg/machinery/api/time"
|
||||||
)
|
)
|
||||||
@ -29,7 +28,6 @@ func collectMethods(t *testing.T) map[string]struct{} {
|
|||||||
cluster.ClusterService_ServiceDesc,
|
cluster.ClusterService_ServiceDesc,
|
||||||
inspect.InspectService_ServiceDesc,
|
inspect.InspectService_ServiceDesc,
|
||||||
machine.MachineService_ServiceDesc,
|
machine.MachineService_ServiceDesc,
|
||||||
resource.ResourceService_ServiceDesc,
|
|
||||||
// security.SecurityService_ServiceDesc, - not in machined
|
// security.SecurityService_ServiceDesc, - not in machined
|
||||||
storage.StorageService_ServiceDesc,
|
storage.StorageService_ServiceDesc,
|
||||||
time.TimeService_ServiceDesc,
|
time.TimeService_ServiceDesc,
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
storaged "github.com/siderolabs/talos/internal/app/storaged"
|
storaged "github.com/siderolabs/talos/internal/app/storaged"
|
||||||
"github.com/siderolabs/talos/internal/pkg/configuration"
|
"github.com/siderolabs/talos/internal/pkg/configuration"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
"github.com/siderolabs/talos/pkg/machinery/api/machine"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
"github.com/siderolabs/talos/pkg/machinery/api/storage"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/config/configloader"
|
"github.com/siderolabs/talos/pkg/machinery/config/configloader"
|
||||||
v1alpha1machine "github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/machine"
|
v1alpha1machine "github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1/machine"
|
||||||
@ -63,7 +62,6 @@ func (s *Server) Register(obj *grpc.Server) {
|
|||||||
|
|
||||||
storage.RegisterStorageServiceServer(obj, &storaged.Server{Controller: s.controller})
|
storage.RegisterStorageServiceServer(obj, &storaged.Server{Controller: s.controller})
|
||||||
machine.RegisterMachineServiceServer(obj, s)
|
machine.RegisterMachineServiceServer(obj, s)
|
||||||
resource.RegisterResourceServiceServer(obj, &resources.Server{Resources: resourceState}) //nolint:staticcheck
|
|
||||||
cosiv1alpha1.RegisterStateServer(obj, server.NewState(resourceState))
|
cosiv1alpha1.RegisterStateServer(obj, server.NewState(resourceState))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
// Package resources contains shared implementation of COSI resource API.
|
||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,290 +0,0 @@
|
|||||||
// 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 resources implements resources API server.
|
|
||||||
package resources
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/cosi-project/runtime/pkg/resource"
|
|
||||||
"github.com/cosi-project/runtime/pkg/resource/meta"
|
|
||||||
"github.com/cosi-project/runtime/pkg/state"
|
|
||||||
"github.com/siderolabs/gen/slices"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
|
||||||
|
|
||||||
resourceapi "github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Server implements ResourceService API.
|
|
||||||
type Server struct {
|
|
||||||
resourceapi.UnimplementedResourceServiceServer
|
|
||||||
|
|
||||||
Resources state.State
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalResource(r resource.Resource) (*resourceapi.Resource, error) {
|
|
||||||
md := &resourceapi.Metadata{
|
|
||||||
Namespace: r.Metadata().Namespace(),
|
|
||||||
Type: r.Metadata().Type(),
|
|
||||||
Id: r.Metadata().ID(),
|
|
||||||
Version: r.Metadata().Version().String(),
|
|
||||||
Phase: r.Metadata().Phase().String(),
|
|
||||||
Owner: r.Metadata().Owner(),
|
|
||||||
Created: timestamppb.New(r.Metadata().Created()),
|
|
||||||
Updated: timestamppb.New(r.Metadata().Updated()),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fin := range *r.Metadata().Finalizers() {
|
|
||||||
md.Finalizers = append(md.Finalizers, fin)
|
|
||||||
}
|
|
||||||
|
|
||||||
spec := &resourceapi.Spec{}
|
|
||||||
|
|
||||||
if !resource.IsTombstone(r) && r.Spec() != nil {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
spec.Yaml, err = yaml.Marshal(r.Spec())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resourceapi.Resource{
|
|
||||||
Metadata: md,
|
|
||||||
Spec: spec,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceKind struct {
|
|
||||||
Namespace resource.Namespace
|
|
||||||
Type resource.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint:gocyclo
|
|
||||||
func (s *Server) resolveResourceKind(ctx context.Context, kind *resourceKind) (*meta.ResourceDefinition, error) {
|
|
||||||
registeredResources, err := s.Resources.List(ctx, resource.NewMetadata(meta.NamespaceName, meta.ResourceDefinitionType, "", resource.VersionUndefined))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
matched := []*meta.ResourceDefinition{}
|
|
||||||
|
|
||||||
for _, item := range registeredResources.Items {
|
|
||||||
rd, ok := item.(*meta.ResourceDefinition)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected resource definition type")
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.EqualFold(rd.Metadata().ID(), kind.Type) {
|
|
||||||
matched = append(matched, rd)
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
spec := rd.TypedSpec()
|
|
||||||
|
|
||||||
for _, alias := range spec.AllAliases {
|
|
||||||
if strings.EqualFold(alias, kind.Type) {
|
|
||||||
matched = append(matched, rd)
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case len(matched) == 1:
|
|
||||||
kind.Type = matched[0].TypedSpec().Type
|
|
||||||
|
|
||||||
if kind.Namespace == "" {
|
|
||||||
kind.Namespace = matched[0].TypedSpec().DefaultNamespace
|
|
||||||
}
|
|
||||||
|
|
||||||
return matched[0], nil
|
|
||||||
case len(matched) > 1:
|
|
||||||
matchedTypes := slices.Map(matched, func(rd *meta.ResourceDefinition) string { return rd.Metadata().ID() })
|
|
||||||
|
|
||||||
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("resource type %q is ambiguous: %v", kind.Type, matchedTypes))
|
|
||||||
default:
|
|
||||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("resource %q is not registered", kind.Type))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get implements resource.ResourceServiceServer interface.
|
|
||||||
func (s *Server) Get(ctx context.Context, in *resourceapi.GetRequest) (*resourceapi.GetResponse, error) {
|
|
||||||
kind := &resourceKind{
|
|
||||||
Namespace: in.GetNamespace(),
|
|
||||||
Type: in.GetType(),
|
|
||||||
}
|
|
||||||
|
|
||||||
rd, err := s.resolveResourceKind(ctx, kind)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := s.Resources.Get(ctx, resource.NewMetadata(kind.Namespace, kind.Type, in.GetId(), resource.VersionUndefined))
|
|
||||||
if err != nil {
|
|
||||||
if state.IsNotFoundError(err) {
|
|
||||||
return nil, status.Error(codes.NotFound, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
protoD, err := marshalResource(rd)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
protoR, err := marshalResource(r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resourceapi.GetResponse{
|
|
||||||
Messages: []*resourceapi.Get{
|
|
||||||
{
|
|
||||||
Definition: protoD,
|
|
||||||
Resource: protoR,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// List implements resource.ResourceServiceServer interface.
|
|
||||||
func (s *Server) List(in *resourceapi.ListRequest, srv resourceapi.ResourceService_ListServer) error {
|
|
||||||
kind := &resourceKind{
|
|
||||||
Namespace: in.GetNamespace(),
|
|
||||||
Type: in.GetType(),
|
|
||||||
}
|
|
||||||
|
|
||||||
rd, err := s.resolveResourceKind(srv.Context(), kind)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
list, err := s.Resources.List(srv.Context(), resource.NewMetadata(kind.Namespace, kind.Type, "", resource.VersionUndefined))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
protoD, err := marshalResource(rd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = srv.Send(&resourceapi.ListResponse{
|
|
||||||
Definition: protoD,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, r := range list.Items {
|
|
||||||
protoR, err := marshalResource(r)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = srv.Send(&resourceapi.ListResponse{
|
|
||||||
Resource: protoR,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch implements resource.ResourceServiceServer interface.
|
|
||||||
//
|
|
||||||
//nolint:gocyclo
|
|
||||||
func (s *Server) Watch(in *resourceapi.WatchRequest, srv resourceapi.ResourceService_WatchServer) error {
|
|
||||||
kind := &resourceKind{
|
|
||||||
Namespace: in.GetNamespace(),
|
|
||||||
Type: in.GetType(),
|
|
||||||
}
|
|
||||||
|
|
||||||
rd, err := s.resolveResourceKind(srv.Context(), kind)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
protoD, err := marshalResource(rd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = srv.Send(&resourceapi.WatchResponse{
|
|
||||||
Definition: protoD,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(srv.Context())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
eventCh := make(chan state.Event)
|
|
||||||
|
|
||||||
md := resource.NewMetadata(kind.Namespace, kind.Type, in.GetId(), resource.VersionUndefined)
|
|
||||||
|
|
||||||
if in.GetId() == "" {
|
|
||||||
opts := []state.WatchKindOption{}
|
|
||||||
|
|
||||||
if in.TailEvents > 0 {
|
|
||||||
opts = append(opts, state.WithKindTailEvents(int(in.TailEvents)))
|
|
||||||
} else {
|
|
||||||
opts = append(opts, state.WithBootstrapContents(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.Resources.WatchKind(ctx, md, eventCh, opts...)
|
|
||||||
} else {
|
|
||||||
opts := []state.WatchOption{}
|
|
||||||
|
|
||||||
if in.TailEvents > 0 {
|
|
||||||
opts = append(opts, state.WithTailEvents(int(in.TailEvents)))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.Resources.Watch(ctx, md, eventCh, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error setting up watch: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for event := range eventCh {
|
|
||||||
protoR, err := marshalResource(event.Resource)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := &resourceapi.WatchResponse{
|
|
||||||
Resource: protoR,
|
|
||||||
}
|
|
||||||
|
|
||||||
switch event.Type {
|
|
||||||
case state.Created:
|
|
||||||
resp.EventType = resourceapi.EventType_CREATED
|
|
||||||
case state.Updated:
|
|
||||||
resp.EventType = resourceapi.EventType_UPDATED
|
|
||||||
case state.Destroyed:
|
|
||||||
resp.EventType = resourceapi.EventType_DESTROYED
|
|
||||||
case state.Bootstrapped:
|
|
||||||
// ignore
|
|
||||||
case state.Errored:
|
|
||||||
return fmt.Errorf("error watching resource: %w", event.Error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = srv.Send(resp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,245 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// - protoc-gen-go-grpc v1.3.0
|
|
||||||
// - protoc v4.23.0
|
|
||||||
// source: resource/resource.proto
|
|
||||||
|
|
||||||
package resource
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
codes "google.golang.org/grpc/codes"
|
|
||||||
status "google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
// Requires gRPC-Go v1.32.0 or later.
|
|
||||||
const _ = grpc.SupportPackageIsVersion7
|
|
||||||
|
|
||||||
const (
|
|
||||||
ResourceService_Get_FullMethodName = "/resource.ResourceService/Get"
|
|
||||||
ResourceService_List_FullMethodName = "/resource.ResourceService/List"
|
|
||||||
ResourceService_Watch_FullMethodName = "/resource.ResourceService/Watch"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResourceServiceClient is the client API for ResourceService service.
|
|
||||||
//
|
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type ResourceServiceClient interface {
|
|
||||||
Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error)
|
|
||||||
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (ResourceService_ListClient, error)
|
|
||||||
Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (ResourceService_WatchClient, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceServiceClient struct {
|
|
||||||
cc grpc.ClientConnInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func NewResourceServiceClient(cc grpc.ClientConnInterface) ResourceServiceClient {
|
|
||||||
return &resourceServiceClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *resourceServiceClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
|
|
||||||
out := new(GetResponse)
|
|
||||||
err := c.cc.Invoke(ctx, ResourceService_Get_FullMethodName, in, out, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *resourceServiceClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (ResourceService_ListClient, error) {
|
|
||||||
stream, err := c.cc.NewStream(ctx, &ResourceService_ServiceDesc.Streams[0], ResourceService_List_FullMethodName, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &resourceServiceListClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceService_ListClient interface {
|
|
||||||
Recv() (*ListResponse, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceServiceListClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *resourceServiceListClient) Recv() (*ListResponse, error) {
|
|
||||||
m := new(ListResponse)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *resourceServiceClient) Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (ResourceService_WatchClient, error) {
|
|
||||||
stream, err := c.cc.NewStream(ctx, &ResourceService_ServiceDesc.Streams[1], ResourceService_Watch_FullMethodName, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
x := &resourceServiceWatchClient{stream}
|
|
||||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceService_WatchClient interface {
|
|
||||||
Recv() (*WatchResponse, error)
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceServiceWatchClient struct {
|
|
||||||
grpc.ClientStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *resourceServiceWatchClient) Recv() (*WatchResponse, error) {
|
|
||||||
m := new(WatchResponse)
|
|
||||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceServiceServer is the server API for ResourceService service.
|
|
||||||
// All implementations must embed UnimplementedResourceServiceServer
|
|
||||||
// for forward compatibility
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type ResourceServiceServer interface {
|
|
||||||
Get(context.Context, *GetRequest) (*GetResponse, error)
|
|
||||||
List(*ListRequest, ResourceService_ListServer) error
|
|
||||||
Watch(*WatchRequest, ResourceService_WatchServer) error
|
|
||||||
mustEmbedUnimplementedResourceServiceServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnimplementedResourceServiceServer must be embedded to have forward compatible implementations.
|
|
||||||
type UnimplementedResourceServiceServer struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UnimplementedResourceServiceServer) Get(context.Context, *GetRequest) (*GetResponse, error) {
|
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Get not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedResourceServiceServer) List(*ListRequest, ResourceService_ListServer) error {
|
|
||||||
return status.Errorf(codes.Unimplemented, "method List not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedResourceServiceServer) Watch(*WatchRequest, ResourceService_WatchServer) error {
|
|
||||||
return status.Errorf(codes.Unimplemented, "method Watch not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedResourceServiceServer) mustEmbedUnimplementedResourceServiceServer() {}
|
|
||||||
|
|
||||||
// UnsafeResourceServiceServer may be embedded to opt out of forward compatibility for this service.
|
|
||||||
// Use of this interface is not recommended, as added methods to ResourceServiceServer will
|
|
||||||
// result in compilation errors.
|
|
||||||
type UnsafeResourceServiceServer interface {
|
|
||||||
mustEmbedUnimplementedResourceServiceServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func RegisterResourceServiceServer(s grpc.ServiceRegistrar, srv ResourceServiceServer) {
|
|
||||||
s.RegisterService(&ResourceService_ServiceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ResourceService_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(GetRequest)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(ResourceServiceServer).Get(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: ResourceService_Get_FullMethodName,
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(ResourceServiceServer).Get(ctx, req.(*GetRequest))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ResourceService_List_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(ListRequest)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(ResourceServiceServer).List(m, &resourceServiceListServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceService_ListServer interface {
|
|
||||||
Send(*ListResponse) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceServiceListServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *resourceServiceListServer) Send(m *ListResponse) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _ResourceService_Watch_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
||||||
m := new(WatchRequest)
|
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return srv.(ResourceServiceServer).Watch(m, &resourceServiceWatchServer{stream})
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceService_WatchServer interface {
|
|
||||||
Send(*WatchResponse) error
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
type resourceServiceWatchServer struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *resourceServiceWatchServer) Send(m *WatchResponse) error {
|
|
||||||
return x.ServerStream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceService_ServiceDesc is the grpc.ServiceDesc for ResourceService service.
|
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
|
||||||
// and not to be introspected or modified (even as a copy)
|
|
||||||
var ResourceService_ServiceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "resource.ResourceService",
|
|
||||||
HandlerType: (*ResourceServiceServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Get",
|
|
||||||
Handler: _ResourceService_Get_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{
|
|
||||||
{
|
|
||||||
StreamName: "List",
|
|
||||||
Handler: _ResourceService_List_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
StreamName: "Watch",
|
|
||||||
Handler: _ResourceService_Watch_Handler,
|
|
||||||
ServerStreams: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Metadata: "resource/resource.proto",
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
||||||
inspectapi "github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
inspectapi "github.com/siderolabs/talos/pkg/machinery/api/inspect"
|
||||||
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
|
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
|
||||||
resourceapi "github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
storageapi "github.com/siderolabs/talos/pkg/machinery/api/storage"
|
storageapi "github.com/siderolabs/talos/pkg/machinery/api/storage"
|
||||||
timeapi "github.com/siderolabs/talos/pkg/machinery/api/time"
|
timeapi "github.com/siderolabs/talos/pkg/machinery/api/time"
|
||||||
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
|
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
|
||||||
@ -46,10 +45,6 @@ type Client struct {
|
|||||||
StorageClient storageapi.StorageServiceClient
|
StorageClient storageapi.StorageServiceClient
|
||||||
InspectClient inspectapi.InspectServiceClient
|
InspectClient inspectapi.InspectServiceClient
|
||||||
|
|
||||||
// Deprecated: use COSI client.
|
|
||||||
Resources *ResourcesClient
|
|
||||||
ResourceClient resourceapi.ResourceServiceClient //nolint:staticcheck
|
|
||||||
|
|
||||||
COSI state.State
|
COSI state.State
|
||||||
|
|
||||||
Inspect *InspectClient
|
Inspect *InspectClient
|
||||||
@ -169,10 +164,8 @@ func New(ctx context.Context, opts ...OptionFunc) (c *Client, err error) {
|
|||||||
c.TimeClient = timeapi.NewTimeServiceClient(c.conn)
|
c.TimeClient = timeapi.NewTimeServiceClient(c.conn)
|
||||||
c.ClusterClient = clusterapi.NewClusterServiceClient(c.conn)
|
c.ClusterClient = clusterapi.NewClusterServiceClient(c.conn)
|
||||||
c.StorageClient = storageapi.NewStorageServiceClient(c.conn)
|
c.StorageClient = storageapi.NewStorageServiceClient(c.conn)
|
||||||
c.ResourceClient = resourceapi.NewResourceServiceClient(c.conn) //nolint:staticcheck
|
|
||||||
c.InspectClient = inspectapi.NewInspectServiceClient(c.conn)
|
c.InspectClient = inspectapi.NewInspectServiceClient(c.conn)
|
||||||
|
|
||||||
c.Resources = &ResourcesClient{c.ResourceClient}
|
|
||||||
c.Inspect = &InspectClient{c.InspectClient}
|
c.Inspect = &InspectClient{c.InspectClient}
|
||||||
c.COSI = state.WrapCore(client.NewAdapter(cosiv1alpha1.NewStateClient(c.conn)))
|
c.COSI = state.WrapCore(client.NewAdapter(cosiv1alpha1.NewStateClient(c.conn)))
|
||||||
|
|
||||||
|
@ -1,206 +0,0 @@
|
|||||||
// 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 client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/cosi-project/runtime/pkg/resource"
|
|
||||||
"github.com/cosi-project/runtime/pkg/state"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
|
|
||||||
"github.com/siderolabs/talos/pkg/machinery/api/common"
|
|
||||||
resourceapi "github.com/siderolabs/talos/pkg/machinery/api/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResourcesClient provides access to resource API.
|
|
||||||
//
|
|
||||||
// Deprecated: use COSI client.
|
|
||||||
type ResourcesClient struct {
|
|
||||||
client resourceapi.ResourceServiceClient //nolint:staticcheck
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceResponse is a parsed resource response.
|
|
||||||
type ResourceResponse struct {
|
|
||||||
Metadata *common.Metadata
|
|
||||||
Definition resource.Resource
|
|
||||||
Resource resource.Resource
|
|
||||||
}
|
|
||||||
|
|
||||||
// WatchResponse is a parsed resource watch response.
|
|
||||||
type WatchResponse struct {
|
|
||||||
ResourceResponse
|
|
||||||
EventType state.EventType
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a specified resource.
|
|
||||||
func (c *ResourcesClient) Get(ctx context.Context, resourceNamespace, resourceType, resourceID string, callOptions ...grpc.CallOption) ([]ResourceResponse, error) {
|
|
||||||
resp, err := c.client.Get(ctx, &resourceapi.GetRequest{
|
|
||||||
Namespace: resourceNamespace,
|
|
||||||
Type: resourceType,
|
|
||||||
Id: resourceID,
|
|
||||||
}, callOptions...)
|
|
||||||
|
|
||||||
var filtered interface{}
|
|
||||||
filtered, err = FilterMessages(resp, err)
|
|
||||||
resp, _ = filtered.(*resourceapi.GetResponse) //nolint:errcheck
|
|
||||||
|
|
||||||
if resp == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
items := make([]ResourceResponse, 0, len(resp.GetMessages()))
|
|
||||||
|
|
||||||
for _, msg := range resp.GetMessages() {
|
|
||||||
var resourceResp ResourceResponse
|
|
||||||
|
|
||||||
resourceResp.Metadata = msg.GetMetadata()
|
|
||||||
|
|
||||||
if msg.GetDefinition() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
resourceResp.Definition, e = resource.NewAnyFromProto(msg.GetDefinition().GetMetadata(), msg.GetDefinition().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return nil, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetResource() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
resourceResp.Resource, e = resource.NewAnyFromProto(msg.GetResource().GetMetadata(), msg.GetResource().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return nil, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items = append(items, resourceResp)
|
|
||||||
}
|
|
||||||
|
|
||||||
return items, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceListClient wraps gRPC list client.
|
|
||||||
type ResourceListClient struct {
|
|
||||||
grpcClient resourceapi.ResourceService_ListClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recv next item from the list.
|
|
||||||
func (client *ResourceListClient) Recv() (ResourceResponse, error) {
|
|
||||||
var resourceResp ResourceResponse
|
|
||||||
|
|
||||||
msg, err := client.grpcClient.Recv()
|
|
||||||
if err != nil {
|
|
||||||
return resourceResp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resourceResp.Metadata = msg.GetMetadata()
|
|
||||||
|
|
||||||
if msg.GetDefinition() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
resourceResp.Definition, e = resource.NewAnyFromProto(msg.GetDefinition().GetMetadata(), msg.GetDefinition().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return resourceResp, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetResource() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
resourceResp.Resource, e = resource.NewAnyFromProto(msg.GetResource().GetMetadata(), msg.GetResource().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return resourceResp, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resourceResp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// List resources by kind.
|
|
||||||
func (c *ResourcesClient) List(ctx context.Context, resourceNamespace, resourceType string, callOptions ...grpc.CallOption) (*ResourceListClient, error) {
|
|
||||||
client, err := c.client.List(ctx, &resourceapi.ListRequest{
|
|
||||||
Namespace: resourceNamespace,
|
|
||||||
Type: resourceType,
|
|
||||||
}, callOptions...)
|
|
||||||
|
|
||||||
return &ResourceListClient{
|
|
||||||
grpcClient: client,
|
|
||||||
}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResourceWatchClient wraps gRPC watch client.
|
|
||||||
type ResourceWatchClient struct {
|
|
||||||
grpcClient resourceapi.ResourceService_WatchClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recv next item from the list.
|
|
||||||
//
|
|
||||||
//nolint:gocyclo
|
|
||||||
func (client *ResourceWatchClient) Recv() (WatchResponse, error) {
|
|
||||||
var watchResp WatchResponse
|
|
||||||
|
|
||||||
msg, err := client.grpcClient.Recv()
|
|
||||||
if err != nil {
|
|
||||||
return watchResp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetMetadata().GetError() != "" {
|
|
||||||
if msg.GetMetadata().Status != nil {
|
|
||||||
return watchResp, status.ErrorProto(msg.GetMetadata().GetStatus())
|
|
||||||
}
|
|
||||||
|
|
||||||
return watchResp, errors.New(msg.GetMetadata().GetError())
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetDefinition() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
watchResp.Definition, e = resource.NewAnyFromProto(msg.GetDefinition().GetMetadata(), msg.GetDefinition().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return watchResp, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetResource() != nil {
|
|
||||||
var e error
|
|
||||||
|
|
||||||
watchResp.Resource, e = resource.NewAnyFromProto(msg.GetResource().GetMetadata(), msg.GetResource().GetSpec())
|
|
||||||
if e != nil {
|
|
||||||
return watchResp, e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch msg.GetEventType() {
|
|
||||||
case resourceapi.EventType_CREATED:
|
|
||||||
watchResp.EventType = state.Created
|
|
||||||
case resourceapi.EventType_UPDATED:
|
|
||||||
watchResp.EventType = state.Updated
|
|
||||||
case resourceapi.EventType_DESTROYED:
|
|
||||||
watchResp.EventType = state.Destroyed
|
|
||||||
}
|
|
||||||
|
|
||||||
return watchResp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch resources by kind or by kind and ID.
|
|
||||||
func (c *ResourcesClient) Watch(ctx context.Context, resourceNamespace, resourceType, resourceID string, callOptions ...grpc.CallOption) (*ResourceWatchClient, error) {
|
|
||||||
return c.WatchRequest(ctx, &resourceapi.WatchRequest{
|
|
||||||
Namespace: resourceNamespace,
|
|
||||||
Type: resourceType,
|
|
||||||
Id: resourceID,
|
|
||||||
}, callOptions...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WatchRequest resources by watch request.
|
|
||||||
func (c *ResourcesClient) WatchRequest(ctx context.Context, request *resourceapi.WatchRequest, callOptions ...grpc.CallOption) (*ResourceWatchClient, error) {
|
|
||||||
client, err := c.client.Watch(ctx, request, callOptions...)
|
|
||||||
|
|
||||||
return &ResourceWatchClient{
|
|
||||||
grpcClient: client,
|
|
||||||
}, err
|
|
||||||
}
|
|
@ -395,24 +395,6 @@ description: Talos gRPC API reference.
|
|||||||
|
|
||||||
- [MachineService](#machine.MachineService)
|
- [MachineService](#machine.MachineService)
|
||||||
|
|
||||||
- [resource/resource.proto](#resource/resource.proto)
|
|
||||||
- [Get](#resource.Get)
|
|
||||||
- [GetRequest](#resource.GetRequest)
|
|
||||||
- [GetResponse](#resource.GetResponse)
|
|
||||||
- [ListRequest](#resource.ListRequest)
|
|
||||||
- [ListResponse](#resource.ListResponse)
|
|
||||||
- [Metadata](#resource.Metadata)
|
|
||||||
- [Metadata.AnnotationsEntry](#resource.Metadata.AnnotationsEntry)
|
|
||||||
- [Metadata.LabelsEntry](#resource.Metadata.LabelsEntry)
|
|
||||||
- [Resource](#resource.Resource)
|
|
||||||
- [Spec](#resource.Spec)
|
|
||||||
- [WatchRequest](#resource.WatchRequest)
|
|
||||||
- [WatchResponse](#resource.WatchResponse)
|
|
||||||
|
|
||||||
- [EventType](#resource.EventType)
|
|
||||||
|
|
||||||
- [ResourceService](#resource.ResourceService)
|
|
||||||
|
|
||||||
- [security/security.proto](#security/security.proto)
|
- [security/security.proto](#security/security.proto)
|
||||||
- [CertificateRequest](#securityapi.CertificateRequest)
|
- [CertificateRequest](#securityapi.CertificateRequest)
|
||||||
- [CertificateResponse](#securityapi.CertificateResponse)
|
- [CertificateResponse](#securityapi.CertificateResponse)
|
||||||
@ -6821,257 +6803,6 @@ This method is available only on control plane nodes (which run etcd). |
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource/resource.proto"></a>
|
|
||||||
<p align="right"><a href="#top">Top</a></p>
|
|
||||||
|
|
||||||
## resource/resource.proto
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Get"></a>
|
|
||||||
|
|
||||||
### Get
|
|
||||||
The GetResponse message contains the Resource returned.
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| metadata | [common.Metadata](#common.Metadata) | | |
|
|
||||||
| definition | [Resource](#resource.Resource) | | |
|
|
||||||
| resource | [Resource](#resource.Resource) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.GetRequest"></a>
|
|
||||||
|
|
||||||
### GetRequest
|
|
||||||
rpc Get
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| namespace | [string](#string) | | |
|
|
||||||
| type | [string](#string) | | |
|
|
||||||
| id | [string](#string) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.GetResponse"></a>
|
|
||||||
|
|
||||||
### GetResponse
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| messages | [Get](#resource.Get) | repeated | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.ListRequest"></a>
|
|
||||||
|
|
||||||
### ListRequest
|
|
||||||
rpc List
|
|
||||||
The ListResponse message contains the Resource returned.
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| namespace | [string](#string) | | |
|
|
||||||
| type | [string](#string) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.ListResponse"></a>
|
|
||||||
|
|
||||||
### ListResponse
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| metadata | [common.Metadata](#common.Metadata) | | |
|
|
||||||
| definition | [Resource](#resource.Resource) | | |
|
|
||||||
| resource | [Resource](#resource.Resource) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Metadata"></a>
|
|
||||||
|
|
||||||
### Metadata
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| namespace | [string](#string) | | |
|
|
||||||
| type | [string](#string) | | |
|
|
||||||
| id | [string](#string) | | |
|
|
||||||
| version | [string](#string) | | |
|
|
||||||
| owner | [string](#string) | | |
|
|
||||||
| phase | [string](#string) | | |
|
|
||||||
| created | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
|
|
||||||
| updated | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
|
|
||||||
| finalizers | [string](#string) | repeated | |
|
|
||||||
| labels | [Metadata.LabelsEntry](#resource.Metadata.LabelsEntry) | repeated | |
|
|
||||||
| annotations | [Metadata.AnnotationsEntry](#resource.Metadata.AnnotationsEntry) | repeated | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Metadata.AnnotationsEntry"></a>
|
|
||||||
|
|
||||||
### Metadata.AnnotationsEntry
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| key | [string](#string) | | |
|
|
||||||
| value | [string](#string) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Metadata.LabelsEntry"></a>
|
|
||||||
|
|
||||||
### Metadata.LabelsEntry
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| key | [string](#string) | | |
|
|
||||||
| value | [string](#string) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Resource"></a>
|
|
||||||
|
|
||||||
### Resource
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| metadata | [Metadata](#resource.Metadata) | | |
|
|
||||||
| spec | [Spec](#resource.Spec) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.Spec"></a>
|
|
||||||
|
|
||||||
### Spec
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| yaml | [bytes](#bytes) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.WatchRequest"></a>
|
|
||||||
|
|
||||||
### WatchRequest
|
|
||||||
rpc Watch
|
|
||||||
The WatchResponse message contains the Resource returned.
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| namespace | [string](#string) | | |
|
|
||||||
| type | [string](#string) | | |
|
|
||||||
| id | [string](#string) | | |
|
|
||||||
| tail_events | [uint32](#uint32) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.WatchResponse"></a>
|
|
||||||
|
|
||||||
### WatchResponse
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Field | Type | Label | Description |
|
|
||||||
| ----- | ---- | ----- | ----------- |
|
|
||||||
| metadata | [common.Metadata](#common.Metadata) | | |
|
|
||||||
| event_type | [EventType](#resource.EventType) | | |
|
|
||||||
| definition | [Resource](#resource.Resource) | | |
|
|
||||||
| resource | [Resource](#resource.Resource) | | |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- end messages -->
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.EventType"></a>
|
|
||||||
|
|
||||||
### EventType
|
|
||||||
|
|
||||||
|
|
||||||
| Name | Number | Description |
|
|
||||||
| ---- | ------ | ----------- |
|
|
||||||
| CREATED | 0 | |
|
|
||||||
| UPDATED | 1 | |
|
|
||||||
| DESTROYED | 2 | |
|
|
||||||
|
|
||||||
|
|
||||||
<!-- end enums -->
|
|
||||||
|
|
||||||
<!-- end HasExtensions -->
|
|
||||||
|
|
||||||
|
|
||||||
<a name="resource.ResourceService"></a>
|
|
||||||
|
|
||||||
### ResourceService
|
|
||||||
The resource service definition.
|
|
||||||
|
|
||||||
ResourceService provides user-facing API for the Talos resources.
|
|
||||||
|
|
||||||
| Method Name | Request Type | Response Type | Description |
|
|
||||||
| ----------- | ------------ | ------------- | ------------|
|
|
||||||
| Get | [GetRequest](#resource.GetRequest) | [GetResponse](#resource.GetResponse) | |
|
|
||||||
| List | [ListRequest](#resource.ListRequest) | [ListResponse](#resource.ListResponse) stream | |
|
|
||||||
| Watch | [WatchRequest](#resource.WatchRequest) | [WatchResponse](#resource.WatchResponse) stream | |
|
|
||||||
|
|
||||||
<!-- end services -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="security/security.proto"></a>
|
<a name="security/security.proto"></a>
|
||||||
<p align="right"><a href="#top">Top</a></p>
|
<p align="right"><a href="#top">Top</a></p>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user