Skip to content

Commit

Permalink
Additional check for Kubernetes update
Browse files Browse the repository at this point in the history
Check for Kubernetes update only if config and upstream version are not nil.

Issue: #686
(cherry picked from commit 61bd24f)
  • Loading branch information
mjura committed Jul 17, 2024
1 parent a5e24e2 commit 8747c54
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions controller/eks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 8747c54

Please sign in to comment.