Skip to content

Commit 6d8d2f6

Browse files
Merge pull request #2713 from dtantsur/use-irso
✨ Integrate with IrSO for getting Ironic details
2 parents 28ecc25 + 04b59d4 commit 6d8d2f6

File tree

11 files changed

+268
-9
lines changed

11 files changed

+268
-9
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ IMG_NAME ?= baremetal-operator
9292
IMG_TAG ?= latest
9393
IMG ?= $(REGISTRY)/$(IMG_NAME)
9494

95+
# Which configuration to use when deploying (from the config directory)
96+
DEPLOY_CONFIG ?= default
97+
9598
## --------------------------------------
9699
## Test Targets
97100
## --------------------------------------
@@ -194,7 +197,7 @@ uninstall: $(KUSTOMIZE) manifests ## Uninstall CRDs from a cluster
194197
.PHONY: deploy
195198
deploy: $(KUSTOMIZE) manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
196199
make set-manifest-image-bmo MANIFEST_IMG=$(IMG_NAME) MANIFEST_TAG=$(IMG_TAG)
197-
$< build config/default | kubectl apply -f -
200+
$< build config/$(DEPLOY_CONFIG) | kubectl apply -f -
198201

199202
$(CONTROLLER_GEN): hack/tools/go.mod
200203
cd hack/tools; go build -o $(abspath $@) sigs.k8s.io/controller-tools/cmd/controller-gen

config/base/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ rules:
2525
- list
2626
- update
2727
- watch
28+
- apiGroups:
29+
- ironic.metal3.io
30+
resources:
31+
- ironics
32+
verbs:
33+
- get
34+
- list
35+
- watch
2836
- apiGroups:
2937
- metal3.io
3038
resources:

config/overlays/e2e/roles-rolebindings/roles-rolebindings.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ rules:
2424
- list
2525
- update
2626
- watch
27+
- apiGroups:
28+
- ironic.metal3.io
29+
resources:
30+
- ironics
31+
verbs:
32+
- get
33+
- list
34+
- watch
2735
- apiGroups:
2836
- metal3.io
2937
resources:

config/render/capm3.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,14 @@ rules:
23962396
- list
23972397
- update
23982398
- watch
2399+
- apiGroups:
2400+
- ironic.metal3.io
2401+
resources:
2402+
- ironics
2403+
verbs:
2404+
- get
2405+
- list
2406+
- watch
23992407
- apiGroups:
24002408
- metal3.io
24012409
resources:

config/use-irso/ironic.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IRONIC_NAME=ironic

config/use-irso/kustomization.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: baremetal-operator-system
4+
resources:
5+
- ../base
6+
7+
generatorOptions:
8+
disableNameSuffixHash: true
9+
10+
configMapGenerator:
11+
- name: ironic
12+
behavior: create
13+
envs:
14+
- ironic.env

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/gophercloud/gophercloud/v2 v2.8.0
1010
github.com/metal3-io/baremetal-operator/apis v0.5.1
1111
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.5.1
12+
github.com/metal3-io/ironic-standalone-operator/api v0.6.0
1213
github.com/onsi/gomega v1.38.2
1314
github.com/prometheus/client_golang v1.23.2
1415
github.com/stretchr/testify v1.11.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
9494
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
9595
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
9696
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
97+
github.com/metal3-io/ironic-standalone-operator/api v0.6.0 h1:u2BDGpGdJqzzZAr4pL4LywKcxfjHXPQNxuJ47ej/6Cc=
98+
github.com/metal3-io/ironic-standalone-operator/api v0.6.0/go.mod h1:V2uX3UR0gK0J8IvF8msNRcdWKviZRrvDCCFMF0uVPQY=
9799
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
98100
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
99101
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

