Skip to content

Commit e265afa

Browse files
authored
Merge pull request kubernetes#81170 from claudiubelu/test-images/centralize-image-to-agnhost-part-4
Centralizes images into agnhost (part 4)
2 parents 1c51c44 + 8f09901 commit e265afa

File tree

33 files changed

+489
-348
lines changed

33 files changed

+489
-348
lines changed

test/images/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ filegroup(
1515
"//test/images/apparmor-loader:all-srcs",
1616
"//test/images/echoserver:all-srcs",
1717
"//test/images/metadata-concealment:all-srcs",
18-
"//test/images/mounttest:all-srcs",
1918
"//test/images/nonewprivs:all-srcs",
2019
"//test/images/pets/peer-finder:all-srcs",
2120
"//test/images/regression-issue-74839:all-srcs",
2221
"//test/images/resource-consumer:all-srcs",
23-
"//test/images/resource-consumer-controller:all-srcs",
2422
"//test/images/sample-apiserver:all-srcs",
2523
"//test/images/sample-device-plugin:all-srcs",
26-
"//test/images/test-webserver:all-srcs",
2724
],
2825
tags = ["automanaged"],
2926
)

test/images/agnhost/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ go_library(
2626
"//test/images/agnhost/inclusterclient:go_default_library",
2727
"//test/images/agnhost/liveness:go_default_library",
2828
"//test/images/agnhost/logs-generator:go_default_library",
29+
"//test/images/agnhost/mounttest:go_default_library",
2930
"//test/images/agnhost/net:go_default_library",
3031
"//test/images/agnhost/netexec:go_default_library",
3132
"//test/images/agnhost/nettest:go_default_library",
@@ -34,7 +35,9 @@ go_library(
3435
"//test/images/agnhost/pause:go_default_library",
3536
"//test/images/agnhost/port-forward-tester:go_default_library",
3637
"//test/images/agnhost/porter:go_default_library",
38+
"//test/images/agnhost/resource-consumer-controller:go_default_library",
3739
"//test/images/agnhost/serve-hostname:go_default_library",
40+
"//test/images/agnhost/test-webserver:go_default_library",
3841
"//test/images/agnhost/webhook:go_default_library",
3942
"//vendor/github.com/spf13/cobra:go_default_library",
4043
"//vendor/k8s.io/klog:go_default_library",
@@ -62,6 +65,7 @@ filegroup(
6265
"//test/images/agnhost/inclusterclient:all-srcs",
6366
"//test/images/agnhost/liveness:all-srcs",
6467
"//test/images/agnhost/logs-generator:all-srcs",
68+
"//test/images/agnhost/mounttest:all-srcs",
6569
"//test/images/agnhost/net:all-srcs",
6670
"//test/images/agnhost/netexec:all-srcs",
6771
"//test/images/agnhost/nettest:all-srcs",
@@ -70,7 +74,9 @@ filegroup(
7074
"//test/images/agnhost/pause:all-srcs",
7175
"//test/images/agnhost/port-forward-tester:all-srcs",
7276
"//test/images/agnhost/porter:all-srcs",
77+
"//test/images/agnhost/resource-consumer-controller:all-srcs",
7378
"//test/images/agnhost/serve-hostname:all-srcs",
79+
"//test/images/agnhost/test-webserver:all-srcs",
7480
"//test/images/agnhost/webhook:all-srcs",
7581
],
7682
tags = ["automanaged"],

test/images/agnhost/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ FROM BASEIMAGE
1616

1717
CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/
1818

19+
# from dnsutils image
20+
# install necessary packages:
21+
# - bind-tools: contains dig, which can used in DNS tests.
22+
# - CoreDNS: used in some DNS tests.
1923
# from hostexec image
2024
# install necessary packages:
2125
# - curl, nc: used by a lot of e2e tests
@@ -26,10 +30,14 @@ RUN apk --update add bind-tools curl netcat-openbsd iproute2 iperf bash && rm -r
2630
&& ln -s /usr/bin/iperf /usr/local/bin/iperf \
2731
&& ls -altrh /usr/local/bin/iperf
2832

29-
# PORT 8080 needed by: netexec, nettest
33+
ADD https://github.com/coredns/coredns/releases/download/v1.6.2/coredns_1.6.2_linux_BASEARCH.tgz /coredns.tgz
34+
RUN tar -xzvf /coredns.tgz && rm -f /coredns.tgz
35+
36+
# PORT 80 needed by: test-webserver
37+
# PORT 8080 needed by: netexec, nettest, resource-consumer, resource-consumer-controller
3038
# PORT 8081 needed by: netexec
3139
# PORT 9376 needed by: serve-hostname
32-
EXPOSE 8080 8081 9376
40+
EXPOSE 80 8080 8081 9376
3341

3442
# from netexec
3543
RUN mkdir /uploads

test/images/agnhost/README.md

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For example, let's consider the following `pod.yaml` file:
4040
containers:
4141
- args:
4242
- dns-suffix
43-
image: gcr.io/kubernetes-e2e-test-images/agnhost:2.8
43+
image: gcr.io/kubernetes-e2e-test-images/agnhost:2.9
4444
name: agnhost
4545
dnsConfig:
4646
nameservers:
@@ -290,21 +290,52 @@ Examples:
290290

291291
```console
292292
docker run -i \
293-
gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
293+
gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
294294
logs-generator --log-lines-total 10 --run-duration 1s
295295
```
296296

297297
```console
298298
kubectl run logs-generator \
299299
--generator=run-pod/v1 \
300-
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
300+
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
301301
--restart=Never \
302302
-- logs-generator -t 10 -d 1s
303303
```
304304

305305
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/logs-generator/README.md?pixel)]()
306306

307307

308+
### mounttest
309+
310+
The `mounttest` subcommand can be used to create files with various permissions, read files,
311+
and output file system type, mode, owner, and permissions for any given file.
312+
313+
The subcommand can accept the following flags:
314+
315+
- `fs_type`: Path to print the FS type for.
316+
- `file_mode`: Path to print the mode bits of.
317+
- `file_perm`: Path to print the perms of.
318+
- `file_owner`: Path to print the owning UID and GID of.
319+
- `new_file_0644`: Path to write to and read from with perm 0644.
320+
- `new_file_0666`: Path to write to and read from with perm 0666.
321+
- `new_file_0660`: Path to write to and read from with perm 0660.
322+
- `new_file_0777`: Path to write to and read from with perm 0777.
323+
- `file_content`: Path to read the file content from.
324+
- `file_content_in_loop`: Path to read the file content in loop from.
325+
- `retry_time` (default: 180): Retry time during the loop.
326+
- `break_on_expected_content` (default: true): Break out of loop on expected content (use with `--file_content_in_loop` flag only).
327+
328+
Usage:
329+
330+
```console
331+
kubectl exec test-agnhost -- /agnhost mounttest \
332+
[--fs_type <path>] [--file_mode <path>] [--file_perm <path>] [--file_owner <path>] \
333+
[--new_file_0644 <path>] [--new_file_0666 <path>] [--new_file_0660 <path>] [--new_file_0777 <path>] \
334+
[--file_content <path>] [--file_content_in_loop <path>] \
335+
[--retry_time <seconds>] [--break_on_expected_content <true_or_false>]
336+
```
337+
338+
308339
### net
309340

310341
The goal of this Go project is to consolidate all low-level
@@ -424,7 +455,7 @@ Usage:
424455
```console
425456
kubectl run test-agnhost \
426457
--generator=run-pod/v1 \
427-
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
458+
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
428459
--restart=Never \
429460
--env "POD_IP=<POD_IP>" \
430461
--env "NODE_IP=<NODE_IP>" \
@@ -479,7 +510,7 @@ Usage:
479510
```console
480511
kubectl run test-agnhost \
481512
--generator=run-pod/v1 \
482-
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
513+
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
483514
--restart=Never \
484515
--env "BIND_ADDRESS=localhost" \
485516
--env "BIND_PORT=8080" \
@@ -517,6 +548,25 @@ Usage:
517548
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/porter/README.md?pixel)]()
518549

