Documentation ¶
Overview ¶
Package client provides Omni API client.
Package client provides Omni API client.
Example ¶
package main import ( "context" "log" "github.com/cosi-project/runtime/pkg/safe" "google.golang.org/protobuf/types/known/emptypb" "github.com/siderolabs/omni-client/pkg/client" "github.com/siderolabs/omni-client/pkg/omni/resources" "github.com/siderolabs/omni-client/pkg/omni/resources/omni" "github.com/siderolabs/omni-client/pkg/template" "github.com/siderolabs/omni-client/pkg/version" ) func main() { // This example shows how to use Omni client to access resources. // Setup versions information. You can embed that into `go build` too. version.Name = "omni" version.SHA = "build SHA" version.Tag = "v0.9.1" // For this example we will use Omni service account. // You can create your service account in advance: // // omnictl serviceaccount create example.account // Created service account "example.account" with public key ID "<REDACTED>" // // Set the following environment variables to use the service account: // OMNI_ENDPOINT=https://<account>.omni.siderolabs.io:443 // OMNI_SERVICE_ACCOUNT_KEY=base64encodedkey // // Note: Store the service account key securely, it will not be displayed again ctx := context.Background() // Creating a new client. client, err := client.New(ctx, "https://<account>.omni.siderolabs.io:443", client.WithServiceAccount( "automation", // This is context name, same as Talos or Kubernetes context, it can be named any way, but should be unique for each account // as Omni client stores generated keys there. "base64encodedkey", // From the generated service account. )) if err != nil { log.Fatalf("failed to create omni client %s", err) } // Omni service is using COSI https://github.com/cosi-project/runtime/. // The same client is used to get resources in Talos. st := client.Omni().State() // Getting the resources from the Omni state. machines, err := safe.StateList[*omni.MachineStatus](ctx, st, omni.NewMachineStatus(resources.DefaultNamespace, "").Metadata()) if err != nil { log.Fatalf("failed to get machines %s", err) } var ( cluster string machine *omni.MachineStatus ) for iter := safe.IteratorFromList(machines); iter.Next(); { item := iter.Value() log.Printf("machine %s, connected: %t", item.Metadata(), item.TypedSpec().Value.GetConnected()) // Check cluster assignment for a machine. // Find a machine which is allocated into a cluster for the later use. if c, ok := item.Metadata().Labels().Get(omni.LabelCluster); ok && machine == nil { cluster = c machine = item } } // Creating an empty cluster via template. // Alternative is to use template.Load to load a cluster template. template := template.WithCluster("example.cluster") if _, err = template.Sync(ctx, st); err != nil { log.Fatalf("failed to sync cluster %s", err) } log.Printf("sync cluster") // Delete cluster. if _, err = template.Delete(ctx, st); err != nil { log.Fatalf("failed to delete the cluster %s", err) } log.Printf("destroyed cluster") // No machines found, exit. if machine == nil { log.Printf("no allocated machines found, exit") return } // Using Talos through Omni. // Use cluster and machine which we previously found. cpuInfo, err := client.Talos().WithCluster( cluster, ).WithNodes( machine.Metadata().ID(), // You can use machine UUID as Omni will properly resolve it into machine IP. ).CPUInfo(ctx, &emptypb.Empty{}) if err != nil { log.Fatalf("failed to read machine CPU info %s", err) } for _, message := range cpuInfo.Messages { for i, info := range message.CpuInfo { log.Printf("machine %s, CPU %d family %s", machine.Metadata(), i, info.CpuFamily) } if len(message.CpuInfo) == 0 { log.Printf("no CPU info for machine %s", machine.Metadata()) } } // Talking to Omni specific APIs: getting talosconfig. _, err = client.Management().Talosconfig(ctx) if err != nil { log.Fatalf("failed to get talosconfig %s", err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth adds basic auth for each gRPC request.
func (BasicAuth) GetRequestMetadata ¶
GetRequestMetadata implements credentials.PerGRPCCredentials.
func (BasicAuth) RequireTransportSecurity ¶
RequireTransportSecurity implements credentials.PerRPCCredentials.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is Omni API client.
func (*Client) Management ¶
func (c *Client) Management() *management.Client
Management provides access to the management API.
type Option ¶
type Option func() ([]grpc.DialOption, error)
Option is the function that generates gRPC dial options.
func WithBasicAuth ¶
WithBasicAuth creates the client with basic auth.
func WithGrpcOpts ¶
func WithGrpcOpts(opts ...grpc.DialOption) Option
WithGrpcOpts creates the client with basic auth.
func WithServiceAccount ¶
WithServiceAccount creates the client for a context with the given service account key.
func WithUserAccount ¶
WithUserAccount used for accessing Omni by a human.
Directories ¶
Path | Synopsis |
---|---|
Package management provides client for Omni management API.
|
Package management provides client for Omni management API. |
Package oidc provides client for Omni OIDC API.
|
Package oidc provides client for Omni OIDC API. |
Package omni provides client for Omni resource access.
|
Package omni provides client for Omni resource access. |
Package talos provides helpers for accessing Talos Machine API.
|
Package talos provides helpers for accessing Talos Machine API. |