Skip to content

Commit 663a3ce

Browse files
rsmittytalos-bot
authored andcommitted
fix: ensure version is not nil
This PR fixes a bug where the pointer to the version string could be nil and we were trying to call a TrimPrefix on the contents, causing a panic. This now introduces a default kube version constant that will be overridden if the version pointer is not nil. Signed-off-by: Spencer Smith <[email protected]>
1 parent dd4350e commit 663a3ce

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

controllers/talosconfig_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/go-logr/logr"
2727
bootstrapv1alpha3 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
28+
"github.com/talos-systems/cluster-api-bootstrap-provider-talos/pkg/constants"
2829
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
2930
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/generate"
3031
configmachine "github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@@ -274,9 +275,13 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
274275
machineType = configmachine.TypeControlPlane
275276
}
276277

277-
// Handle k8s version being formatted like "vX.Y.Z" instead of without leading 'v'
278+
// Allow user to override default kube version.
279+
// This also handles version being formatted like "vX.Y.Z" instead of without leading 'v'
278280
// TrimPrefix returns the string unchanged if the prefix isn't present.
279-
k8sVersion := strings.TrimPrefix(*scope.Machine.Spec.Version, "v")
281+
k8sVersion := constants.DefaultKubeVersion
282+
if scope.Machine.Spec.Version != nil {
283+
k8sVersion = strings.TrimPrefix(*scope.Machine.Spec.Version, "v")
284+
}
280285

281286
APIEndpointPort := strconv.Itoa(int(scope.Cluster.Spec.ControlPlaneEndpoint.Port))
282287
input, err := generate.NewInput(scope.Cluster.Name,

pkg/constants/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package constants
2+
3+
const (
4+
//DefaultKubeVersion is the default kube version
5+
DefaultKubeVersion = "1.19.0"
6+
)

0 commit comments

Comments
 (0)