519550

551+
### resource-consumer-controller
552+
553+
This subcommand starts an HTTP server that spreads requests around resource consumers. The HTTP server has the same endpoints and usage as the one spawned by the ``resource-consumer`` subcommand.
554+
555+
The subcommand can accept the following flags:
556+
557+
- `port` (default: 8080): The port number to listen to.
558+
- `consumer-port` (default: 8080): Port number of consumers.
559+
- `consumer-service-name` (default: `resource-consumer`): Name of service containing resource consumers.
560+
- `consumer-service-namespace` (default: `default`): Namespace of service containing resource consumers.
561+
562+
Usage:
563+
564+
```console
565+
kubectl exec test-agnhost -- /agnhost resource-consumer-controller \
566+
[--port <port>] [--consumer-port <port>] [--consumer-service-name <service-name>] [--consumer-service-namespace <namespace>]
567+
```
568+
569+
520570
### serve-hostname
521571

522572
This is a small util app to serve your hostname on TCP and/or UDP. Useful for testing.
@@ -542,6 +592,21 @@ Usage:
542592
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/serve_hostname/README.md?pixel)]()
543593

544594

595+
### test-webserver
596+
597+
Starts a simple HTTP fileserver which serves any file specified in the URL path, if it exists.
598+
599+
The subcommand can accept the following flags:
600+
601+
- `port` (default: `80`): The port number to listen to.
602+
603+
Usage:
604+
605+
```console
606+
kubectl exec test-agnhost -- /agnhost test-webserver [--port <port>]
607+
```
608+
609+
545610
### webhook (Kubernetes External Admission Webhook)
546611

