mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
* Convert existing non-gogo codegen to the Hybrid API Contributes to https://github.com/gravitational/teleport/issues/66776. All existing protos explicitly set to API_OPEN have been change to API_HBYRID. The new codegen was performed via make grpc. There are no other functional changes to the code to start consuming the Hybrid API those will come later. The intent is to get all Hybrid codegen in and backported to ease the transition. * Initial migration to the Opaque API Contributes to https://github.com/gravitational/teleport/issues/66776. All of the changes here are mechanical conversions generated from `open2opaque rewrite -levels=green ./...`. There will be a follow up to this in teleport.e which does the same. Once all changes have been merged the process will be repeated with -levels=yellow followed by -levels=red. See https://protobuf.dev/reference/go/opaque-migration/ for more details.
100 lines
4.0 KiB
Go
100 lines
4.0 KiB
Go
/*
|
|
* Teleport
|
|
* Copyright (C) 2026 Gravitational, Inc.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package resources
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gravitational/trace"
|
|
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"github.com/gravitational/teleport/api/client"
|
|
summarizerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/summarizer/v1"
|
|
"github.com/gravitational/teleport/api/types"
|
|
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
|
"github.com/gravitational/teleport/integrations/operator/controllers"
|
|
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
|
)
|
|
|
|
// retrievalModelClient implements TeleportResourceClient and offers CRUD methods needed to reconcile RetrievalModel.
|
|
type retrievalModelClient struct {
|
|
teleportClient *client.Client
|
|
}
|
|
|
|
// Get gets the Teleport RetrievalModel singleton. The name parameter is ignored.
|
|
func (r retrievalModelClient) Get(ctx context.Context, _ string) (*summarizerv1.RetrievalModel, error) {
|
|
resp, err := r.teleportClient.SummarizerServiceClient().
|
|
GetRetrievalModel(ctx, &summarizerv1.GetRetrievalModelRequest{})
|
|
if err != nil {
|
|
return nil, trace.Wrap(err)
|
|
}
|
|
return resp.GetModel(), nil
|
|
}
|
|
|
|
// Create creates the Teleport RetrievalModel singleton.
|
|
func (r retrievalModelClient) Create(ctx context.Context, resource *summarizerv1.RetrievalModel) error {
|
|
_, err := r.teleportClient.SummarizerServiceClient().
|
|
CreateRetrievalModel(ctx, summarizerv1.CreateRetrievalModelRequest_builder{Model: resource}.Build())
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
// Update upserts the Teleport RetrievalModel singleton.
|
|
func (r retrievalModelClient) Update(ctx context.Context, resource *summarizerv1.RetrievalModel) error {
|
|
_, err := r.teleportClient.SummarizerServiceClient().
|
|
UpsertRetrievalModel(ctx, summarizerv1.UpsertRetrievalModelRequest_builder{Model: resource}.Build())
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
// Delete deletes the Teleport RetrievalModel singleton. The name parameter is ignored.
|
|
func (r retrievalModelClient) Delete(ctx context.Context, _ string) error {
|
|
_, err := r.teleportClient.SummarizerServiceClient().
|
|
DeleteRetrievalModel(ctx, &summarizerv1.DeleteRetrievalModelRequest{})
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
// Mutate validates that the Kubernetes CR is named with the singleton name before
|
|
// creating or updating. RetrievalModel can only exist under types.MetaNameRetrievalModel
|
|
// in Teleport; a differently-named CR would silently map to the same singleton, so we
|
|
// reject it early with a clear status condition instead.
|
|
func (r retrievalModelClient) Mutate(_ context.Context, _, _ *summarizerv1.RetrievalModel, crKey kclient.ObjectKey) error {
|
|
if crKey.Name != types.MetaNameRetrievalModel {
|
|
return trace.BadParameter(
|
|
"TeleportRetrievalModelV1 must be named %q, got %q; delete and recreate the resource with the correct name",
|
|
types.MetaNameRetrievalModel, crKey.Name,
|
|
)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NewRetrievalModelV1Reconciler instantiates a new Kubernetes controller reconciling RetrievalModel resources.
|
|
func NewRetrievalModelV1Reconciler(client kclient.Client, tClient *client.Client) (controllers.Reconciler, error) {
|
|
rmClient := &retrievalModelClient{
|
|
teleportClient: tClient,
|
|
}
|
|
|
|
resourceReconciler, err := reconcilers.NewTeleportResource153Reconciler[
|
|
*summarizerv1.RetrievalModel, *resourcesv1.TeleportRetrievalModelV1,
|
|
](
|
|
client,
|
|
rmClient,
|
|
)
|
|
|
|
return resourceReconciler, trace.Wrap(err, "building teleport resource reconciler")
|
|
}
|