Files
teleport/integrations/operator/controllers/resources/inference_model_controller.go
T
rosstimothy 4f17314a11 Initial migration to the Opaque API (#67279)
* 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.
2026-06-05 14:52:58 +00:00

98 lines
3.3 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"
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"
)
// inferenceModelClient implements [reconcilers.resourceClient] and offers CRUD
// methods needed to reconcile InferenceModel
type inferenceModelClient struct {
teleportClient *client.Client
}
// Get gets an inference model with a given name from Teleport.
func (c inferenceModelClient) Get(
ctx context.Context, name string,
) (*summarizerv1.InferenceModel, error) {
resp, err := c.teleportClient.SummarizerServiceClient().GetInferenceModel(
ctx, summarizerv1.GetInferenceModelRequest_builder{Name: name}.Build(),
)
if err != nil {
return nil, trace.Wrap(err)
}
return resp.GetModel(), nil
}
// Create creates an inference model in Teleport.
func (c inferenceModelClient) Create(
ctx context.Context, model *summarizerv1.InferenceModel,
) error {
_, err := c.teleportClient.SummarizerServiceClient().CreateInferenceModel(
ctx, summarizerv1.CreateInferenceModelRequest_builder{Model: model}.Build(),
)
return trace.Wrap(err)
}
// Update updates an existing inference model in Teleport.
func (c inferenceModelClient) Update(
ctx context.Context, model *summarizerv1.InferenceModel,
) error {
_, err := c.teleportClient.SummarizerServiceClient().UpdateInferenceModel(
ctx, summarizerv1.UpdateInferenceModelRequest_builder{Model: model}.Build(),
)
return trace.Wrap(err)
}
// Delete deletes an inference model with a given name from Teleport.
func (c inferenceModelClient) Delete(ctx context.Context, name string) error {
_, err := c.teleportClient.SummarizerServiceClient().DeleteInferenceModel(
ctx, summarizerv1.DeleteInferenceModelRequest_builder{Name: name}.Build(),
)
return trace.Wrap(err)
}
// NewInferenceModelReconciler creates a new Kubernetes controller reconciling
// inference_model resources.
func NewInferenceModelReconciler(
client kclient.Client, tClient *client.Client,
) (controllers.Reconciler, error) {
inferenceModelClient := &inferenceModelClient{
teleportClient: tClient,
}
resourceReconciler, err := reconcilers.NewTeleportResource153Reconciler[
*summarizerv1.InferenceModel, *resourcesv1.TeleportInferenceModel,
](
client,
inferenceModelClient,
)
return resourceReconciler, trace.Wrap(err)
}