Skip to content

Commit

Permalink
make gsk release validation for gs tf provider v2 clearer (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvthongswansea authored Jan 3, 2025
1 parent 4e7ae82 commit 647e661
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 1 addition & 13 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,10 @@ func (rgk8sv *ResourceGridscaleK8sValidator) checkIfTemplateSupportsMultiNodePoo
k8sMultiNodePoolSupportRelease,
)
templateRelease, err := NewRelease(template.Properties.Release)

if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
multiNodePoolSupportRelease, err := NewRelease(k8sMultiNodePoolSupportRelease)

if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
err = templateRelease.CheckIfFeatureIsKnown(
&Feature{
Description: "multi node pool support",
Release: *multiNodePoolSupportRelease,
},
)
return err
return templateRelease.CheckIfK8SReleaseIsSupported()
}

// buildInputSchema models the k8s resource's input schema by ResourceGridscaleK8sModeler receiver.
Expand Down
12 changes: 12 additions & 0 deletions 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 supportedK8SRelease = "1.30"

// NewRelease creates a new Release instance.
func NewRelease(representation string) (*Release, error) {
version, err := goVersion.NewVersion(representation)
Expand All @@ -36,3 +38,13 @@ func (r *Release) CheckIfFeatureIsKnown(f *Feature) error {
}
return nil
}

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

0 comments on commit 647e661

Please sign in to comment.