547612
The subcommand tests MutatingAdmissionWebhook and ValidatingAdmissionWebhook. After deploying
@@ -561,11 +626,11 @@ Usage:
561626

562627
## Other tools
563628

564-
The image contains `iperf`.
629+
The image contains `iperf`, `curl`, `dns-tools` (including `dig`), CoreDNS.
565630

566631

567632
## Image
568633

569-
The image can be found at `gcr.io/kubernetes-e2e-test-images/agnhost:2.8` for Linux
634+
The image can be found at `gcr.io/kubernetes-e2e-test-images/agnhost:2.9` for Linux
570635
containers, and `e2eteam/agnhost:2.8` for Windows containers. In the future, the same
571636
repository can be used for both OSes.

test/images/agnhost/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8
1+
2.9

test/images/agnhost/agnhost.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/kubernetes/test/images/agnhost/inclusterclient"
3333
"k8s.io/kubernetes/test/images/agnhost/liveness"
3434
"k8s.io/kubernetes/test/images/agnhost/logs-generator"
35+
"k8s.io/kubernetes/test/images/agnhost/mounttest"
3536
"k8s.io/kubernetes/test/images/agnhost/net"
3637
"k8s.io/kubernetes/test/images/agnhost/netexec"
3738
"k8s.io/kubernetes/test/images/agnhost/nettest"
@@ -40,12 +41,14 @@ import (
4041
"k8s.io/kubernetes/test/images/agnhost/pause"
4142
"k8s.io/kubernetes/test/images/agnhost/port-forward-tester"
4243
"k8s.io/kubernetes/test/images/agnhost/porter"
44+
"k8s.io/kubernetes/test/images/agnhost/resource-consumer-controller"
4345
"k8s.io/kubernetes/test/images/agnhost/serve-hostname"
46+
"k8s.io/kubernetes/test/images/agnhost/test-webserver"
4447
"k8s.io/kubernetes/test/images/agnhost/webhook"
4548
)
4649

