mirror of https://github.com/kubernetes/kops.git
Add tests for docker nodeup side
This commit is contained in:
parent
a46f1109ce
commit
2f256b9d39
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
Copyright 2016 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 (
|
||||||
|
"io/ioutil"
|
||||||
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/pkg/diff"
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"path"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
// Register our APIs
|
||||||
|
_ "k8s.io/kops/pkg/apis/kops/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDockerBuilder(t *testing.T) {
|
||||||
|
runDockerBuilderTest(t, "simple")
|
||||||
|
runDockerBuilderTest(t, "docker_1.12.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func runDockerBuilderTest(t *testing.T, key string) {
|
||||||
|
basedir := path.Join("tests/dockerbuilder/", key)
|
||||||
|
|
||||||
|
clusterYamlPath := path.Join(basedir, "cluster.yaml")
|
||||||
|
clusterYaml, err := ioutil.ReadFile(clusterYamlPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error reading cluster yaml file %q: %v", clusterYamlPath, err)
|
||||||
|
}
|
||||||
|
obj, _, err := kops.ParseVersionedYaml(clusterYaml)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error parsing cluster yaml %q: %v", clusterYamlPath, err)
|
||||||
|
}
|
||||||
|
cluster := obj.(*kops.Cluster)
|
||||||
|
|
||||||
|
context := &fi.ModelBuilderContext{
|
||||||
|
Tasks: make(map[string]fi.Task),
|
||||||
|
}
|
||||||
|
nodeUpModelContext := &NodeupModelContext{
|
||||||
|
Cluster: cluster,
|
||||||
|
Architecture: "amd64",
|
||||||
|
Distribution: DistributionXenial,
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := DockerBuilder{NodeupModelContext: nodeUpModelContext}
|
||||||
|
|
||||||
|
err = builder.Build(context)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error from DockerBuilder Build: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys []string
|
||||||
|
for key := range context.Tasks {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
var yamls []string
|
||||||
|
for _, key := range keys {
|
||||||
|
task := context.Tasks[key]
|
||||||
|
yaml, err := kops.ToRawYaml(task)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error serializing task: %v", err)
|
||||||
|
}
|
||||||
|
yamls = append(yamls, strings.TrimSpace(string(yaml)))
|
||||||
|
}
|
||||||
|
|
||||||
|
actualTasksYaml := strings.Join(yamls, "\n---\n")
|
||||||
|
|
||||||
|
tasksYamlPath := path.Join(basedir, "tasks.yaml")
|
||||||
|
expectedTasksYaml, err := ioutil.ReadFile(tasksYamlPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error reading file %q: %v", tasksYamlPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(string(expectedTasksYaml)) != strings.TrimSpace(actualTasksYaml) {
|
||||||
|
diffString := diff.FormatDiff(string(expectedTasksYaml), actualTasksYaml)
|
||||||
|
t.Logf("diff:\n%s\n", diffString)
|
||||||
|
|
||||||
|
t.Fatalf("tasks differed from expected for test %q", key)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
apiVersion: kops/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
|
||||||
|
- etcdMembers:
|
||||||
|
- instanceGroup: master-us-test-1a
|
||||||
|
name: master-us-test-1a
|
||||||
|
name: events
|
||||||
|
kubernetesVersion: v1.4.6
|
||||||
|
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
|
||||||
|
docker:
|
||||||
|
version: 1.12.1
|
|
@ -0,0 +1,18 @@
|
||||||
|
contents: {}
|
||||||
|
path: /usr/share/doc/docker/apache.txt
|
||||||
|
type: file
|
||||||
|
---
|
||||||
|
Name: bridge-utils
|
||||||
|
---
|
||||||
|
Name: docker-engine
|
||||||
|
hash: 30f7840704361673db2b62f25b6038628184b056
|
||||||
|
preventStart: true
|
||||||
|
source: http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.1-0~xenial_amd64.deb
|
||||||
|
version: 1.12.1-0~xenial
|
||||||
|
---
|
||||||
|
Name: libapparmor1
|
||||||
|
---
|
||||||
|
Name: libltdl7
|
||||||
|
---
|
||||||
|
Name: perl
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
apiVersion: kops/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
|
||||||
|
- etcdMembers:
|
||||||
|
- instanceGroup: master-us-test-1a
|
||||||
|
name: master-us-test-1a
|
||||||
|
name: events
|
||||||
|
kubernetesVersion: v1.4.6
|
||||||
|
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
|
|
@ -0,0 +1,18 @@
|
||||||
|
contents: {}
|
||||||
|
path: /usr/share/doc/docker/apache.txt
|
||||||
|
type: file
|
||||||
|
---
|
||||||
|
Name: bridge-utils
|
||||||
|
---
|
||||||
|
Name: docker-engine
|
||||||
|
hash: b758fc88346a1e5eebf7408b0d0c99f4f134166c
|
||||||
|
preventStart: true
|
||||||
|
source: http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.3-0~xenial_amd64.deb
|
||||||
|
version: 1.12.3-0~xenial
|
||||||
|
---
|
||||||
|
Name: libapparmor1
|
||||||
|
---
|
||||||
|
Name: libltdl7
|
||||||
|
---
|
||||||
|
Name: perl
|
||||||
|
|
|
@ -36,11 +36,11 @@ const FileType_Directory = "directory"
|
||||||
const FileType_File = "file"
|
const FileType_File = "file"
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Path string
|
Path string `json:"path,omitempty"`
|
||||||
Contents fi.Resource
|
Contents fi.Resource `json:"contents,omitempty"`
|
||||||
|
|
||||||
Mode *string `json:"mode"`
|
Mode *string `json:"mode,omitempty"`
|
||||||
IfNotExists bool `json:"ifNotExists"`
|
IfNotExists bool `json:"ifNotExists,omitempty"`
|
||||||
|
|
||||||
OnChangeExecute []string `json:"onChangeExecute,omitempty"`
|
OnChangeExecute []string `json:"onChangeExecute,omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,13 @@ import (
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
Version *string `json:"version"`
|
Version *string `json:"version,omitempty"`
|
||||||
Source *string `json:"source"`
|
Source *string `json:"source,omitempty"`
|
||||||
Hash *string `json:"hash"`
|
Hash *string `json:"hash,omitempty"`
|
||||||
PreventStart *bool `json:"preventStart"`
|
PreventStart *bool `json:"preventStart,omitempty"`
|
||||||
|
|
||||||
// Healthy is true if the package installation did not fail
|
// Healthy is true if the package installation did not fail
|
||||||
Healthy *bool `json:"healthy"`
|
Healthy *bool `json:"healthy,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
Loading…
Reference in New Issue