internal/controller/metal3.io/baremetalhost_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func (info *reconcileInfo) publishEvent(reason, message string) {
106106
// Allow for updating hostupdatepolicies
107107
// +kubebuilder:rbac:groups=metal3.io,resources=hostupdatepolicies,verbs=get;list;watch;update
108108

109+
// Allow reading Ironic resources
110+
// +kubebuilder:rbac:groups=ironic.metal3.io,resources=ironics,verbs=get;list;watch
111+
109112
// Reconcile handles changes to BareMetalHost resources.
110113
func (r *BareMetalHostReconciler) Reconcile(ctx context.Context, request ctrl.Request) (result ctrl.Result, err error) {
111114
reconcileCounters.With(hostMetricLabels(request)).Inc()

main.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ import (
3535
"github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic"
3636
"github.com/metal3-io/baremetal-operator/pkg/secretutils"
3737
"github.com/metal3-io/baremetal-operator/pkg/version"
38+
ironicv1alpha1 "github.com/metal3-io/ironic-standalone-operator/api/v1alpha1"
3839
"go.uber.org/zap/zapcore"
3940
k8sruntime "k8s.io/apimachinery/pkg/runtime"
4041
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4142
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4243
cliflag "k8s.io/component-base/cli/flag"
4344
ctrl "sigs.k8s.io/controller-runtime"
4445
"sigs.k8s.io/controller-runtime/pkg/cache"
46+
"sigs.k8s.io/controller-runtime/pkg/client"
4547
"sigs.k8s.io/controller-runtime/pkg/healthz"
4648
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4749
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -75,6 +77,7 @@ func init() {
7577
_ = clientgoscheme.AddToScheme(scheme)
7678

7779
_ = metal3api.AddToScheme(scheme)
80+
_ = ironicv1alpha1.AddToScheme(scheme)
7881
}
7982

8083
func printVersion() {
@@ -215,6 +218,24 @@ func main() {
215218
setupLog.Info("Manager set up with cluster scope")
216219
}
217220

221+
// Setup cache options
222+
var byObject map[client.Object]cache.ByObject
223+
224+
ironicName := os.Getenv("IRONIC_NAME")
225+
ironicNamespace := os.Getenv("IRONIC_NAMESPACE")
226+
if ironicNamespace == "" {
227+
ironicNamespace = leaderElectionNamespace
228+
}
229+
if ironicName != "" && ironicNamespace != "" {
230+
byObject = map[client.Object]cache.ByObject{
231+
&ironicv1alpha1.Ironic{}: {
232+
Namespaces: map[string]cache.Config{
233+
ironicNamespace: {},
234+
},
235+
},
236+
}
237+
}
238+
218239
ctrlOpts := ctrl.Options{
219240
Scheme: scheme,
220241
Metrics: metricsserver.Options{
@@ -233,7 +254,7 @@ func main() {
233254
LeaderElectionReleaseOnCancel: true,
234255
HealthProbeBindAddress: healthAddr,
235256
Cache: cache.Options{
236-
ByObject: secretutils.AddSecretSelector(nil),
257+
ByObject: secretutils.AddSecretSelector(byObject),
237258
DefaultNamespaces: watchNamespaces,
238259
},
239260
}
@@ -288,7 +309,13 @@ func main() {
288309
provisionerFactory = &demo.Demo{}
289310
} else {
290311
provLog := zap.New(zap.UseFlagOptions(&logOpts)).WithName("provisioner")
291-
provisionerFactory, err = ironic.NewProvisionerFactory(provLog, preprovImgEnable)
312+
// Check if we should use Ironic CR integration
313+
if ironicName != "" && ironicNamespace != "" {
314+
provisionerFactory, err = ironic.NewProvisionerFactoryWithClient(provLog, preprovImgEnable,
315+
mgr.GetClient(), mgr.GetAPIReader(), ironicName, ironicNamespace)
316+
} else {
317+
provisionerFactory, err = ironic.NewProvisionerFactory(provLog, preprovImgEnable)
318+
}
292319
if err != nil {
293320
setupLog.Error(err, "cannot start ironic provisioner")
294321
os.Exit(1)

0 commit comments

Comments
 (0)