Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Nomad dependency #226

Merged
merged 12 commits into from
May 14, 2021
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/nomad v1.0.4
github.com/hashicorp/nomad/api v0.0.0-20210223222946-149b150fb2d8
github.com/hashicorp/nomad v1.1.0-beta1
github.com/hashicorp/nomad/api v0.0.0-20210503143957-4ccada7924cf
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/hashicorp/vault v0.10.4
github.com/mitchellh/mapstructure v1.4.1 // indirect
Expand Down
90 changes: 54 additions & 36 deletions go.sum

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions nomad/data_source_scheduler_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ func dataSourceSchedulerConfig() *schema.Resource {
Read: dataSourceSchedulerConfigRead,

Schema: map[string]*schema.Schema{
"memory_oversubscription_enabled": {
Description: "When true, tasks may exceed their reserved memory limit.",
Type: schema.TypeBool,
Computed: true,
},
"scheduler_algorithm": {
Description: "Specifies whether scheduler binpacks or spreads allocations on available nodes.",
Type: schema.TypeString,
Expand Down Expand Up @@ -47,6 +52,7 @@ func dataSourceSchedulerConfigRead(d *schema.ResourceData, meta interface{}) err
}

sw := helper.NewStateWriter(d)
sw.Set("memory_oversubscription_enabled", schedCfg.SchedulerConfig.MemoryOversubscriptionEnabled)
sw.Set("scheduler_algorithm", schedCfg.SchedulerConfig.SchedulerAlgorithm)
sw.Set("preemption_config", premptMap)
return sw.Error()
Expand Down
16 changes: 11 additions & 5 deletions nomad/data_source_scheduler_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,33 @@ func TestAccDataSourceSchedulerConfig_basic(t *testing.T) {
CheckDestroy: testFinalConfiguration,
Steps: []resource.TestStep{
{
Config: testAccNomadSchedulerConfigSpread,
Config: testAccNomadDataSourceSchedulerConfigS,
Check: resource.ComposeTestCheckFunc(
lgfa29 marked this conversation as resolved.
Show resolved Hide resolved
resource.TestCheckResourceAttr(
"nomad_scheduler_config.config",
"data.nomad_scheduler_config.config",
"scheduler_algorithm",
"spread",
),
resource.TestCheckResourceAttr(
"nomad_scheduler_config.config",
"data.nomad_scheduler_config.config",
"preemption_config.batch_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"nomad_scheduler_config.config",
"data.nomad_scheduler_config.config",
"preemption_config.service_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"nomad_scheduler_config.config",
"data.nomad_scheduler_config.config",
"preemption_config.system_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"memory_oversubscription_enabled",
"true",
),
),
},
},
Expand All @@ -43,6 +48,7 @@ func TestAccDataSourceSchedulerConfig_basic(t *testing.T) {

const testAccNomadDataSourceSchedulerConfigS = `
resource "nomad_scheduler_config" "config" {
memory_oversubscription_enabled = true
scheduler_algorithm = "spread"
preemption_config = {
system_scheduler_enabled = true
Expand Down
58 changes: 57 additions & 1 deletion nomad/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"reflect"
"strings"
"testing"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -132,12 +133,18 @@ func TestAccNomadProvider_Headers(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactoryInternal(&provider),
CheckDestroy: nil,
CheckDestroy: testAccCheckNomadProviderConfigWithHeadersCrashCheckDestroy(provider),
Steps: []resource.TestStep{
{
Config: testAccNomadProviderConfigWithHeaders,
Check: testAccCheckNomadProviderConfigWithHeaders(provider),
},
{
// Test concurrent access to Nomad API headers.
// On fail the provider would panic, so there's no check necessary.
// https://github.com/hashicorp/terraform-provider-nomad/issues/215
Config: testAccNomadProviderConfigWithHeadersCrash,
},
},
})
}
Expand All @@ -160,6 +167,30 @@ func testAccCheckNomadProviderConfigWithHeaders(provider *schema.Provider) resou
}
}

func testAccCheckNomadProviderConfigWithHeadersCrashCheckDestroy(provider *schema.Provider) resource.TestCheckFunc {
return func(_ *terraform.State) error {
providerConfig := provider.Meta().(ProviderConfig)
client := providerConfig.client
namespaces, _, err := client.Namespaces().List(nil)
if err != nil {
return err
}

count := 0
namespacePrefix := "headers-crash-test"
for _, ns := range namespaces {
if strings.HasPrefix(ns.Name, namespacePrefix) {
count++
}
}

if count != 0 {
return fmt.Errorf("%d namespaces still registered", count)
}
return nil
}
}

var testAccNomadProviderConfigWithHeaders = `
provider "nomad" {
headers {
Expand All @@ -180,6 +211,31 @@ provider "nomad" {
data "nomad_namespaces" "test" {}
`

var testAccNomadProviderConfigWithHeadersCrash = `
provider "nomad" {
headers {
name = "Test-Header-1"
value = "a"
}
headers {
name = "Test-header-1"
value = "b"
}
headers {
name = "test-header-2"
value = "c"
}
}

// necessary to initialize the provider
data "nomad_namespaces" "test" {}

resource "nomad_namespace" "test" {
count = 100
name = "headers-crash-test-${count.index}"
}
`

func TestAccNomadProvider_ConsulToken(t *testing.T) {
var provider *schema.Provider

Expand Down
Loading