-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: InitContainer support for ACI Connector (#204)
Co-authored-by: suselva <101893421+suselva@users.noreply.github.com> Co-authored-by: Arnav Arnav <fnuarnav@microsoft.com>
- Loading branch information
1 parent
ad4a0dc
commit 93389d1
Showing
8 changed files
with
518 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: vk-e2e-initcontainers-order | ||
namespace: vk-test | ||
spec: | ||
initContainers: | ||
- image: alpine | ||
name: init-container-01 | ||
command: [ "/bin/sh" ] | ||
args: [ "-c", "echo Hi from init-container-01 >> /mnt/azure/newfile.txt" ] | ||
volumeMounts: | ||
- name: azure | ||
mountPath: /mnt/azure | ||
- image: alpine | ||
name: init-container-02 | ||
command: [ "/bin/sh" ] | ||
args: [ "-c", "echo Hi from init-container-02 >> /mnt/azure/newfile.txt" ] | ||
volumeMounts: | ||
- name: azure | ||
mountPath: /mnt/azure | ||
containers: | ||
- image: alpine | ||
imagePullPolicy: Always | ||
name: container | ||
command: [ | ||
"sh", | ||
"-c", | ||
"echo Hi from container >> /mnt/azure/newfile.txt; while sleep 10; do cat /mnt/azure/newfile.txt; done;" | ||
] | ||
resources: | ||
requests: | ||
memory: 1G | ||
cpu: 1 | ||
volumeMounts: | ||
- name: azure | ||
mountPath: /mnt/azure | ||
nodeSelector: | ||
kubernetes.io/role: agent | ||
beta.kubernetes.io/os: linux | ||
type: virtual-kubelet | ||
tolerations: | ||
- key: virtual-kubelet.io/provider | ||
operator: Exists | ||
volumes: | ||
- name: azure | ||
csi: | ||
driver: file.csi.azure.com | ||
volumeAttributes: | ||
secretName: csidriversecret # required | ||
shareName: vncsidriversharename # required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
|
||
package e2e | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
"io/ioutil" | ||
"os/exec" | ||
"os" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestPodWithInitContainersOrder(t *testing.T) { | ||
// delete the namespace first | ||
cmd := kubectl("delete", "namespace", "vk-test", "--ignore-not-found") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
|
||
// create namespace | ||
cmd = kubectl("apply", "-f", "fixtures/namespace.yml") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
|
||
testStorageAccount := os.Getenv("CSI_DRIVER_STORAGE_ACCOUNT_NAME") | ||
testStorageKey := os.Getenv("CSI_DRIVER_STORAGE_ACCOUNT_KEY") | ||
|
||
cmd = kubectl("create", "secret", "generic", "csidriversecret", "--from-literal", "azurestorageaccountname="+testStorageAccount, "--from-literal", "azurestorageaccountkey="+testStorageKey, "--namespace=vk-test") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
|
||
cmd = kubectl("apply", "-f", "fixtures/initcontainers_ordertest_pod.yml") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
deadline, ok := t.Deadline() | ||
timeout := time.Until(deadline) | ||
if !ok { | ||
timeout = 300 * time.Second | ||
} | ||
cmd = kubectl("wait", "--for=condition=ready", "--timeout="+timeout.String(), "pod/vk-e2e-initcontainers-order", "--namespace=vk-test") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
t.Log("success create pod") | ||
|
||
// query metrics | ||
deadline = time.Now().Add(10 * time.Minute) | ||
for { | ||
t.Log("query metrics ....") | ||
cmd = kubectl("get", "--raw", "/apis/metrics.k8s.io/v1beta1/namespaces/vk-test/pods/vk-e2e-initcontainers-order") | ||
out, err := cmd.CombinedOutput() | ||
if time.Now().After(deadline) { | ||
t.Fatal("failed to query pod's stats from metrics server API") | ||
} | ||
if err == nil { | ||
t.Logf("success query metrics %s", string(out)) | ||
break | ||
} | ||
time.Sleep(10 * time.Second) | ||
} | ||
|
||
// download file created by pod | ||
cmd = exec.Command("az", "storage", "file", "download", "--account-name", testStorageAccount, "--account-key", testStorageKey, "-s", "vncsidriversharename", "-p", "newfile.txt") | ||
cmd.Env = os.Environ() | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
t.Log("file newfile.txt downloaded from storage account") | ||
|
||
file, err := ioutil.ReadFile("newfile.txt") | ||
if err != nil { | ||
t.Fatal("could not read downloaded file") | ||
} | ||
t.Log("read file content successfully") | ||
|
||
fileContent := string(file) | ||
expectedString := "Hi from init-container-01\nHi from init-container-02\nHi from container\n" | ||
assert.Equal(t, fileContent, expectedString, "file content doesn't match expected value") | ||
|
||
// check pod status | ||
t.Log("get pod status ....") | ||
cmd = kubectl("get", "pod", "--field-selector=status.phase=Running", "--namespace=vk-test", "--output=jsonpath={.items..metadata.name}") | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
if string(out) != "vk-e2e-initcontainers-order" { | ||
t.Fatal("failed to get pod's status") | ||
} | ||
t.Logf("success query pod status %s", string(out)) | ||
|
||
// check container status | ||
t.Log("get container status ....") | ||
cmd = kubectl("get", "pod", "vk-e2e-initcontainers-order", "--namespace=vk-test", "--output=jsonpath={.status.containerStatuses[0].ready}") | ||
out, err = cmd.CombinedOutput() | ||
if err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
if string(out) != "true" { | ||
t.Fatal("failed to get pod's status") | ||
} | ||
t.Logf("success query container status %s", string(out)) | ||
|
||
t.Log("clean up pod") | ||
cmd = kubectl("delete", "namespace", "vk-test", "--ignore-not-found") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.