4750
func main() {
48-
rootCmd := &cobra.Command{Use: "app", Version: "2.8"}
51+
rootCmd := &cobra.Command{Use: "app", Version: "2.9"}
4952

5053
rootCmd.AddCommand(auditproxy.CmdAuditProxy)
5154
rootCmd.AddCommand(connect.CmdConnect)
@@ -59,6 +62,7 @@ func main() {
5962
rootCmd.AddCommand(inclusterclient.CmdInClusterClient)
6063
rootCmd.AddCommand(liveness.CmdLiveness)
6164
rootCmd.AddCommand(logsgen.CmdLogsGenerator)
65+
rootCmd.AddCommand(mounttest.CmdMounttest)
6266
rootCmd.AddCommand(net.CmdNet)
6367
rootCmd.AddCommand(netexec.CmdNetexec)
6468
rootCmd.AddCommand(nettest.CmdNettest)
@@ -67,7 +71,9 @@ func main() {
6771
rootCmd.AddCommand(pause.CmdPause)
6872
rootCmd.AddCommand(porter.CmdPorter)
6973
rootCmd.AddCommand(portforwardtester.CmdPortForwardTester)
74+
rootCmd.AddCommand(resconsumerctrl.CmdResourceConsumerController)
7075
rootCmd.AddCommand(servehostname.CmdServeHostname)
76+
rootCmd.AddCommand(testwebserver.CmdTestWebserver)
7177
rootCmd.AddCommand(webhook.CmdWebhook)
7278

7379
// NOTE(claudiub): Some tests are passing logging related flags, so we need to be able to

test/images/mounttest/BUILD renamed to test/images/agnhost/mounttest/BUILD

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package(default_visibility = ["//visibility:public"])
22

33
load(
44
"@io_bazel_rules_go//go:def.bzl",
5-
"go_binary",
65
"go_library",
76
)
87

98
go_library(
109
name = "go_default_library",
11-
srcs = ["mt.go"],
12-
importpath = "k8s.io/kubernetes/test/images/mounttest",
10+
srcs = [
11+
"mt.go",
12+
"mt_utils.go",
13+
"mt_utils_windows.go",
14+
],
15+
importpath = "k8s.io/kubernetes/test/images/agnhost/mounttest",
16+
deps = ["//vendor/github.com/spf13/cobra:go_default_library"],
1317
)
1418

1519
filegroup(
@@ -24,8 +28,3 @@ filegroup(
2428
srcs = [":package-srcs"],
2529
tags = ["automanaged"],
2630
)
27-
28-
go_binary(
29-
name = "mounttest",
30-
embed = [":go_default_library"],
31-
)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
Param(
16+
[string]$FileName = $(throw "-FileName is required.")
17+
)
18+
19+
20+
# read = read data | read attributes
21+
$READ_PERMISSIONS = 0x0001 -bor 0x0080
22+
23+
# write = write data | append data | write attributes | write EA
24+
$WRITE_PERMISSIONS = 0x0002 -bor 0x0004 -bor 0x0100 -bor 0x0010
25+
26+
# execute = read data | file execute
27+
$EXECUTE_PERMISSIONS = 0x0001 -bor 0x0020
28+
29+
30+
function GetFilePermissions($path) {
31+
$objPath = "Win32_LogicalFileSecuritySetting='$path'"
32+
$output = Invoke-WmiMethod -Namespace root/cimv2 -Path $objPath -Name GetSecurityDescriptor
33+
34+
if ($output.ReturnValue -ne 0) {
35+
$retVal = $output.ReturnValue
36+
Write-Error "GetSecurityDescriptor invocation failed with code: $retVal"
37+
exit 1
38+
}
39+
40+
$fileSD = $output.Descriptor
41+
$fileOwnerGroup = $fileSD.Group
42+
$fileOwner = $fileSD.Owner
43+
44+
if ($fileOwnerGroup.Name -eq $null -and $fileOwnerGroup.Domain -eq $null) {
45+
# the file owner's group is not recognized. Check if the Owner itself is
46+
# a group, and if so, default the group to it.
47+
net user $fileOwner.Name > $null 2> $null
48+
if (-not $?) {
49+
$fileOwnerGroup = $fileOwner
50+
}
51+
52+
}
53+
54+
$userMask = 0
55+
$groupMask = 0
56+
$otherMask = 0
57+
58+
foreach ($ace in $fileSD.DACL) {
59+
$mask = 0
60+
if ($ace.AceType -ne 0) {
61+
# not an Allow ACE, skip.
62+
continue
63+
}
64+
65+
# convert mask.
66+
if ( ($ace.AccessMask -band $READ_PERMISSIONS) -eq $READ_PERMISSIONS ) {
67+
$mask = $mask -bor 4
68+
}
69+
if ( ($ace.AccessMask -band $WRITE_PERMISSIONS) -eq $WRITE_PERMISSIONS ) {
70+
$mask = $mask -bor 2
71+
}
72+
if ( ($ace.AccessMask -band $EXECUTE_PERMISSIONS) -eq $EXECUTE_PERMISSIONS ) {
73+
$mask = $mask -bor 1
74+
}
75+
76+
# detect mask type.
77+
if ($ace.Trustee.Equals($fileOwner)) {
78+
$userMask = $mask
79+
}
80+
if ($ace.Trustee.Equals($fileOwnerGroup)) {
81+
$groupMask = $mask
82+
}
83+
if ($ace.Trustee.Name.ToLower() -eq "users") {
84+
$otherMask = $mask
85+
}
86+
}
87+
88+
return "$userMask$groupMask$otherMask"
89+
}
90+
91+
$mask = GetFilePermissions($FileName)
92+
if (-not $?) {
93+
exit 1
94+
}
95+
96+
# print the permission mask Linux-style.
97+
echo "0$mask"

0 commit comments

Comments
 (0)