From 8747c54000f1e7055313e9481a7fa4d39d965de6 Mon Sep 17 00:00:00 2001 From: Michal Jura Date: Wed, 17 Jul 2024 09:18:47 +0200 Subject: [PATCH] Additional check for Kubernetes update Check for Kubernetes update only if config and upstream version are not nil. Issue: https://github.com/rancher/eks-operator/issues/686 (cherry picked from commit 61bd24f2d3096cdea65458a5dbb0c84428045cec) --- controller/eks-cluster-config-handler.go | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/controller/eks-cluster-config-handler.go b/controller/eks-cluster-config-handler.go index 0ecd980a..2e6b4e5d 100644 --- a/controller/eks-cluster-config-handler.go +++ b/controller/eks-cluster-config-handler.go @@ -693,28 +693,29 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, upstreamSpec * return config, fmt.Errorf("aws services not initialized") } - configVersion, err := semver.ParseTolerant(aws.ToString(config.Spec.KubernetesVersion)) - if err != nil { - return config, fmt.Errorf("couldn't parse config version: %w", err) - } - upstreamVersion, err := semver.ParseTolerant(aws.ToString(upstreamSpec.KubernetesVersion)) - if err != nil { - return config, fmt.Errorf("couldn't parse upstream version: %w", err) - } - - // check kubernetes version for update - if config.Spec.KubernetesVersion != nil && - configVersion.GT(upstreamVersion) { - updated, err := awsservices.UpdateClusterVersion(ctx, &awsservices.UpdateClusterVersionOpts{ - EKSService: awsSVCs.eks, - Config: config, - UpstreamClusterSpec: upstreamSpec, - }) - if err != nil && !isResourceInUse(err) { - return config, fmt.Errorf("error updating cluster version: %w", err) + if config.Spec.KubernetesVersion != nil && upstreamSpec.KubernetesVersion != nil { + configVersion, err := semver.ParseTolerant(aws.ToString(config.Spec.KubernetesVersion)) + if err != nil { + return config, fmt.Errorf("couldn't parse config version: %w", err) } - if updated { - return h.enqueueUpdate(config) + upstreamVersion, err := semver.ParseTolerant(aws.ToString(upstreamSpec.KubernetesVersion)) + if err != nil { + return config, fmt.Errorf("couldn't parse upstream version: %w", err) + } + + // check kubernetes version for update + if configVersion.GT(upstreamVersion) { + updated, err := awsservices.UpdateClusterVersion(ctx, &awsservices.UpdateClusterVersionOpts{ + EKSService: awsSVCs.eks, + Config: config, + UpstreamClusterSpec: upstreamSpec, + }) + if err != nil && !isResourceInUse(err) { + return config, fmt.Errorf("error updating cluster version: %w", err) + } + if updated { + return h.enqueueUpdate(config) + } } }