@@ -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
8083func 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