Skip to content

Commit

Permalink
Fix cannot retry upgrade 1.29 to 1.30 when previous upgrade fails (#406)
Browse files Browse the repository at this point in the history
* ensure freshness of k8s resource after creation

* always get template uuid from version/release even if version/release is not changed

IF the previous upgrade (from 1.29 to 1.30) fails, the updated value of version/release is still persisted (tf provider behaviour because we don't set version/release in k8s resource READ). Hence when we re-try the upgrade, this piece of code detect no changes in version/release parameter => tf tries to get template uuid from service_template_uuid (which is just the current template of the cluster), hence no upgrade happens.
  • Loading branch information
nvthongswansea authored Jan 2, 2025
1 parent 7209505 commit 5c53faa
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,30 +427,18 @@ func deriveK8sTemplateFromResourceData(client *gsclient.Client, d *schema.Resour
releaseInterface, isReleaseSet := d.GetOk("release")
release := releaseInterface.(string)

if !d.IsNewResource() { // case if update of resource is requested
if isVersionSet && d.HasChange("version") {
derivationTypesRequested += 1
derivationType = "version"
}

if isReleaseSet && d.HasChange("release") {
derivationTypesRequested += 1
derivationType = "release"
}
} else { // case if creation of resource is requested
if isVersionSet {
derivationTypesRequested += 1
derivationType = "version"
}
if isVersionSet {
derivationTypesRequested += 1
derivationType = "version"
}

if isReleaseSet {
derivationTypesRequested += 1
derivationType = "release"
}
if isReleaseSet {
derivationTypesRequested += 1
derivationType = "release"
}

if derivationTypesRequested == 0 {
return nil, errors.New("either \"release\" or \"gsk_version\" has to be defined")
}
if derivationTypesRequested == 0 {
return nil, errors.New("either \"release\" or \"gsk_version\" has to be defined")
}

if derivationTypesRequested > 1 {
Expand Down Expand Up @@ -1027,7 +1015,7 @@ func resourceGridscaleK8sCreate(d *schema.ResourceData, meta interface{}) error
}
d.SetId(response.ObjectUUID)
log.Printf("The id for PaaS service %s has been set to %v", requestBody.Name, response.ObjectUUID)
return nil //resourceGridscaleK8sRead(d, meta)
return resourceGridscaleK8sRead(d, meta)
}

func resourceGridscaleK8sUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down

0 comments on commit 5c53faa

Please sign in to comment.