From f401342d8ff0db4788ccb334035b7d7f166c1077 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Sun, 15 Dec 2019 22:31:52 +0200 Subject: [PATCH] Update Protokube tests --- nodeup/pkg/model/protokube.go | 16 ++++- nodeup/pkg/model/protokube_test.go | 13 +++- .../tests/protokube/containerd/cluster.yaml | 60 +++++++++++++++++++ .../tests/protokube/containerd/tasks.yaml | 20 +++++++ .../model/tests/protokube/docker/cluster.yaml | 1 + .../model/tests/protokube/docker/tasks.yaml | 5 +- 6 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 nodeup/pkg/model/tests/protokube/containerd/cluster.yaml create mode 100644 nodeup/pkg/model/tests/protokube/containerd/tasks.yaml diff --git a/nodeup/pkg/model/protokube.go b/nodeup/pkg/model/protokube.go index d2ff38fcb7..0b5aa24388 100644 --- a/nodeup/pkg/model/protokube.go +++ b/nodeup/pkg/model/protokube.go @@ -239,8 +239,14 @@ func (t *ProtokubeBuilder) ProtokubeContainerRunCommand() (string, error) { }...) } + protokubeEnvVars := t.ProtokubeEnvironmentVariables() + if protokubeEnvVars != "" { + containerRunArgs = append(containerRunArgs, []string{ + protokubeEnvVars, + }...) + } + containerRunArgs = append(containerRunArgs, []string{ - t.ProtokubeEnvironmentVariables(), "--name", "protokube", t.ProtokubeImageName(), "/usr/bin/protokube", @@ -271,8 +277,14 @@ func (t *ProtokubeBuilder) ProtokubeContainerRunCommand() (string, error) { }...) } + protokubeEnvVars := t.ProtokubeEnvironmentVariables() + if protokubeEnvVars != "" { + containerRunArgs = append(containerRunArgs, []string{ + protokubeEnvVars, + }...) + } + containerRunArgs = append(containerRunArgs, []string{ - t.ProtokubeEnvironmentVariables(), "docker.io/library/" + t.ProtokubeImageName(), "protokube", "/usr/bin/protokube", diff --git a/nodeup/pkg/model/protokube_test.go b/nodeup/pkg/model/protokube_test.go index c6ed78f5da..6a9225d280 100644 --- a/nodeup/pkg/model/protokube_test.go +++ b/nodeup/pkg/model/protokube_test.go @@ -17,6 +17,7 @@ limitations under the License. package model import ( + "path" "testing" "k8s.io/kops/pkg/apis/kops" @@ -25,8 +26,16 @@ import ( "k8s.io/kops/upup/pkg/fi" ) -func TestProtokubeBuilder(t *testing.T) { - basedir := "tests/protokube/docker" +func TestProtokubeBuilder_Docker(t *testing.T) { + runProtokubeBuilderTest(t, "docker") +} + +func TestProtokubeBuilder_containerd(t *testing.T) { + runProtokubeBuilderTest(t, "containerd") +} + +func runProtokubeBuilderTest(t *testing.T, key string) { + basedir := path.Join("tests/protokube/", key) context := &fi.ModelBuilderContext{ Tasks: make(map[string]fi.Task), diff --git a/nodeup/pkg/model/tests/protokube/containerd/cluster.yaml b/nodeup/pkg/model/tests/protokube/containerd/cluster.yaml new file mode 100644 index 0000000000..dcb956258a --- /dev/null +++ b/nodeup/pkg/model/tests/protokube/containerd/cluster.yaml @@ -0,0 +1,60 @@ +apiVersion: kops.k8s.io/v1alpha2 +kind: Cluster +metadata: + creationTimestamp: "2016-12-10T22:42:27Z" + name: minimal.example.com +spec: + kubernetesApiAccess: + - 0.0.0.0/0 + channel: stable + cloudProvider: aws + configBase: memfs://clusters.example.com/minimal.example.com + containerRuntime: containerd + etcdClusters: + - etcdMembers: + - instanceGroup: master-us-test-1a + name: master-us-test-1a + name: main + provider: Manager + - etcdMembers: + - instanceGroup: master-us-test-1a + name: master-us-test-1a + name: events + provider: Manager + kubelet: {} + kubernetesVersion: v1.17.0 + masterInternalName: api.internal.minimal.example.com + masterPublicName: api.minimal.example.com + networkCIDR: 172.20.0.0/16 + networking: + kubenet: {} + nonMasqueradeCIDR: 100.64.0.0/10 + sshAccess: + - 0.0.0.0/0 + topology: + masters: public + nodes: public + subnets: + - cidr: 172.20.32.0/19 + name: us-test-1a + type: Public + zone: us-test-1a + +--- + +apiVersion: kops.k8s.io/v1alpha2 +kind: InstanceGroup +metadata: + creationTimestamp: "2016-12-10T22:42:28Z" + name: nodes + labels: + kops.k8s.io/cluster: minimal.example.com +spec: + associatePublicIp: true + image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 + machineType: t2.medium + maxSize: 2 + minSize: 2 + role: Node + subnets: + - us-test-1a diff --git a/nodeup/pkg/model/tests/protokube/containerd/tasks.yaml b/nodeup/pkg/model/tests/protokube/containerd/tasks.yaml new file mode 100644 index 0000000000..0cface88e1 --- /dev/null +++ b/nodeup/pkg/model/tests/protokube/containerd/tasks.yaml @@ -0,0 +1,20 @@ +Name: protokube.service +definition: | + [Unit] + Description=Kubernetes Protokube Service + Documentation=https://github.com/kubernetes/kops + + [Service] + ExecStartPre=-/usr/bin/ctr --namespace k8s.io task pause protokube + ExecStartPre=-/usr/bin/ctr --namespace k8s.io container rm protokube + ExecStart=/usr/bin/ctr --namespace k8s.io run --net-host --with-ns pid:/proc/1/ns/pid --privileged --mount type=bind,src=/,dst=/rootfs,options=rbind:rslave --mount type=bind,src=/var/run/dbus,dst=/var/run/dbus,options=rbind:rprivate --mount type=bind,src=/run/systemd,dst=/run/systemd,options=rbind:rprivate --env KUBECONFIG=/rootfs/var/lib/kops/kubeconfig --mount type=bind,src=/usr/local/bin,dst=/opt/kops/bin,options=rbind:ro:rprivate --env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/kops/bin docker.io/library/protokube:test protokube /usr/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --containerized=true --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --initialize-rbac=true --manage-etcd=false --master=true --node-name=example-hostname --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 + Restart=always + RestartSec=2s + StartLimitInterval=0 + + [Install] + WantedBy=multi-user.target +enabled: true +manageState: true +running: true +smartRestart: true diff --git a/nodeup/pkg/model/tests/protokube/docker/cluster.yaml b/nodeup/pkg/model/tests/protokube/docker/cluster.yaml index 046a2caca2..127d0c8adf 100644 --- a/nodeup/pkg/model/tests/protokube/docker/cluster.yaml +++ b/nodeup/pkg/model/tests/protokube/docker/cluster.yaml @@ -9,6 +9,7 @@ spec: channel: stable cloudProvider: aws configBase: memfs://clusters.example.com/minimal.example.com + containerRuntime: docker etcdClusters: - etcdMembers: - instanceGroup: master-us-test-1a diff --git a/nodeup/pkg/model/tests/protokube/docker/tasks.yaml b/nodeup/pkg/model/tests/protokube/docker/tasks.yaml index bf63800e0d..30bd9a9a52 100644 --- a/nodeup/pkg/model/tests/protokube/docker/tasks.yaml +++ b/nodeup/pkg/model/tests/protokube/docker/tasks.yaml @@ -5,8 +5,9 @@ definition: | Documentation=https://github.com/kubernetes/kops [Service] - ExecStartPre=/bin/true - ExecStart=/usr/bin/docker run -v /:/rootfs/ -v /var/run/dbus:/var/run/dbus -v /run/systemd:/run/systemd -v /usr/local/bin:/opt/kops/bin:ro --env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/kops/bin --net=host --pid=host --privileged --env KUBECONFIG=/rootfs/var/lib/kops/kubeconfig protokube:test /usr/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --containerized=true --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --initialize-rbac=true --manage-etcd=false --master=true --node-name=example-hostname --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 + ExecStartPre=-/usr/bin/docker stop protokube + ExecStartPre=-/usr/bin/docker rm protokube + ExecStart=/usr/bin/docker run --net=host --pid=host --privileged --volume /:/rootfs/ --volume /var/run/dbus:/var/run/dbus --volume /run/systemd:/run/systemd --env KUBECONFIG=/rootfs/var/lib/kops/kubeconfig --volume /usr/local/bin:/opt/kops/bin:ro --env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/kops/bin --name protokube protokube:test /usr/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --containerized=true --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --initialize-rbac=true --manage-etcd=false --master=true --node-name=example-hostname --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 Restart=always RestartSec=2s StartLimitInterval=0