Skip to content

Commit 4b7ae2f

Browse files
committed
CLI Option for naming servers as the BMC objects
While the redfish standard supports an API with multiple systems managed by one endpoint (such as Cisco IMC and others), an often use-case is to communicate with the BMC directly. In Netbox, one usually models the system managed by the BMC and the BMC itself is just an attribute on the system. The expectation in these circumstances is, that the Server is not a child of the BMC (i.e. suffix -system-0), but they are both belonging to the same server (i.e. have the same name). The CLI option disable-server-name-suffix allows one to opt-in into the logic that such a Server should be named as the BMC.
1 parent 8261698 commit 4b7ae2f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func main() { // nolint: gocyclo
8282
discoveryTimeout time.Duration
8383
serverMaxConcurrentReconciles int
8484
serverClaimMaxConcurrentReconciles int
85+
disableServerNameSuffix bool
8586
)
8687

8788
flag.IntVar(&serverMaxConcurrentReconciles, "server-max-concurrent-reconciles", 5,
@@ -128,6 +129,8 @@ func main() { // nolint: gocyclo
128129
"If set the metrics endpoint is served securely")
129130
flag.BoolVar(&enableHTTP2, "enable-http2", false,
130131
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
132+
flag.BoolVar(&disableServerNameSuffix, "disable-server-name-suffix", false,
133+
"If set, will drop the suffix -system-0 for servers, if there is only one system known to the BMC")
131134
opts := zap.Options{
132135
Development: true,
133136
}
@@ -299,9 +302,10 @@ func main() { // nolint: gocyclo
299302
os.Exit(1)
300303
}
301304
if err = (&controller.BMCReconciler{
302-
Client: mgr.GetClient(),
303-
Scheme: mgr.GetScheme(),
304-
Insecure: insecure,
305+
Client: mgr.GetClient(),
306+
Scheme: mgr.GetScheme(),
307+
Insecure: insecure,
308+
DisableServerNameSuffix: disableServerNameSuffix,
305309
}).SetupWithManager(mgr); err != nil {
306310
setupLog.Error(err, "unable to create controller", "controller", "BMC")
307311
os.Exit(1)

internal/controller/bmc_controller.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const BMCFinalizer = "metal.ironcore.dev/bmc"
3131
// BMCReconciler reconciles a BMC object
3232
type BMCReconciler struct {
3333
client.Client
34-
Scheme *runtime.Scheme
35-
Insecure bool
36-
BMCPollingOptions bmc.Options
34+
Scheme *runtime.Scheme
35+
Insecure bool
36+
BMCPollingOptions bmc.Options
37+
DisableServerNameSuffix bool
3738
}
3839

3940
//+kubebuilder:rbac:groups=metal.ironcore.dev,resources=endpoints,verbs=get;list;watch
@@ -161,9 +162,15 @@ func (r *BMCReconciler) discoverServers(ctx context.Context, log logr.Logger, bm
161162
}
162163

163164
var errs []error
165+
serverCount := len(servers)
166+
useShortServerName := serverCount == 1 && r.DisableServerNameSuffix
164167
for i, s := range servers {
165168
server := &metalv1alpha1.Server{}
166-
server.Name = bmcutils.GetServerNameFromBMCandIndex(i, bmcObj)
169+
if useShortServerName {
170+
server.Name = bmcObj.Name
171+
} else {
172+
server.Name = bmcutils.GetServerNameFromBMCandIndex(i, bmcObj)
173+
}
167174

168175
opResult, err := controllerutil.CreateOrPatch(ctx, r.Client, server, func() error {
169176
metautils.SetLabels(server, bmcObj.Labels)

0 commit comments

Comments
 (0)