Skip to content

Commit

Permalink
Merge pull request #216 from TruePack/update_quotas_usage
Browse files Browse the repository at this point in the history
Update quotas usage with new quotas schema
  • Loading branch information
T-Sh authored Feb 8, 2023
2 parents df8a225 + 47becbe commit f33b349
Show file tree
Hide file tree
Showing 83 changed files with 289 additions and 421 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/selectel/dbaas-go v0.7.0
github.com/selectel/domains-go v0.4.0
github.com/selectel/go-selvpcclient v1.12.0
github.com/selectel/go-selvpcclient/v2 v2.1.0
github.com/selectel/mks-go v0.12.0
github.com/stretchr/testify v1.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ github.com/selectel/dbaas-go v0.7.0 h1:IBEU7EAPlkQ7wGjtIz9bppthpTZLGn3E6TVX7JWMt
github.com/selectel/dbaas-go v0.7.0/go.mod h1:8D945oFzpx94v08zIb4s1bRTPCdPoNVnBu4umMYFJrQ=
github.com/selectel/domains-go v0.4.0 h1:mVUeJK8oW9XMizft7Vu4OCyvjbzq4+o+zHgzJ2ZxnIY=
github.com/selectel/domains-go v0.4.0/go.mod h1:AhXhwyMSTkpEWFiBLUvzFP76W+WN+ZblwmjLJLt7y58=
github.com/selectel/go-selvpcclient v1.12.0 h1:LsT074HOVF1dWYapsAWjaaJDQhmDPpcsVjSwQ1r1fj0=
github.com/selectel/go-selvpcclient v1.12.0/go.mod h1:HNteVXevZMjUCRR6lImTsGZZSTeKu89S/qbEDWDqmgc=
github.com/selectel/go-selvpcclient/v2 v2.1.0 h1:6CblJtXrL03IbBSgVrX2HU92cfiaPMB7v8kbS1mQN3M=
github.com/selectel/go-selvpcclient/v2 v2.1.0/go.mod h1:kFPnYYxcgJHybnmYEmZ9S+G0MNe8wBmYhhCkEqYjAuc=
github.com/selectel/mks-go v0.12.0 h1:nLWHK8BXkhFlXvjFqf7WRrdAfvmrOhQzDSLx7BGa6aM=
github.com/selectel/mks-go v0.12.0/go.mod h1:FcFqF3WvZIhztyAt1+ZySKf0zWmCEvg9e2gRwxVyQOw=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
13 changes: 10 additions & 3 deletions selectel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"github.com/hashicorp/go-retryablehttp"
domainsV1 "github.com/selectel/domains-go/pkg/v1"
"github.com/selectel/go-selvpcclient/selvpcclient"
"github.com/selectel/go-selvpcclient/selvpcclient/resell"
resellV2 "github.com/selectel/go-selvpcclient/selvpcclient/resell/v2"
"github.com/selectel/go-selvpcclient/v2/selvpcclient"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/quotamanager"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell"
resellV2 "github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2"
)

// Config contains all available configuration options.
Expand Down Expand Up @@ -51,3 +52,9 @@ func (c *Config) domainsV1Client() *domainsV1.ServiceClient {

return domainsClient
}

