Skip to content

Commit

Permalink
Fix secret type nil bug and add test case #182
Browse files Browse the repository at this point in the history
  • Loading branch information
pst committed Jun 2, 2022
1 parent 7826652 commit 8274dfe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions kustomize/resource_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions kustomize/resource_kustomization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace: test-secret-sa-token

resources:
- namespace.yaml
- secret.yaml
- secret_default.yaml
- secret_sa_token.yaml
- service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: Secret
metadata:
name: test
namespace: test-secret-sa-token

0 comments on commit 8274dfe

Please sign in to comment.