docs: add COSI resource operations in API usage examples#2808
docs: add COSI resource operations in API usage examples#2808utkuozdemir wants to merge 1 commit intosiderolabs:mainfrom
Conversation
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()) |
There was a problem hiding this comment.
As we touch this code we can update it with newer versions of the method:
| machines, err := safe.StateList[*omni.MachineStatus](ctx, st, omni.NewMachineStatus("").Metadata()) | |
| machines, err := safe.ReaderListAll[*omni.MachineStatus](ctx, st) |
There was a problem hiding this comment.
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 (
client→c,template→tmpl) for readability.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 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 |
There was a problem hiding this comment.
good one. this means probably the label in https://github.com/siderolabs/docs/blob/main/public/omni/omni-cluster-setup/create-a-machine-class.mdx is also incorrect.
| defer func() { | ||
| if e := client.Close(); e != nil { | ||
| if e := c.Close(); e != nil { | ||
| log.Printf("failed to close client %s", e) | ||
| } |
| if err = st.Create(ctx, machineClass); err != nil { | ||
| log.Panicf("failed to create machine class %s", err) | ||
| } |
| if err != nil { | ||
| log.Panicf("failed to update machine class %s", err) | ||
| } |
| 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" |
There was a problem hiding this comment.
don't we generate version via abbrev_tag?
smira
left a comment
There was a problem hiding this comment.
I would probably add some Watch example (or WatchKind)? with proper context cancelation, etc.?
Show how COSI resources should be created, updated and destroyed.
Closes #2804.