Skip to content

Commit

Permalink
Merge pull request #152 from appilon/87-k8s-secret-fix-validation
Browse files Browse the repository at this point in the history
validators: change label validation to DNS1123 subdomain
  • Loading branch information
appilon authored Apr 9, 2018
2 parents bcc3a26 + 1d2bf9b commit 9b42a22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 27 additions & 0 deletions kubernetes/resource_kubernetes_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ func TestAccKubernetesSecret_basic(t *testing.T) {
})
}

func TestAccKuberNetesSecret_dotInName(t *testing.T) {
var conf api.Secret

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesSecretDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesSecretConfig_dotInSecretName,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesSecretExists("kubernetes_secret.test", &conf),
resource.TestCheckResourceAttr("kubernetes_secret.test", "metadata.0.name", "dot.test"),
),
},
},
})
}

func TestAccKubernetesSecret_importBasic(t *testing.T) {
resourceName := "kubernetes_secret.test"
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -302,6 +321,14 @@ func testAccCheckKubernetesSecretExists(n string, obj *api.Secret) resource.Test
}
}

const testAccKubernetesSecretConfig_dotInSecretName = `
resource "kubernetes_secret" "test" {
metadata {
name = "dot.test"
}
}
`

func testAccKubernetesSecretConfig_emptyData(name string) string {
return fmt.Sprintf(`
resource "kubernetes_secret" "test" {
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func validateAnnotations(value interface{}, key string) (ws []string, es []error

func validateName(value interface{}, key string) (ws []string, es []error) {
v := value.(string)

errors := apiValidation.NameIsDNSLabel(v, false)
errors := apiValidation.NameIsDNSSubdomain(v, false)
if len(errors) > 0 {
for _, err := range errors {
es = append(es, fmt.Errorf("%s %s", key, err))
Expand Down

0 comments on commit 9b42a22

Please sign in to comment.