Skip to content

Commit 6982405

Browse files
yevgeny-shnaidmanybettan
authored andcommitted
Fixing KMM deployment for clusters under RedHat SRE (ROSA)
Openshift cluster that are managed by Redhat SRE, do not allow(restrict) user from changing ignitions etc'. It means that the MachineConfig CRD is not deployed on the cluster, which causes the BMC controller to constantly fail, since it is watching for that object. The fix is to check the presence of the MachineConfig CRD, and to kick-off the BMC controller only in case it is present
1 parent 0a74311 commit 6982405

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

cmd/manager/main.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import (
4848
"github.com/rh-ecosystem-edge/kernel-module-management/internal/networkpolicy"
4949
"github.com/rh-ecosystem-edge/kernel-module-management/internal/nmc"
5050
"github.com/rh-ecosystem-edge/kernel-module-management/internal/syncronizedmap"
51+
"k8s.io/apimachinery/pkg/api/meta"
52+
runtimescheme "k8s.io/apimachinery/pkg/runtime/schema"
5153

5254
"k8s.io/apimachinery/pkg/runtime"
5355
"k8s.io/apimachinery/pkg/types"
@@ -199,8 +201,17 @@ func main() {
199201
cmd.FatalError(setupLogger, err, "unable to create controller", "name", controllers.MICReconcilerName)
200202
}
201203

202-
if err = controllers.NewBMCReconciler(client, mcfgAPI, scheme).SetupWithManager(mgr); err != nil {
203-
cmd.FatalError(setupLogger, err, "unable to create controller", "name", controllers.BMCReconcilerName)
204+
bmcSupported, err := isBMCSupported(mgr.GetRESTMapper())
205+
if err != nil {
206+
cmd.FatalError(setupLogger, err, "failed to check presence of CRDs needed for BMC controller")
207+
}
208+
209+
if bmcSupported {
210+
if err = controllers.NewBMCReconciler(client, mcfgAPI, scheme).SetupWithManager(mgr); err != nil {
211+
cmd.FatalError(setupLogger, err, "unable to create controller", "name", controllers.BMCReconcilerName)
212+
}
213+
} else {
214+
setupLogger.Info("BMC controller is not running on the cluster, since MachineConfig CRD is not provided by MCO")
204215
}
205216

206217
if managed {
@@ -282,3 +293,22 @@ func GetBoolEnv(s string) (bool, error) {
282293

283294
return managed, nil
284295
}
296+
297+
func isBMCSupported(mapper meta.RESTMapper) (bool, error) {
298+
gk := runtimescheme.GroupKind{
299+
Group: "machineconfiguration.openshift.io",
300+
Kind: "MachineConfig",
301+
}
302+
303+
_, err := mapper.RESTMapping(gk, "v1")
304+
305+
if err != nil {
306+
if meta.IsNoMatchError(err) {
307+
return false, nil
308+
}
309+
// Any other error (network, etc.) should be treated as a failure
310+
return false, fmt.Errorf("failed to get the MC CRD due to internal error: %v", err)
311+
}
312+
313+
return true, nil
314+
}

0 commit comments

Comments
 (0)