@@ -11,6 +11,7 @@ import (
1111 "net/netip"
1212 "os"
1313 "slices"
14+ "strconv"
1415 "strings"
1516
1617 "github.com/google/uuid"
@@ -23,8 +24,10 @@ import (
2324 "github.com/siderolabs/talos/pkg/machinery/config"
2425 "github.com/siderolabs/talos/pkg/machinery/config/bundle"
2526 "github.com/siderolabs/talos/pkg/machinery/config/configpatcher"
27+ "github.com/siderolabs/talos/pkg/machinery/config/container"
2628 "github.com/siderolabs/talos/pkg/machinery/config/generate"
2729 "github.com/siderolabs/talos/pkg/machinery/config/machine"
30+ "github.com/siderolabs/talos/pkg/machinery/config/types/siderolink"
2831 "github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1"
2932 "github.com/siderolabs/talos/pkg/machinery/constants"
3033 "github.com/siderolabs/talos/pkg/provision"
@@ -67,6 +70,7 @@ type Maker[ExtraOps any] struct {
6770 Cidrs []netip.Prefix
6871 InClusterEndpoint string
6972 Endpoints []string
73+ WithOmni bool
7074
7175 ProvisionOps []provision.Option
7276 GenOps []generate.Option
@@ -101,15 +105,18 @@ func (m *Maker[T]) InitExtra() error {
101105 return err
102106 }
103107
104- if err := m .extraOptionsProvider .AddExtraGenOps (); err != nil {
105- return err
106- }
108+ // skip generating machine config if nodes are to be used with omni
109+ if ! m .WithOmni {
110+ if err := m .extraOptionsProvider .AddExtraGenOps (); err != nil {
111+ return err
112+ }
107113
108- if err := m .extraOptionsProvider .AddExtraProvisionOpts (); err != nil {
109- return err
114+ if err := m .extraOptionsProvider .AddExtraConfigBundleOpts (); err != nil {
115+ return err
116+ }
110117 }
111118
112- if err := m .extraOptionsProvider .AddExtraConfigBundleOpts (); err != nil {
119+ if err := m .extraOptionsProvider .AddExtraProvisionOpts (); err != nil {
113120 return err
114121 }
115122
@@ -125,7 +132,13 @@ func (m *Maker[T]) InitExtra() error {
125132}
126133
127134// InitCommon initializes the common fields.
135+ //
136+ //nolint:gocyclo
128137func (m * Maker [T ]) InitCommon () error {
138+ if m .Ops .OmniAPIEndpoint != "" {
139+ m .WithOmni = true
140+ }
141+
129142 if err := m .initVersionContract (); err != nil {
130143 return err
131144 }
@@ -152,15 +165,18 @@ func (m *Maker[T]) InitCommon() error {
152165 return err
153166 }
154167
155- if err := m .initGenOps (); err != nil {
156- return err
157- }
168+ // skip generating machine config if nodes are to be used with omni
169+ if ! m .WithOmni {
170+ if err := m .initGenOps (); err != nil {
171+ return err
172+ }
158173
159- if err := m .initProvisionOps (); err != nil {
160- return err
174+ if err := m .initConfigBundleOps (); err != nil {
175+ return err
176+ }
161177 }
162178
163- if err := m .initConfigBundleOps (); err != nil {
179+ if err := m .initProvisionOps (); err != nil {
164180 return err
165181 }
166182
@@ -210,6 +226,53 @@ func (m *Maker[T]) initVersionContract() error {
210226// GetClusterConfigs prepares and returns the cluster create request data. This method is ment to be called after the implemeting maker
211227// logic has been run.
212228func (m * Maker [T ]) GetClusterConfigs () (clusterops.ClusterConfigs , error ) {
229+ var configBundle * bundle.Bundle
230+
231+ if ! m .WithOmni {
232+ cfgBundle , err := m .finalizeMachineConfigs ()
233+ if err != nil {
234+ return clusterops.ClusterConfigs {}, err
235+ }
236+
237+ configBundle = cfgBundle
238+ } else {
239+ err := m .applyOmniConfigs ()
240+ if err != nil {
241+ return clusterops.ClusterConfigs {}, err
242+ }
243+ }
244+
245+ return clusterops.ClusterConfigs {
246+ ClusterRequest : m .ClusterRequest ,
247+ ProvisionOptions : m .ProvisionOps ,
248+ ConfigBundle : configBundle ,
249+ }, nil
250+ }
251+
252+ func (m * Maker [T ]) applyOmniConfigs () error {
253+ cfg := siderolink .NewConfigV1Alpha1 ()
254+
255+ parsedURL , err := ParseOmniAPIUrl (m .Ops .OmniAPIEndpoint )
256+ if err != nil {
257+ return fmt .Errorf ("error parsing omni api url: %w" , err )
258+ }
259+
260+ cfg .APIUrlConfig .URL = parsedURL
261+
262+ ctr , err := container .New (cfg )
263+ if err != nil {
264+ return err
265+ }
266+
267+ m .ForEachNode (func (i int , node * provision.NodeRequest ) {
268+ node .Config = ctr
269+ node .Name = m .Ops .RootOps .ClusterName + "-machine-" + strconv .Itoa (i + 1 )
270+ })
271+
272+ return nil
273+ }
274+
275+ func (m * Maker [T ]) finalizeMachineConfigs () (* bundle.Bundle , error ) {
213276 // These options needs to be generated after the implementing maker has made changes to the cluster request.
214277 m .GenOps = slices .Concat (m .GenOps , m .Provisioner .GenOptions (m .ClusterRequest .Network , m .VersionContract ))
215278 m .GenOps = slices .Concat (m .GenOps , []generate.Option {generate .WithEndpointList (m .Endpoints )})
@@ -226,7 +289,7 @@ func (m *Maker[T]) GetClusterConfigs() (clusterops.ClusterConfigs, error) {
226289
227290 configBundle , err := bundle .NewBundle (m .ConfigBundleOps ... )
228291 if err != nil {
229- return clusterops. ClusterConfigs {} , err
292+ return nil , err
230293 }
231294
232295 if m .ClusterRequest .Nodes [0 ].Type == machine .TypeInit {
@@ -243,15 +306,15 @@ func (m *Maker[T]) GetClusterConfigs() (clusterops.ClusterConfigs, error) {
243306 if m .Ops .WireguardCIDR != "" {
244307 wireguardConfigBundle , err := helpers .NewWireguardConfigBundle (m .IPs [0 ], m .Ops .WireguardCIDR , 51111 , m .Ops .Controlplanes )
245308 if err != nil {
246- return clusterops. ClusterConfigs {} , err
309+ return nil , err
247310 }
248311
249312 for i := range m .ClusterRequest .Nodes {
250313 node := & m .ClusterRequest .Nodes [i ]
251314
252315 patchedCfg , err := wireguardConfigBundle .PatchConfig (node .IPs [0 ], node .Config )
253316 if err != nil {
254- return clusterops. ClusterConfigs {} , err
317+ return nil , err
255318 }
256319
257320 node .Config = patchedCfg
@@ -260,11 +323,7 @@ func (m *Maker[T]) GetClusterConfigs() (clusterops.ClusterConfigs, error) {
260323
261324 m .ProvisionOps = append (m .ProvisionOps , provision .WithTalosConfig (configBundle .TalosConfig ()))
262325
263- return clusterops.ClusterConfigs {
264- ClusterRequest : m .ClusterRequest ,
265- ProvisionOptions : m .ProvisionOps ,
266- ConfigBundle : configBundle ,
267- }, nil
326+ return configBundle , nil
268327}
269328
270329// ForEachNode iterates over all nodes allowing modification of each node.
0 commit comments