10BC0 Merge pull request #74738 from wk8/wk8/gmsa_e2e · kubernetes/kubernetes@96ee0d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 96ee0d0

Browse files
authored
Merge pull request #74738 from wk8/wk8/gmsa_e2e
Adding an e2e test on Windows GMSA support
2 parents b7bf26a + b721f8e commit 96ee0d0

File tree

5 files changed

+170
-9
lines changed

5 files changed

+170
-9
lines changed

test/e2e/windows/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
srcs = [
88
"density.go",
99
"framework.go",
10+
"gmsa.go",
1011
"hybrid_network.go",
1112
"memory_limits.go",
1213
"networking.go",

test/e2e/windows/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```bash
66
KUBECONFIG=path/to/kubeconfig
7-
curl https://raw.githubusercontent.com/e2e-win/e2e-win-prow-deployment/master/repo-list -o repo_list
7+
curl https://raw.githubusercontent.com/kubernetes-sigs/windows-testing/master/images/image-repo-list -o repo_list
88
export KUBE_TEST_REPO_LIST=$(pwd)/repo_list
99
```
1010

test/e2e/windows/density.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ import (
3737
)
3838

3939
var _ = SIGDescribe("[Feature:Windows] Density [Serial] [Slow]", func() {
40-
4140
f := framework.NewDefaultFramework("density-test-windows")
4241

43-
ginkgo.BeforeEach(func() {
44-
// NOTE(vyta): these tests are Windows specific
45-
framework.SkipUnlessNodeOSDistroIs("windows")
46-
})
47-
4842
ginkgo.Context("create a batch of pods", func() {
4943
// TODO(coufon): the values are generous, set more precise limits with benchmark data
5044
// and add more tests

test/e2e/windows/framework.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ limitations under the License.
1616

1717
package windows
1818

19-
import "github.com/onsi/ginkgo"
19+
import (
20+
"k8s.io/kubernetes/test/e2e/framework"
21+
22+
"github.com/onsi/ginkgo"
23+
)
2024

2125
// SIGDescribe annotates the test with the SIG label.
2226
func SIGDescribe(text string, body func()) bool {
23-
return ginkgo.Describe("[sig-windows] "+text, body)
27+
return ginkgo.Describe("[sig-windows] "+text, func() {
28+
ginkgo.BeforeEach(func() {
29+
// all tests in this package are Windows specific
30+
framework.SkipUnlessNodeOSDistroIs("windows")
31+
})
32+
33+
body()
34+
})
2435
}

test/e2e/windows/gmsa.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package windows
18+
19+
import (
20+
"fmt"
21+
"strings"
22+
"time"
23+
24+
corev1 "k8s.io/api/core/v1"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/kubernetes/test/e2e/framework"
27+
imageutils "k8s.io/kubernetes/test/utils/image"
28+
29+
"github.com/onsi/ginkgo"
30+
"github.com/onsi/gomega"
31+
)
32+
33+
var _ = SIGDescribe("[Feature:Windows] [Feature:WindowsGMSA] GMSA [Slow]", func() {
34+
f := framework.NewDefaultFramework("gmsa-test-windows")
35+
36+
ginkgo.Describe("kubelet GMSA support", func() {
37+
ginkgo.Context("when creating a pod with correct GMSA credential specs", func() {
38+
ginkgo.It("passes the credential specs down to the Pod's containers", func() {
39+
defer ginkgo.GinkgoRecover()
40+
41+
podName := "with-correct-gmsa-annotations"
42+
43+
container1Name := "container1"
44+
podDomain := "acme.com"
45+
46+
container2Name := "container2"
47+
container2Domain := "contoso.org"
48+
49+
containers := make([]corev1.Container, 2)
50+
for i, name := range []string{container1Name, container2Name} {
51+
containers[i] = corev1.Container{
52+
Name: name,
53+
Image: imageutils.GetPauseImageName(),
54+
}
55+
}
56+
57+
pod := &corev1.Pod{
58+
ObjectMeta: metav1.ObjectMeta{
59+
Name: podName,
60+
Annotations: map[string]string{
61+
"pod.alpha.windows.kubernetes.io/gmsa-credential-spec": generateDummyCredSpecs(podDomain),
62+
container2Name + ".container.alpha.windows.kubernetes.io/gmsa-credential-sp 6DAE ec": generateDummyCredSpecs(container2Domain),
63+
},
64+
},
65+
Spec: corev1.PodSpec{
66+
Containers: containers,
67+
},
68+
}
69+
70+
ginkgo.By("creating a pod with correct GMSA annotations")
71+
f.PodClient().Create(pod)
72+
73+
ginkgo.By("waiting for the pod and its containers to be running")
74+
gomega.Eventually(func() bool {
75+
pod, err := f.PodClient().Get(podName, metav1.GetOptions{})
76+
if err != nil && pod.Status.Phase != corev1.PodRunning {
77+
return false
78+
}
79+
80+
for _, containerStatus := range pod.Status.ContainerStatuses {
81< 9E12 code class="diff-text syntax-highlighted-line addition">+
if containerStatus.State.Running == nil {
82+
return false
83+
}
84+
}
85+
86+
return true
87+
}, 5*time.Minute, 1*time.Second).Should(gomega.BeTrue())
88+
89+
ginkgo.By("checking the domain reported by nltest in the containers")
90+
namespaceOption := fmt.Sprintf("--namespace=%s", f.Namespace.Name)
91+
for containerName, domain := range map[string]string{
92+
container1Name: podDomain,
93+
container2Name: container2Domain,
94+
} {
95+
var (
96+
output string
97+
err error
98+
)
99+
100+
containerOption := fmt.Sprintf("--container=%s", containerName)
101+
// even for bogus creds, `nltest /PARENTDOMAIN` simply returns the AD domain, which is enough for our purpose here.
102+
// note that the "eventually" part seems to be needed to account for the fact that powershell containers
103+
// are a bit slow to become responsive, even when docker reports them as running.
104+
gomega.Eventually(func() bool {
105+
output, err = framework.RunKubectl("exec", namespaceOption, podName, containerOption, "--", "nltest", "/PARENTDOMAIN")
106+
return err == nil
107+
}, 1*time.Minute, 1*time.Second).Should(gomega.BeTrue())
108+
109+
if !strings.HasPrefix(output, domain) {
110+
framework.Failf("Expected %q to start with %q", output, domain)
111+
}
112+
113+
expectedSubstr := "The command completed successfully"
114+
if !strings.Contains(output, expectedSubstr) {
115+
framework.Failf("Expected %q to contain %q", output, expectedSubstr)
116+
}
117+
}
118+
119+
// If this was an e2e_node test, we could also check that the registry keys used to pass down the cred specs to Docker
120+
// have been properly cleaned up - but as of right now, e2e_node tests don't support Windows. We should migrate this
121+
// test to an e2e_node test when they start supporting Windows.
122+
})
123+
})
124+
})
125+
})
126+
127+
func generateDummyCredSpecs(domain string) string {
128+
shortName := strings.ToUpper(strings.Split(domain, ".")[0])
129+
130+
return fmt.Sprintf(`{
131+
"ActiveDirectoryConfig":{
132+
"GroupManagedServiceAccounts":[
133+
{
134+
"Name":"WebApplication",
135+
"Scope":"%s"
136+
},
137+
{
138+
"Name":"WebApplication",
139+
"Scope":"%s"
140+
}
141+
]
142+
},
143+
"CmsPlugins":[
144+
"ActiveDirectory"
145+
],
146+
"DomainJoinConfig":{
147+
"DnsName":"%s",
148+
"DnsTreeName":"%s",
149+
"Guid":"244818ae-87ca-4fcd-92ec-e79e5252348a",
150+
"MachineAccountName":"WebApplication",
151+
"NetBiosName":"%s",
152+
"Sid":"S-1-5-21-2126729477-2524175714-3194792973"
153+
}
154+
}`, shortName, domain, domain, domain, shortName)
155+
}

0 commit comments

Comments
 (0)
0