From 8274dfe45d171e687dddd01a923b6f8cd7372566 Mon Sep 17 00:00:00 2001 From: Philipp Strube Date: Thu, 2 Jun 2022 09:33:04 +0200 Subject: [PATCH] Fix secret type nil bug and add test case #182 --- kustomize/resource_kustomization.go | 1 + kustomize/resource_kustomization_test.go | 11 ++++++++--- .../secret_service_account_token/Kustomization | 3 ++- .../secret_service_account_token/secret_default.yaml | 5 +++++ .../{secret.yaml => secret_sa_token.yaml} | 0 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 kustomize/test_kustomizations/secret_service_account_token/secret_default.yaml rename kustomize/test_kustomizations/secret_service_account_token/{secret.yaml => secret_sa_token.yaml} (100%) diff --git a/kustomize/resource_kustomization.go b/kustomize/resource_kustomization.go index 4f689c5..8661c81 100644 --- a/kustomize/resource_kustomization.go +++ b/kustomize/resource_kustomization.go @@ -91,6 +91,7 @@ func kustomizationResourceCreate(d *schema.ResourceData, m interface{}) error { // wait for service account to exist // https://github.com/kubernetes/kubernetes/issues/109401 if (u.GetKind() == "Secret") && + (u.UnstructuredContent()["type"] != nil) && (u.UnstructuredContent()["type"].(string) == string(k8scorev1.SecretTypeServiceAccountToken)) { annotations := u.GetAnnotations() diff --git a/kustomize/resource_kustomization_test.go b/kustomize/resource_kustomization_test.go index 0e358e8..74f6aaa 100644 --- a/kustomize/resource_kustomization_test.go +++ b/kustomize/resource_kustomization_test.go @@ -674,8 +674,9 @@ func TestAccResourceKustomization_secretSAToken(t *testing.T) { Config: testAccResourceKustomizationConfig_secretSAToken("test_kustomizations/secret_service_account_token"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("kustomization_resource.ns", "id"), - resource.TestCheckResourceAttrSet("kustomization_resource.sec", "id"), - testAccCheckManifestAnnotation("kustomization_resource.sec", "kubernetes.io/service-account.name", "test-sa"), + resource.TestCheckResourceAttrSet("kustomization_resource.sec_sa_token", "id"), + testAccCheckManifestAnnotation("kustomization_resource.sec_sa_token", "kubernetes.io/service-account.name", "test-sa"), + resource.TestCheckResourceAttrSet("kustomization_resource.sec_default", "id"), resource.TestCheckResourceAttrSet("kustomization_resource.sa", "id"), ), }, @@ -689,10 +690,14 @@ resource "kustomization_resource" "ns" { manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-secret-sa-token"] } -resource "kustomization_resource" "sec" { +resource "kustomization_resource" "sec_sa_token" { manifest = data.kustomization_build.test.manifests["_/Secret/test-secret-sa-token/test-sa-token"] } +resource "kustomization_resource" "sec_default" { + manifest = data.kustomization_build.test.manifests["_/Secret/test-secret-sa-token/test"] +} + resource "time_sleep" "garbage_collection" { create_duration = "5s" } diff --git a/kustomize/test_kustomizations/secret_service_account_token/Kustomization b/kustomize/test_kustomizations/secret_service_account_token/Kustomization index dac284b..a48e178 100644 --- a/kustomize/test_kustomizations/secret_service_account_token/Kustomization +++ b/kustomize/test_kustomizations/secret_service_account_token/Kustomization @@ -5,5 +5,6 @@ namespace: test-secret-sa-token resources: - namespace.yaml -- secret.yaml +- secret_default.yaml +- secret_sa_token.yaml - service_account.yaml diff --git a/kustomize/test_kustomizations/secret_service_account_token/secret_default.yaml b/kustomize/test_kustomizations/secret_service_account_token/secret_default.yaml new file mode 100644 index 0000000..49a890b --- /dev/null +++ b/kustomize/test_kustomizations/secret_service_account_token/secret_default.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Secret +metadata: + name: test + namespace: test-secret-sa-token diff --git a/kustomize/test_kustomizations/secret_service_account_token/secret.yaml b/kustomize/test_kustomizations/secret_service_account_token/secret_sa_token.yaml similarity index 100% rename from kustomize/test_kustomizations/secret_service_account_token/secret.yaml rename to kustomize/test_kustomizations/secret_service_account_token/secret_sa_token.yaml