Skip to content

docs: add COSI resource operations in API usage examples#2808

Open
utkuozdemir wants to merge 1 commit intosiderolabs:mainfrom
utkuozdemir:chore/update-client-example
Open

docs: add COSI resource operations in API usage examples#2808
utkuozdemir wants to merge 1 commit intosiderolabs:mainfrom
utkuozdemir:chore/update-client-example

Conversation

@utkuozdemir
Copy link
Copy Markdown
Member

Show how COSI resources should be created, updated and destroyed.

Closes #2804.

Show how COSI resources should be created, updated and destroyed.

Closes siderolabs#2804.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
st := c.Omni().State()

// List all machine statuses.
machines, err := safe.StateList[*omni.MachineStatus](ctx, st, omni.NewMachineStatus("").Metadata())
Copy link
Copy Markdown
Member

@Unix4ever Unix4ever May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we touch this code we can update it with newer versions of the method:

Suggested change
machines, err := safe.StateList[*omni.MachineStatus](ctx, st, omni.NewMachineStatus("").Metadata())
machines, err := safe.ReaderListAll[*omni.MachineStatus](ctx, st)

@github-project-automation github-project-automation Bot moved this from In Review to Approved in Planning May 7, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Go client usage example to better document how Omni uses COSI for resource management, and adds an end-to-end example of creating, updating, and destroying a user-managed COSI resource (MachineClass).

Changes:

  • Improves wording/structure of the existing Omni/Talos API usage example.
  • Adds a COSI state resource lifecycle example (create/update/teardown+destroy) using MachineClass.
  • Minor naming cleanups (clientc, templatetmpl) for readability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to 46
// Create a new client.
c, err := client.New("https://<account>.omni.siderolabs.io:443", client.WithServiceAccount(
"base64encodedkey", // From the generated service account.
))
// Talking to Omni specific APIs: getting talosconfig.
_, err = client.Management().Talosconfig(ctx)
// Get the talosconfig for the cluster.
_, err = c.Management().Talosconfig(ctx)
machineClass.Metadata().Labels().Set("my-label", "my-value")

machineClass.TypedSpec().Value.MatchLabels = []string{
"omni.sidero.dev/arch = amd64, omni.sidero.dev/cpus > 2", // amd64 machines with more than 2 CPUs
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 51 to 54
defer func() {
if e := client.Close(); e != nil {
if e := c.Close(); e != nil {
log.Printf("failed to close client %s", e)
}
Comment on lines +146 to +148
if err = st.Create(ctx, machineClass); err != nil {
log.Panicf("failed to create machine class %s", err)
}
Comment on lines +156 to +158
if err != nil {
log.Panicf("failed to update machine class %s", err)
}
Comment on lines +170 to +172
if err = st.TeardownAndDestroy(ctx, machineClass.Metadata()); err != nil {
log.Panicf("failed to destroy machine class %s", err)
}

// Setup versions information. You can embed that into `go build` too.
// Setup version information. You can embed this into the binary via `go build -ldflags`.
version.Name = "omni"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we generate version via abbrev_tag?

Copy link
Copy Markdown
Member

@smira smira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably add some Watch example (or WatchKind)? with proper context cancelation, etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

Update Omni API example to include resource operations

5 participants