mirror of https://github.com/kubernetes/kops.git
Add HA test, test against single "all yaml" output
Related to #1189 ... we have this output now (in testing!)
This commit is contained in:
parent
9bfd067520
commit
9a3b96f853
|
|
@ -39,16 +39,21 @@ import (
|
|||
|
||||
var MagicTimestamp = unversioned.Time{Time: time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)}
|
||||
|
||||
// TestMinimal runs kops create cluster minimal.example.com --zones us-test-1a
|
||||
// TestCreateClusterMinimal runs kops create cluster minimal.example.com --zones us-test-1a
|
||||
func TestCreateClusterMinimal(t *testing.T) {
|
||||
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/minimal", 2)
|
||||
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/minimal")
|
||||
}
|
||||
|
||||
func runCreateClusterIntegrationTest(t *testing.T, srcDir string, expectedInstanceGroups int) {
|
||||
// TestCreateClusterHA runs kops create cluster ha.example.com --zones us-test-1a,us-test-1b,us-test-1c --master-zones us-test-1a,us-test-1b,us-test-1c
|
||||
func TestCreateClusterHA(t *testing.T) {
|
||||
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/ha")
|
||||
}
|
||||
|
||||
func runCreateClusterIntegrationTest(t *testing.T, srcDir string) {
|
||||
var stdout bytes.Buffer
|
||||
|
||||
optionsYAML := "options.yaml"
|
||||
expectedClusterPath := "cluster.yaml"
|
||||
expectedClusterPath := "expected.yaml"
|
||||
|
||||
factoryOptions := &util.FactoryOptions{}
|
||||
factoryOptions.RegistryPath = "memfs://tests"
|
||||
|
|
@ -105,28 +110,18 @@ func runCreateClusterIntegrationTest(t *testing.T, srcDir string, expectedInstan
|
|||
if len(clusters.Items) != 1 {
|
||||
t.Fatalf("expected one cluster, found %d", len(clusters.Items))
|
||||
}
|
||||
|
||||
var yamlAll []string
|
||||
|
||||
for _, cluster := range clusters.Items {
|
||||
cluster.ObjectMeta.CreationTimestamp = MagicTimestamp
|
||||
actualYAMLBytes, err := kops.ToVersionedYaml(&cluster)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error serializing cluster: %v", err)
|
||||
}
|
||||
expectedYAMLBytes, err := ioutil.ReadFile(path.Join(srcDir, expectedClusterPath))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error reading expected cluster: %v", err)
|
||||
}
|
||||
|
||||
actualYAML := strings.TrimSpace(string(actualYAMLBytes))
|
||||
expectedYAML := strings.TrimSpace(string(expectedYAMLBytes))
|
||||
|
||||
if actualYAML != expectedYAML {
|
||||
glog.Infof("Actual cluster:\n%s\n", actualYAML)
|
||||
|
||||
diffString := diff.FormatDiff(expectedYAML, actualYAML)
|
||||
t.Logf("diff:\n%s\n", diffString)
|
||||
|
||||
t.Fatalf("cluster differed from expected")
|
||||
}
|
||||
yamlAll = append(yamlAll, actualYAML)
|
||||
}
|
||||
|
||||
// Compare instance groups
|
||||
|
|
@ -136,9 +131,6 @@ func runCreateClusterIntegrationTest(t *testing.T, srcDir string, expectedInstan
|
|||
t.Fatalf("error listing instance groups: %v", err)
|
||||
}
|
||||
|
||||
if len(instanceGroups.Items) != expectedInstanceGroups {
|
||||
t.Fatalf("expected %d instance groups, found %d", expectedInstanceGroups, len(instanceGroups.Items))
|
||||
}
|
||||
for _, ig := range instanceGroups.Items {
|
||||
ig.ObjectMeta.CreationTimestamp = MagicTimestamp
|
||||
|
||||
|
|
@ -146,21 +138,27 @@ func runCreateClusterIntegrationTest(t *testing.T, srcDir string, expectedInstan
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected error serializing InstanceGroup: %v", err)
|
||||
}
|
||||
expectedYAMLBytes, err := ioutil.ReadFile(path.Join(srcDir, ig.ObjectMeta.Name+".yaml"))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error reading expected InstanceGroup: %v", err)
|
||||
}
|
||||
|
||||
actualYAML := strings.TrimSpace(string(actualYAMLBytes))
|
||||
expectedYAML := strings.TrimSpace(string(expectedYAMLBytes))
|
||||
|
||||
if actualYAML != expectedYAML {
|
||||
glog.Infof("Actual IG %q:\n%s\n", ig.ObjectMeta.Name, actualYAML)
|
||||
|
||||
diffString := diff.FormatDiff(expectedYAML, actualYAML)
|
||||
t.Logf("diff:\n%s\n", diffString)
|
||||
|
||||
t.Fatalf("instance group %q differed from expected", ig.ObjectMeta.Name)
|
||||
}
|
||||
yamlAll = append(yamlAll, actualYAML)
|
||||
}
|
||||
|
||||
expectedYAMLBytes, err := ioutil.ReadFile(path.Join(srcDir, expectedClusterPath))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error reading expected YAML: %v", err)
|
||||
}
|
||||
|
||||
expectedYAML := strings.TrimSpace(string(expectedYAMLBytes))
|
||||
|
||||
actualYAML := strings.Join(yamlAll, "\n\n---\n\n")
|
||||
if actualYAML != expectedYAML {
|
||||
glog.Infof("Actual YAML:\n%s\n", actualYAML)
|
||||
|
||||
diffString := diff.FormatDiff(expectedYAML, actualYAML)
|
||||
t.Logf("diff:\n%s\n", diffString)
|
||||
|
||||
t.Fatalf("YAML differed from expected")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
apiVersion: kops/v1alpha1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: ha.example.com
|
||||
spec:
|
||||
channel: stable
|
||||
cloudProvider: aws
|
||||
configBase: memfs://tests/ha.example.com
|
||||
etcdClusters:
|
||||
- etcdMembers:
|
||||
- name: us-test-1a
|
||||
zone: us-test-1a
|
||||
- name: us-test-1b
|
||||
zone: us-test-1b
|
||||
- name: us-test-1c
|
||||
zone: us-test-1c
|
||||
name: main
|
||||
- etcdMembers:
|
||||
- name: us-test-1a
|
||||
zone: us-test-1a
|
||||
- name: us-test-1b
|
||||
zone: us-test-1b
|
||||
- name: us-test-1c
|
||||
zone: us-test-1c
|
||||
name: events
|
||||
kubernetesVersion: v1.4.6
|
||||
masterPublicName: api.ha.example.com
|
||||
networkCIDR: 172.20.0.0/16
|
||||
networking:
|
||||
kubenet: {}
|
||||
nonMasqueradeCIDR: 100.64.0.0/10
|
||||
topology:
|
||||
bastion:
|
||||
idleTimeout: 120
|
||||
machineType: t2.medium
|
||||
masters: public
|
||||
nodes: public
|
||||
zones:
|
||||
- cidr: 172.20.32.0/19
|
||||
name: us-test-1a
|
||||
- cidr: 172.20.64.0/19
|
||||
name: us-test-1b
|
||||
- cidr: 172.20.96.0/19
|
||||
name: us-test-1c
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: master-us-test-1a
|
||||
spec:
|
||||
associatePublicIp: true
|
||||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
|
||||
machineType: m3.medium
|
||||
maxSize: 1
|
||||
minSize: 1
|
||||
role: Master
|
||||
zones:
|
||||
- us-test-1a
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: master-us-test-1b
|
||||
spec:
|
||||
associatePublicIp: true
|
||||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
|
||||
machineType: m3.medium
|
||||
maxSize: 1
|
||||
minSize: 1
|
||||
role: Master
|
||||
zones:
|
||||
- us-test-1b
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: master-us-test-1c
|
||||
spec:
|
||||
associatePublicIp: true
|
||||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
|
||||
machineType: m3.medium
|
||||
maxSize: 1
|
||||
minSize: 1
|
||||
role: Master
|
||||
zones:
|
||||
- us-test-1c
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: nodes
|
||||
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
|
||||
zones:
|
||||
- us-test-1a
|
||||
- us-test-1b
|
||||
- us-test-1c
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ClusterName: ha.example.com
|
||||
Zones: us-test-1a,us-test-1b,us-test-1c
|
||||
MasterZones: us-test-1a,us-test-1b,us-test-1c
|
||||
Cloud: aws
|
||||
|
|
@ -31,3 +31,37 @@ spec:
|
|||
zones:
|
||||
- cidr: 172.20.32.0/19
|
||||
name: us-test-1a
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: master-us-test-1a
|
||||
spec:
|
||||
associatePublicIp: true
|
||||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
|
||||
machineType: m3.medium
|
||||
maxSize: 1
|
||||
minSize: 1
|
||||
role: Master
|
||||
zones:
|
||||
- us-test-1a
|
||||
|
||||
---
|
||||
|
||||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: nodes
|
||||
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
|
||||
zones:
|
||||
- us-test-1a
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: master-us-test-1a
|
||||
spec:
|
||||
associatePublicIp: true
|
||||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
|
||||
machineType: m3.medium
|
||||
maxSize: 1
|
||||
minSize: 1
|
||||
role: Master
|
||||
zones:
|
||||
- us-test-1a
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
apiVersion: kops/v1alpha1
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: nodes
|
||||
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
|
||||
zones:
|
||||
- us-test-1a
|
||||
Loading…
Reference in New Issue