Add test for protokube builder

This should give us some assurances that we haven't changed things too
much with the containerd introduction.
This commit is contained in:
Justin Santa Barbara 2019-12-14 22:11:17 -05:00
parent c54394c0e3
commit 700bd2c0a5
3 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,71 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package model
import (
"testing"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/nodeup"
"k8s.io/kops/pkg/testutils"
"k8s.io/kops/upup/pkg/fi"
)
func TestProtokubeBuilder(t *testing.T) {
basedir := "tests/protokube/docker"
context := &fi.ModelBuilderContext{
Tasks: make(map[string]fi.Task),
}
nodeUpModelContext, err := BuildNodeupModelContext(basedir)
if err != nil {
t.Fatalf("error loading model %q: %v", basedir, err)
return
}
cluster := nodeupModelContext.Cluster
if cluster.Spec.MasterKubelet == nil {
cluster.Spec.MasterKubelet = &kops.KubeletConfigSpec{}
}
if cluster.Spec.MasterKubelet == nil {
cluster.Spec.MasterKubelet = &kops.KubeletConfigSpec{}
}
cluster.Spec.Kubelet.HostnameOverride = "example-hostname"
nodeUpModelContext.IsMaster = true
nodeUpModelContext.NodeupConfig = &nodeup.Config{}
// These trigger use of etcd-manager
nodeUpModelContext.NodeupConfig.EtcdManifests = []string{
"memfs://clusters.example.com/minimal.example.com/manifests/etcd/main.yaml",
"memfs://clusters.example.com/minimal.example.com/manifests/etcd/events.yaml",
}
nodeUpModelContext.NodeupConfig.ProtokubeImage = &nodeup.Image{}
nodeUpModelContext.NodeupConfig.ProtokubeImage.Name = "protokube:test"
builder := &ProtokubeBuilder{NodeupModelContext: nodeUpModelContext}
if task, err := builder.buildSystemdService(); err != nil {
t.Fatalf("error from buildSystemdService: %v", err)
} else {
context.AddTask(task)
}
testutils.ValidateTasks(t, basedir, context)
}

View File

@ -0,0 +1,59 @@
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
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

View File

@ -0,0 +1,19 @@
Name: protokube.service
definition: |
[Unit]
Description=Kubernetes Protokube Service
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
Restart=always
RestartSec=2s
StartLimitInterval=0
[Install]
WantedBy=multi-user.target
enabled: true
manageState: true
running: true
smartRestart: true