-
Notifications
You must be signed in to change notification settings - Fork 71
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
feat: Managed Identity support for Image Pull #240
base: master
Are you sure you want to change the base?
Changes from 107 commits
e979e99
bdf2cc1
1cc644e
6264659
a0530aa
7216493
1a4ed8f
df701e1
d846f64
ec26969
14c2f04
4f9b1e2
3c9d25a
b29a7c8
3b86b2f
8adcb62
c9cda56
cc98532
2039759
48fa251
8189ffa
e2aa4d1
e9eb315
e890b06
03ca373
fc2226e
4eabd8e
bfb5706
5f441ec
d69ed08
ec1c281
38e454f
fe5cbd1
a823e5f
884c479
583d23d
186a6fb
43df01a
d935e7c
093ca98
797c58e
a0ed92a
80e7dee
d6693be
f9bfbec
8545cad
bed4401
1ad2fdc
c2d3e42
f10e459
b93be3d
8a9a647
f75d623
3826ec7
571672c
5c441fd
3ad9e34
0e4734a
d29d133
2c14f20
965f9f7
3ef7bcf
a3ce27e
3f4853b
a36f2b6
87a65ab
1b824ac
8cde356
ff2dcec
9e0e2f6
ef82131
ff2a10c
3805c7b
705f196
8b19ebf
1f7213d
cb28310
0a7f3f5
4cdd3b1
0926639
8d46c25
b6cabe1
1ab605f
4179703
dece820
cc0c0dc
cbfae3a
0873ddb
003b90e
eeb525d
92e395b
3103aa6
19ed975
a31e328
94de42d
25a4c2e
8f6c7bf
57f5c40
735ac08
7759db4
fa28280
ffd61ed
f37fe30
e671ca5
2b235c4
faecc2c
89633db
64a7e37
d8fd3e8
356feeb
3d06794
8278fa7
f6624ec
34a45ca
84bb117
e531a87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
"context" | ||
|
||
"github.com/virtual-kubelet/azure-aci/pkg/featureflag" | ||
) | ||
|
||
func TestImagePullUsingKubeletIdentityMI(t *testing.T) { | ||
ctx := context.TODO() | ||
enabledFeatures := featureflag.InitFeatureFlag(ctx) | ||
if !enabledFeatures.IsEnabled(ctx, featureflag.ManagedIdentityPullFeature) { | ||
t.Skipf("%s feature is not enabled", featureflag.ManagedIdentityPullFeature) | ||
} | ||
// delete the pod 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)) | ||
} | ||
|
||
// run container group pulling image from acr using MI | ||
cmd = kubectl("apply", "-f", "fixtures/mi-pull-image-exec.yaml") | ||
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/e2etest-acr-test-mi-container", "--namespace=vk-test") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(string(out)) | ||
} | ||
t.Log("success pulling image from ACR using managed identity") | ||
|
||
// query metrics | ||
deadline = time.Now().Add(5 * time.Minute) | ||
for { | ||
t.Log("query metrics ....") | ||
cmd = kubectl("get", "--raw", "/apis/metrics.k8s.io/v1beta1/namespaces/vk-test/pods/e2etest-acr-test-mi-container") | ||
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 | ||
} | ||
} | ||
|
||
// 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) != "e2etest-acr-test-mi-container" { | ||
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", "e2etest-acr-test-mi-container", "--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)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: e2etest-acr-test-mi-container | ||
namespace: vk-test | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- image: ${ACR_NAME}.azurecr.io/library/alpine | ||
imagePullPolicy: Always | ||
name: e2etest-acr-test-mi-container | ||
command: [ | ||
"sh", | ||
"-c", | ||
"sleep 1; while sleep 1; do echo pulled image using mi; done", | ||
] | ||
resources: | ||
requests: | ||
memory: 1G | ||
cpu: 1 | ||
nodeSelector: | ||
kubernetes.io/role: agent | ||
beta.kubernetes.io/os: linux | ||
type: virtual-kubelet | ||
tolerations: | ||
- key: virtual-kubelet.io/provider | ||
operator: Exists |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,10 @@ if [ "$E2E_TARGET" = "pr" ]; then | |
|
||
fi | ||
|
||
az acr import --name ${ACR_NAME} --source docker.io/library/alpine:latest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current e2e workflow will create ACR only if we run it for PR. If the e2e tests run on MCR, ACR won't be created as we are using the MCR images. If you find it necessary to have ACR now, we can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to create ACR since this feature is specifically for adding support to pull images from ACR using kubelet-identity, without having to use username/password credentials. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then let's have one ACR instead of 2. |
||
export ACR_ID="$(az acr show --resource-group ${RESOURCE_GROUP} --name ${ACR_NAME} --query id -o tsv)" | ||
export ACR_NAME=${ACR_NAME} | ||
|
||
TMPDIR="$(mktemp -d)" | ||
|
||
az network vnet create \ | ||
|
@@ -209,4 +213,6 @@ CSI_DRIVER_STORAGE_ACCOUNT_KEY=$(az storage account keys list --resource-group " | |
export CSI_DRIVER_STORAGE_ACCOUNT_NAME=$CSI_DRIVER_STORAGE_ACCOUNT_NAME | ||
export CSI_DRIVER_STORAGE_ACCOUNT_KEY=$CSI_DRIVER_STORAGE_ACCOUNT_KEY | ||
|
||
envsubst < e2e/fixtures/mi-pull-image.yaml > e2e/fixtures/mi-pull-image-exec.yaml | ||
|
||
$@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please follow the same as the upgrade, etc docs? by creating a new file in the /docs folder and referring to it in this main one?