func (c *Config) quotaManagerRegionalClient(
identity quotamanager.IdentityManagerInterface,
) *quotamanager.QuotaRegionalClient {
return quotamanager.NewQuotaRegionalClient(selvpcclient.NewHTTPClient(), identity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

func TestAccDBaaSAvailableExtensionsV1Basic(t *testing.T) {
Expand Down Expand Up @@ -67,7 +67,6 @@ func testAccDBaaSAvailableExtensionsV1Basic(projectName, name string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_available_extension_v1" "available_extension_tf_acc_test_1" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

func TestAccDBaaSConfigurationParametersV1Basic(t *testing.T) {
Expand Down Expand Up @@ -97,7 +97,6 @@ func testAccDBaaSConfigurationParametersV1Basic(projectName, engine, version, na
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_datastore_type_v1" "dt" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

func TestAccDBaaSDatastoreTypesV1Basic(t *testing.T) {
Expand Down Expand Up @@ -69,7 +69,6 @@ func testAccDBaaSDatastoreTypesV1Basic(projectName, engine, version string) stri
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_datastore_type_v1" "datastore_type_tf_acc_test_1" {
Expand Down
4 changes: 1 addition & 3 deletions selectel/data_source_selectel_dbaas_flavor_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

func TestAccDBaaSFlavorsV1Basic(t *testing.T) {
Expand Down Expand Up @@ -82,7 +82,6 @@ func testAccDBaaSFlavorsV1Basic(projectName string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_flavor_v1" "flavor_tf_acc_test_1" {
Expand All @@ -96,7 +95,6 @@ func testAccDBaaSFlavorsV1RedisFlavor(projectName string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_datastore_type_v1" "dt" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

func TestAccDBaaSDataSourcePrometheusMetricTokenV1Basic(t *testing.T) {
Expand Down Expand Up @@ -65,7 +65,6 @@ func testAccDBaaSDataSourcePrometheusMetricTokenV1Basic(projectName string) stri
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_dbaas_prometheus_metric_token_v1" "prometheus_metric_token_tf_acc_test_1" {
Expand Down
4 changes: 1 addition & 3 deletions selectel/data_source_selectel_mks_kube_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/projects"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/projects"
)

const (
Expand Down Expand Up @@ -208,7 +208,6 @@ func testKubeOptionsV1BasicConfig(projectName, dataSource, kubeVersion string) s
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "%s" "dt" {
Expand All @@ -225,7 +224,6 @@ func testKubeOptionsV1ConfigNoFilter(projectName, dataSource string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "%s" "dt" {
Expand Down
2 changes: 1 addition & 1 deletion selectel/data_source_selectel_mks_kube_versions_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/tokens"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/tokens"
v1 "github.com/selectel/mks-go/pkg/v1"
"github.com/selectel/mks-go/pkg/v1/kubeversion"
)
Expand Down
1 change: 0 additions & 1 deletion selectel/data_source_selectel_mks_kube_versions_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func testAccMKSKubeVersionsV1Basic(projectName string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
data "selectel_mks_kube_versions_v1" "kube_versions_tf_acc_test_1" {
Expand Down
2 changes: 1 addition & 1 deletion selectel/data_source_selectel_mks_kubeconfig_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/tokens"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/tokens"
v1 "github.com/selectel/mks-go/pkg/v1"
"github.com/selectel/mks-go/pkg/v1/cluster"
)
Expand Down
2 changes: 1 addition & 1 deletion selectel/dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/selectel/dbaas-go"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/tokens"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/tokens"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion selectel/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package selectel
import (
"testing"

"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/keypairs"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/keypairs"
"github.com/stretchr/testify/assert"
)

Expand Down
20 changes: 9 additions & 11 deletions selectel/mks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/quotas"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/tokens"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/quotamanager/quotas"
"github.com/selectel/go-selvpcclient/v2/selvpcclient/resell/v2/tokens"
v1 "github.com/selectel/mks-go/pkg/v1"
"github.com/selectel/mks-go/pkg/v1/cluster"
"github.com/selectel/mks-go/pkg/v1/kubeoptions"
Expand Down Expand Up @@ -671,7 +671,7 @@ func findQuota(quotas []*quotas.Quota, resource string) []quotas.ResourceQuotaEn
return nil
}

func checkQuotasForCluster(projectQuotas []*quotas.Quota, region string, zonal bool) error {
func checkQuotasForCluster(projectQuotas []*quotas.Quota, zonal bool) error {
var (
clusterQuotaChecked bool
quota []quotas.ResourceQuotaEntity
Expand All @@ -692,16 +692,14 @@ func checkQuotasForCluster(projectQuotas []*quotas.Quota, region string, zonal b
}

for _, v := range quota {
if v.Region == region {
if v.Value-v.Used <= 0 {
if zonal {
return errors.New("not enough quota to create zonal k8s cluster")
}

return errors.New("not enough quota to create regional k8s cluster")
if v.Value-v.Used <= 0 {
if zonal {
return errors.New("not enough quota to create zonal k8s cluster")
}
clusterQuotaChecked = true

return errors.New("not enough quota to create regional k8s cluster")
}
clusterQuotaChecked = true
}
if !clusterQuotaChecked {
if zonal {
Expand Down
Loading

0 comments on commit f33b349

Please sign in to comment.