Skip to content

Commit

Permalink
Fix cannot retry upgrade gsk when previous upgrade fails v1 (#410)
Browse files Browse the repository at this point in the history
* 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 detects 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.

* refresh gsk version/release on read
  • Loading branch information
nvthongswansea authored Jan 3, 2025
1 parent eeca020 commit a9def41
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,30 +374,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 @@ -553,6 +541,22 @@ func resourceGridscaleK8sRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("%s error setting kubeconfig: %v", errorPrefix, err)
}
}
template, err := deriveK8sTemplateFromUUID(client, props.ServiceTemplateUUID)
if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
// if version is set, set it with the version of the template
if _, isVersionSet := d.GetOk("gsk_version"); isVersionSet {
if err = d.Set("gsk_version", template.Properties.Version); err != nil {
return fmt.Errorf("%s error setting gsk_version: %v", errorPrefix, err)
}
}
// if release is set, set it with the release of the template
if _, isReleaseSet := d.GetOk("release"); isReleaseSet {
if err = d.Set("release", template.Properties.Release); err != nil {
return fmt.Errorf("%s error setting release: %v", errorPrefix, err)
}
}
if err = d.Set("security_zone_uuid", props.SecurityZoneUUID); err != nil {
return fmt.Errorf("%s error setting security_zone_uuid: %v", errorPrefix, err)
}
Expand Down

0 comments on commit a9def41

Please sign in to comment.