From a71f5c80f433207c0ef3dd74de8a72a6aa5def83 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Tue, 30 Apr 2024 10:24:31 -0500 Subject: [PATCH] MachinePools/OpenStack: Fix nil pointer exception This is *not* a cherry-pick of #2253 / (c6b37ee6 & f59f327d). That solution revendored installer to pick up the fix from upstream. In older branches, this would have dragged in too many dependencies, so we instead fix it "locally" with an explicit nil check. Note also that the original fix added unit tests. We can't do that here either because the new tests rely on the OpenStack UT suite being un-broken [1], which again relied on upstream changes [2][3] we can't pull into older branches. [1] https://github.com/openshift/hive/pull/2251 [2] https://github.com/openshift/installer/pull/8187 [3] https://github.com/openshift/installer/pull/8209 HIVE-2476 --- pkg/controller/machinepool/openstackactuator.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/controller/machinepool/openstackactuator.go b/pkg/controller/machinepool/openstackactuator.go index 005fc9865fc..f0389a8f4dc 100644 --- a/pkg/controller/machinepool/openstackactuator.go +++ b/pkg/controller/machinepool/openstackactuator.go @@ -15,6 +15,7 @@ import ( "k8s.io/apimachinery/pkg/types" utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/json" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" machinev1beta1 "github.com/openshift/api/machine/v1beta1" @@ -66,6 +67,17 @@ func (a *OpenStackActuator) GenerateMachineSets(cd *hivev1.ClusterDeployment, po } computePool := baseMachinePool(pool) + + // HIVE-2476: Avoid nil pointer exception in upstream MachineSets() call. + // In master, this was remedied by revendoring to pull in the upstream fix. See: + // https://github.com/openshift/installer/pull/8227 + // https://github.com/openshift/hive/pull/2253 + // In older branches this would have pulled in too many chained dependencies, so + // we're just fixing it "locally". + if computePool.Replicas == nil { + computePool.Replicas = pointer.Int64(0) + } + computePool.Platform.OpenStack = &installertypesosp.MachinePool{ FlavorName: pool.Spec.Platform.OpenStack.Flavor, // The installer's MachinePool-to-MachineSet function will distribute the generated