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

Add secret_namespace to volume_source azure_file #1204

Merged
merged 2 commits into from
Mar 29, 2021

Conversation

bancek
Copy link
Contributor

@bancek bancek commented Mar 17, 2021

Description

This adds support for setting secret_namespace argument for azure_file volume type for resource kubernetes_persistent_volume (k8s api).

Fixes #1160

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccKubernetesPersistentVolume_azure_file'
...
TF_CLI_CONFIG_FILE=/tmp/terraform-provider-kubernetes/kubernetes/test-infra/external-providers/.terraformrc TF_PLUGIN_CACHE_DIR=/tmp/terraform-provider-kubernetes/kubernetes/test-infra/external-providers/.terraform TF_ACC=1 go test "/tmp/terraform-provider-kubernetes/kubernetes" -v -run=TestAccKubernetesPersistentVolume_azure_file -timeout 120m
=== RUN   TestAccKubernetesPersistentVolume_azure_file
--- PASS: TestAccKubernetesPersistentVolume_azure_file (321.06s)
PASS
ok      github.com/hashicorp/terraform-provider-kubernetes/kubernetes   321.600s

Output from kubectl during the test:

$ kubectl get pv/tfacctestbcvvfyt8dl -o yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: tfacctestbcvvfyt8dl
spec:
  accessModes:
  - ReadWriteOnce
  azureFile:
    secretName: tfacctest8lkacq8lgx
    secretNamespace: tfacctestznnik4h68w
    shareName: tfacctestbcvvfyt8dl
  capacity:
    storage: 1Gi
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem

Release Note

Release note for CHANGELOG:

Add support for updating `kubernetes_persistent_volume` `azure_file` `secret_namespace` argument.

References

Fixes #1160

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

@ghost ghost added size/XS labels Mar 17, 2021
@hashicorp-cla
Copy link

hashicorp-cla commented Mar 17, 2021

CLA assistant check
All committers have signed the CLA.

@BasBerk
Copy link

BasBerk commented Mar 19, 2021

Hi,

Maybe my testing is wrong, I'm not an expert on these kind of things, but even using you code it still tries to look up the secret in the default namespace:

Warning FailedMount 30s (x2 over 32s) kubelet MountVolume.SetUp failed for volume "g7xxx" : Couldn't get secret default/common-sa-secret-dev

    volume {
       name = "g7xxx"
        azure_file {
          share_name = "data/g7_xxx"            
          secret_name = kubernetes_secret.common_sa_secret.metadata[0].name
          secret_namespace = local.namespace
          read_only = false
        }               
      }

+ volume { + name = "g7xxx" + azure_file { + read_only = false + secret_name = "common-sa-secret-dev" + secret_namespace = "iss-ftp-nonp-dev" + share_name = "data/g7_xxx" } }

@bancek
Copy link
Contributor Author

bancek commented Mar 19, 2021

@BazzardTCR it looks like I made a typo in my PR branch. I'll look into adding an acceptance test.

@BasBerk
Copy link

BasBerk commented Mar 19, 2021

@BazzardTCR it looks like I made a typo in my PR branch. I'll look into adding an acceptance test.

I did a rebuild check if the last change was in there, it is, but still the same issue.
Not sure it helps or it's relevant, with kubectl describe pod:

shared: Type: AzureFile (an Azure File Service mount on the host and bind mount to the pod) SecretName: common-sa-secret-dev ShareName: shared ReadOnly: true

@bancek bancek force-pushed the feature-azure-file-secret-namespace branch from ac7c1c7 to 84feb33 Compare March 19, 2021 14:34
@ghost ghost added size/L and removed size/XS labels Mar 19, 2021
@bancek
Copy link
Contributor Author

bancek commented Mar 19, 2021

I've added the acceptance test and hardened the checks for nil and empty values. Changing secret_namespace now also forces recreate.

Base automatically changed from master to main March 23, 2021 15:53
@dak1n1 dak1n1 added the acknowledged Issue has undergone initial review and is in our work queue. label Mar 29, 2021
Copy link
Contributor

@dak1n1 dak1n1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks really good! Thanks for this contribution. I'm going to run a few more tests, but I wanted to leave some initial feedback.

kubernetes/schema_volume_source.go Outdated Show resolved Hide resolved
kubernetes/schema_volume_source.go Show resolved Hide resolved
Comment on lines +1388 to +1398
resource "kubernetes_secret" "test" {
metadata {
name = %[3]q
namespace = %[2]q
}

data = {
azurestorageaccountname = azurerm_storage_account.test.name
azurestorageaccountkey = azurerm_storage_account.test.primary_access_key
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look great! I'm especially excited to see an example demonstrating a feature I haven't used before. Thanks for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would also create a pod and validate that the volume is actually mounted but this is better than nothing :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I ended up doing that manually to test. I'll paste it here in case anyone is randomly googling how to mount azure file shares to their pod.

https://gist.githubusercontent.com/dak1n1/43a199ce6b066d894f5a878f3f588561/raw/d5f86fa57f4dd79bda4d93c1364897a180b9b8a1/gistfile1.txt

@dak1n1 dak1n1 self-assigned this Mar 29, 2021
Copy link
Contributor

@dak1n1 dak1n1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on AKS 1.18, 1.19, 1.20 using terraform 0.14.7 and 0.14.8. It looks like it's working reliably. Thanks again!

Comment on lines +1388 to +1398
resource "kubernetes_secret" "test" {
metadata {
name = %[3]q
namespace = %[2]q
}

data = {
azurestorageaccountname = azurerm_storage_account.test.name
azurestorageaccountkey = azurerm_storage_account.test.primary_access_key
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I ended up doing that manually to test. I'll paste it here in case anyone is randomly googling how to mount azure file shares to their pod.

https://gist.githubusercontent.com/dak1n1/43a199ce6b066d894f5a878f3f588561/raw/d5f86fa57f4dd79bda4d93c1364897a180b9b8a1/gistfile1.txt

@dak1n1 dak1n1 merged commit 1039c8f into hashicorp:main Mar 29, 2021
@ghost
Copy link

ghost commented Apr 29, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
acknowledged Issue has undergone initial review and is in our work queue. documentation size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubernetes_persistent_volume to support arg secret_namespace for azure_file volume type
4 participants