Skip to content

Commit

Permalink
only allow gsk release < 1.30 to use gs tf provider v1 (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvthongswansea authored Jan 3, 2025
1 parent 9708181 commit eeca020
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,18 @@ func resourceGridscaleK8sCreate(d *schema.ResourceData, meta interface{}) error
client := meta.(*gsclient.Client)
errorPrefix := fmt.Sprintf("create k8s (%s) resource -", d.Id())
template, err := deriveK8sTemplateFromResourceData(client, d)

if err != nil {
return err
}
// check if the k8s release is supported by gs tf provider v1
templateRelease, err := NewRelease(template.Properties.Release)
if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
err = templateRelease.CheckIfK8SReleaseIsSupported()
if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
requestBody := gsclient.PaaSServiceCreateRequest{
Name: d.Get("name").(string),
PaaSServiceTemplateUUID: template.Properties.ObjectUUID,
Expand Down Expand Up @@ -1075,8 +1083,17 @@ func resourceGridscaleK8sDelete(d *schema.ResourceData, meta interface{}) error
}

func validateK8sParameters(d *schema.ResourceDiff, template gsclient.PaaSTemplate) error {
var errorMessages []string
// check if the k8s release is supported by gs tf provider v1
templateRelease, err := NewRelease(template.Properties.Release)
if err != nil {
return err
}
err = templateRelease.CheckIfK8SReleaseIsSupported()
if err != nil {
return err
}

var errorMessages []string
worker_memory_scheme, mem_ok := template.Properties.ParametersSchema["k8s_worker_node_ram"]
// TODO: The API scheme will be CHANGED in the future. There will be multiple node pools.
if memory, ok := d.GetOk("node_pool.0.memory"); ok && mem_ok {
Expand Down
14 changes: 13 additions & 1 deletion gridscale/resource_gridscale_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Feature struct {
Release
}

const unsupportedK8SRelease = "1.30"

// NewRelease creates a new Release instance.
func NewRelease(representation string) (*Release, error) {
version, err := goVersion.NewVersion(representation)
Expand All @@ -28,11 +30,21 @@ func NewRelease(representation string) (*Release, error) {
}

// CheckIfFeatureIsKnown checks by a Release receiver if a passed Feature instance is known.
func (r *Release) CheckIfFeatureIsKnown(f *Feature) *ReleaseFeatureIncompatibilityError {
func (r *Release) CheckIfFeatureIsKnown(f *Feature) error {
if r.LessThan(&f.Version) {
return &ReleaseFeatureIncompatibilityError{
Detail: fmt.Sprintf("Feature '%s' is part of release %s but requested for release %s.", f.Description, f.String(), r.String()),
}
}
return nil
}

// CheckIfK8SReleaseIsSupported checks if the Kubernetes release is supported by this gridscale terraform provider.
func (r *Release) CheckIfK8SReleaseIsSupported() error {
if r.GreaterThanOrEqual(goVersion.Must(goVersion.NewVersion(unsupportedK8SRelease))) {
return &ReleaseFeatureIncompatibilityError{
Detail: fmt.Sprintf("this gridscale terraform provider version v1 supports only Kubernetes release < %s, for Kubernetes release %s please use gridscale terraform provider version v2", unsupportedK8SRelease, r.String()),
}
}
return nil
}

0 comments on commit eeca020

Please sign in to comment.