forked from LaconicNetwork/kompose
Add more unit tests for Transform
This commit is contained in:
parent
08488f8fdc
commit
c18288a023
@ -45,14 +45,12 @@ func InitRC(name string, service kobject.ServiceConfig, replicas int) *api.Repli
|
|||||||
},
|
},
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
//Labels: map[string]string{"service": name},
|
|
||||||
},
|
},
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Selector: map[string]string{"service": name},
|
|
||||||
Replicas: int32(replicas),
|
Replicas: int32(replicas),
|
||||||
Template: &api.PodTemplateSpec{
|
Template: &api.PodTemplateSpec{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
//Labels: map[string]string{"service": name},
|
Labels: transformer.ConfigLabels(name),
|
||||||
},
|
},
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
@ -68,45 +66,37 @@ func InitRC(name string, service kobject.ServiceConfig, replicas int) *api.Repli
|
|||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init SC object
|
// Init Svc object
|
||||||
func InitSC(name string, service kobject.ServiceConfig) *api.Service {
|
func InitSvc(name string, service kobject.ServiceConfig) *api.Service {
|
||||||
sc := &api.Service{
|
svc := &api.Service{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
Kind: "Service",
|
Kind: "Service",
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
//Labels: map[string]string{"service": name},
|
Labels: transformer.ConfigLabels(name),
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Selector: map[string]string{"service": name},
|
Selector: transformer.ConfigLabels(name),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return sc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init DC object
|
// Init Deployment
|
||||||
func InitDC(name string, service kobject.ServiceConfig, replicas int) *extensions.Deployment {
|
func InitD(name string, service kobject.ServiceConfig, replicas int) *extensions.Deployment {
|
||||||
dc := &extensions.Deployment{
|
dc := &extensions.Deployment{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
Kind: "Deployment",
|
Kind: "Deployment",
|
||||||
APIVersion: "extensions/v1beta1",
|
APIVersion: "extensions/v1beta1",
|
||||||
},
|
},
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
Labels: map[string]string{"service": name},
|
|
||||||
},
|
},
|
||||||
Spec: extensions.DeploymentSpec{
|
Spec: extensions.DeploymentSpec{
|
||||||
Replicas: int32(replicas),
|
Replicas: int32(replicas),
|
||||||
Selector: &unversioned.LabelSelector{
|
|
||||||
MatchLabels: map[string]string{"service": name},
|
|
||||||
},
|
|
||||||
//UniqueLabelKey: p.Name,
|
|
||||||
Template: api.PodTemplateSpec{
|
Template: api.PodTemplateSpec{
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Labels: map[string]string{"service": name},
|
|
||||||
},
|
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
{
|
{
|
||||||
@ -133,9 +123,6 @@ func InitDS(name string, service kobject.ServiceConfig) *extensions.DaemonSet {
|
|||||||
},
|
},
|
||||||
Spec: extensions.DaemonSetSpec{
|
Spec: extensions.DaemonSetSpec{
|
||||||
Template: api.PodTemplateSpec{
|
Template: api.PodTemplateSpec{
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: name,
|
|
||||||
},
|
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
{
|
{
|
||||||
@ -238,10 +225,10 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
var objects []runtime.Object
|
var objects []runtime.Object
|
||||||
svcnames = append(svcnames, name)
|
svcnames = append(svcnames, name)
|
||||||
|
|
||||||
sc := InitSC(name, service)
|
svc := InitSvc(name, service)
|
||||||
|
|
||||||
if opt.CreateD {
|
if opt.CreateD {
|
||||||
objects = append(objects, InitDC(name, service, opt.Replicas))
|
objects = append(objects, InitD(name, service, opt.Replicas))
|
||||||
}
|
}
|
||||||
if opt.CreateDS {
|
if opt.CreateDS {
|
||||||
objects = append(objects, InitDS(name, service))
|
objects = append(objects, InitDS(name, service))
|
||||||
@ -264,15 +251,11 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
|
|
||||||
// Configure the service ports.
|
// Configure the service ports.
|
||||||
servicePorts := ConfigServicePorts(name, service)
|
servicePorts := ConfigServicePorts(name, service)
|
||||||
sc.Spec.Ports = servicePorts
|
svc.Spec.Ports = servicePorts
|
||||||
|
|
||||||
// Configure label
|
|
||||||
labels := transformer.ConfigLabels(name)
|
|
||||||
sc.ObjectMeta.Labels = labels
|
|
||||||
|
|
||||||
// Configure annotations
|
// Configure annotations
|
||||||
annotations := transformer.ConfigAnnotations(service)
|
annotations := transformer.ConfigAnnotations(service)
|
||||||
sc.ObjectMeta.Annotations = annotations
|
svc.ObjectMeta.Annotations = annotations
|
||||||
|
|
||||||
// fillTemplate fills the pod template with the value calculated from config
|
// fillTemplate fills the pod template with the value calculated from config
|
||||||
fillTemplate := func(template *api.PodTemplateSpec) {
|
fillTemplate := func(template *api.PodTemplateSpec) {
|
||||||
@ -288,7 +271,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
template.Spec.Containers[0].Ports = ports
|
template.Spec.Containers[0].Ports = ports
|
||||||
template.ObjectMeta.Labels = labels
|
template.ObjectMeta.Labels = transformer.ConfigLabels(name)
|
||||||
// Configure the container restart policy.
|
// Configure the container restart policy.
|
||||||
switch service.Restart {
|
switch service.Restart {
|
||||||
case "", "always":
|
case "", "always":
|
||||||
@ -304,7 +287,6 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
|
|
||||||
// fillObjectMeta fills the metadata with the value calculated from config
|
// fillObjectMeta fills the metadata with the value calculated from config
|
||||||
fillObjectMeta := func(meta *api.ObjectMeta) {
|
fillObjectMeta := func(meta *api.ObjectMeta) {
|
||||||
meta.Labels = labels
|
|
||||||
meta.Annotations = annotations
|
meta.Annotations = annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +297,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
|
|
||||||
// If ports not provided in configuration we will not make service
|
// If ports not provided in configuration we will not make service
|
||||||
if PortsExist(name, service) {
|
if PortsExist(name, service) {
|
||||||
objects = append(objects, sc)
|
objects = append(objects, svc)
|
||||||
}
|
}
|
||||||
|
|
||||||
allobjects = append(allobjects, objects...)
|
allobjects = append(allobjects, objects...)
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import (
|
|||||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||||
|
|
||||||
"github.com/skippbox/kompose/pkg/kobject"
|
"github.com/skippbox/kompose/pkg/kobject"
|
||||||
|
"github.com/skippbox/kompose/pkg/transformer"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
@ -38,19 +39,19 @@ func newServiceConfig() kobject.ServiceConfig {
|
|||||||
WorkingDir: "dir",
|
WorkingDir: "dir",
|
||||||
Args: []string{"arg1", "arg2"},
|
Args: []string{"arg1", "arg2"},
|
||||||
Volumes: []string{"/tmp/volume"},
|
Volumes: []string{"/tmp/volume"},
|
||||||
Network: []string{"network1", "network2"},
|
Network: []string{"network1", "network2"}, // not supported
|
||||||
Labels: map[string]string{"service": "app"},
|
Labels: nil,
|
||||||
Annotations: map[string]string{"abc": "def"},
|
Annotations: map[string]string{"abc": "def"},
|
||||||
CPUSet: "cpu_set",
|
CPUSet: "cpu_set", // not supported
|
||||||
CPUShares: 1,
|
CPUShares: 1, // not supported
|
||||||
CPUQuota: 1,
|
CPUQuota: 1, // not supported
|
||||||
CapAdd: []string{"cap_add"},
|
CapAdd: []string{"cap_add"}, // not supported
|
||||||
CapDrop: []string{"cap_drop"},
|
CapDrop: []string{"cap_drop"}, // not supported
|
||||||
Entrypoint: []string{"entrypoint"},
|
Entrypoint: []string{"entrypoint"}, // not supported
|
||||||
Expose: []string{"expose"},
|
Expose: []string{"expose"}, // not supported
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
Restart: "always",
|
Restart: "always",
|
||||||
User: "user",
|
User: "user", // not supported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +115,22 @@ func equalPorts(kPorts []kobject.Ports, k8sPorts []api.ContainerPort) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec) error {
|
func equalStringMaps(map1 map[string]string, map2 map[string]string) bool {
|
||||||
|
if len(map1) != len(map2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for k, v := range map1 {
|
||||||
|
if map2[k] != v {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec, expectedLabels map[string]string) error {
|
||||||
|
if len(template.Spec.Containers) == 0 {
|
||||||
|
return fmt.Errorf("Failed to set container: %#v vs. %#v", config, template)
|
||||||
|
}
|
||||||
container := template.Spec.Containers[0]
|
container := template.Spec.Containers[0]
|
||||||
// FIXME: we should support container name and uncomment this test
|
// FIXME: we should support container name and uncomment this test
|
||||||
//if config.ContainerName != container.Name {
|
//if config.ContainerName != container.Name {
|
||||||
@ -143,19 +159,43 @@ func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec
|
|||||||
(template.Spec.Volumes[0].VolumeSource.HostPath == nil && template.Spec.Volumes[0].VolumeSource.EmptyDir == nil) {
|
(template.Spec.Volumes[0].VolumeSource.HostPath == nil && template.Spec.Volumes[0].VolumeSource.EmptyDir == nil) {
|
||||||
return fmt.Errorf("Found incorrect volumes: %v vs. %#v", config.Volumes, template.Spec.Volumes)
|
return fmt.Errorf("Found incorrect volumes: %v vs. %#v", config.Volumes, template.Spec.Volumes)
|
||||||
}
|
}
|
||||||
|
// We only set controller labels here and k8s server will take care of other defaults, such as selectors
|
||||||
|
if !equalStringMaps(expectedLabels, template.Labels) {
|
||||||
|
return fmt.Errorf("Found different template labels: %#v vs. %#v", expectedLabels, template.Labels)
|
||||||
|
}
|
||||||
restartPolicyMapping := map[string]api.RestartPolicy{"always": api.RestartPolicyAlways}
|
restartPolicyMapping := map[string]api.RestartPolicy{"always": api.RestartPolicyAlways}
|
||||||
if restartPolicyMapping[config.Restart] != template.Spec.RestartPolicy {
|
if restartPolicyMapping[config.Restart] != template.Spec.RestartPolicy {
|
||||||
return fmt.Errorf("Found incorrect restart policy: %v vs. %v", config.Restart, template.Spec.RestartPolicy)
|
return fmt.Errorf("Found incorrect restart policy: %v vs. %v", config.Restart, template.Spec.RestartPolicy)
|
||||||
}
|
}
|
||||||
if len(template.Labels) != 1 || len(template.Labels["service"]) == 0 {
|
if config.Privileged == privilegedNilOrFalse(template) {
|
||||||
return fmt.Errorf("Found incorrect labels: %#v", template.Labels)
|
return fmt.Errorf("Found different template privileged: %#v vs. %#v", config.Privileged, template.Spec.Containers[0].SecurityContext)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func privilegedNilOrFalse(template api.PodTemplateSpec) bool {
|
||||||
|
return len(template.Spec.Containers) == 0 || template.Spec.Containers[0].SecurityContext == nil ||
|
||||||
|
template.Spec.Containers[0].SecurityContext.Privileged == nil || *template.Spec.Containers[0].SecurityContext.Privileged == false
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkService(config kobject.ServiceConfig, svc *api.Service, expectedLabels map[string]string) error {
|
||||||
|
if !equalStringMaps(expectedLabels, svc.Spec.Selector) {
|
||||||
|
return fmt.Errorf("Found unexpected selector: %#v vs. %#v", expectedLabels, svc.Spec.Selector)
|
||||||
}
|
}
|
||||||
// TODO: finish this
|
// TODO: finish this
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkService(config kobject.ServiceConfig, svc *api.Service) error {
|
func checkMeta(config kobject.ServiceConfig, meta api.ObjectMeta, expectedName string, shouldSetLabels bool) error {
|
||||||
// TODO: finish this
|
if expectedName != meta.Name {
|
||||||
|
return fmt.Errorf("Found unexpected name: %s vs. %s", expectedName, meta.Name)
|
||||||
|
}
|
||||||
|
if !equalStringMaps(config.Annotations, meta.Annotations) {
|
||||||
|
return fmt.Errorf("Found different annotations: %#v vs. %#v", config.Annotations, meta.Annotations)
|
||||||
|
}
|
||||||
|
if shouldSetLabels != (len(meta.Labels) > 0) {
|
||||||
|
return fmt.Errorf("Unexpected labels: %#v", meta.Labels)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,62 +206,100 @@ func TestKomposeConvert(t *testing.T) {
|
|||||||
opt kobject.ConvertOptions
|
opt kobject.ConvertOptions
|
||||||
expectedNumObjs int
|
expectedNumObjs int
|
||||||
}{
|
}{
|
||||||
"Convert to Deployments": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, Replicas: replicas}, 2},
|
"Convert to Deployments (D)": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, Replicas: replicas}, 2},
|
||||||
|
"Convert to DaemonSets (DS)": {newKomposeObject(), kobject.ConvertOptions{CreateDS: true}, 2},
|
||||||
|
"Convert to ReplicationController (RC)": {newKomposeObject(), kobject.ConvertOptions{CreateRC: true, Replicas: replicas}, 2},
|
||||||
|
"Convert to D, DS, and RC": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true, Replicas: replicas}, 4},
|
||||||
// TODO: add more tests
|
// TODO: add more tests
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, test := range testCases {
|
for name, test := range testCases {
|
||||||
t.Log("Test case:", name)
|
t.Log("Test case:", name)
|
||||||
k := Kubernetes{}
|
k := Kubernetes{}
|
||||||
|
// Run Transform
|
||||||
objs := k.Transform(test.komposeObject, test.opt)
|
objs := k.Transform(test.komposeObject, test.opt)
|
||||||
if len(objs) != test.expectedNumObjs {
|
if len(objs) != test.expectedNumObjs {
|
||||||
t.Errorf("Expected %d objects returned, got %d", test.expectedNumObjs, len(objs))
|
t.Errorf("Expected %d objects returned, got %d", test.expectedNumObjs, len(objs))
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundSVC, foundD, foundDS, foundRC, foundDC bool
|
var foundSVC, foundD, foundDS, foundRC, foundDC bool
|
||||||
|
name := "app"
|
||||||
|
labels := transformer.ConfigLabels(name)
|
||||||
|
config := test.komposeObject.ServiceConfigs[name]
|
||||||
|
// Check results
|
||||||
for _, obj := range objs {
|
for _, obj := range objs {
|
||||||
if svc, ok := obj.(*api.Service); ok {
|
if svc, ok := obj.(*api.Service); ok {
|
||||||
if err := checkService(test.komposeObject.ServiceConfigs["app"], svc); err != nil {
|
if err := checkService(config, svc, labels); err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
if err := checkMeta(config, svc.ObjectMeta, name, true); err != nil {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
foundSVC = true
|
foundSVC = true
|
||||||
}
|
}
|
||||||
if test.opt.CreateD {
|
if test.opt.CreateD {
|
||||||
if d, ok := obj.(*extensions.Deployment); ok {
|
if d, ok := obj.(*extensions.Deployment); ok {
|
||||||
if err := checkPodTemplate(test.komposeObject.ServiceConfigs["app"], d.Spec.Template); err != nil {
|
if err := checkPodTemplate(config, d.Spec.Template, labels); err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
if err := checkMeta(config, d.ObjectMeta, name, false); err != nil {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
if (int)(d.Spec.Replicas) != replicas {
|
if (int)(d.Spec.Replicas) != replicas {
|
||||||
t.Errorf("Expected %d replicas, got %d", replicas, d.Spec.Replicas)
|
t.Errorf("Expected %d replicas, got %d", replicas, d.Spec.Replicas)
|
||||||
}
|
}
|
||||||
|
if d.Spec.Selector != nil && len(d.Spec.Selector.MatchLabels) > 0 {
|
||||||
|
t.Errorf("Expect selector be unset, got: %#v", d.Spec.Selector)
|
||||||
|
}
|
||||||
foundD = true
|
foundD = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if test.opt.CreateDS {
|
if test.opt.CreateDS {
|
||||||
if ds, ok := obj.(*extensions.DaemonSet); ok {
|
if ds, ok := obj.(*extensions.DaemonSet); ok {
|
||||||
if err := checkPodTemplate(test.komposeObject.ServiceConfigs["app"], ds.Spec.Template); err != nil {
|
if err := checkPodTemplate(config, ds.Spec.Template, labels); err != nil {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
|
if err := checkMeta(config, ds.ObjectMeta, name, false); err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
if ds.Spec.Selector != nil && len(ds.Spec.Selector.MatchLabels) > 0 {
|
||||||
|
t.Errorf("Expect selector be unset, got: %#v", ds.Spec.Selector)
|
||||||
|
}
|
||||||
foundDS = true
|
foundDS = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if test.opt.CreateRC {
|
if test.opt.CreateRC {
|
||||||
if rc, ok := obj.(*api.ReplicationController); ok {
|
if rc, ok := obj.(*api.ReplicationController); ok {
|
||||||
if err := checkPodTemplate(test.komposeObject.ServiceConfigs["app"], *rc.Spec.Template); err != nil {
|
if err := checkPodTemplate(config, *rc.Spec.Template, labels); err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
if err := checkMeta(config, rc.ObjectMeta, name, false); err != nil {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
if (int)(rc.Spec.Replicas) != replicas {
|
if (int)(rc.Spec.Replicas) != replicas {
|
||||||
t.Errorf("Expected %d replicas, got %d", replicas, rc.Spec.Replicas)
|
t.Errorf("Expected %d replicas, got %d", replicas, rc.Spec.Replicas)
|
||||||
}
|
}
|
||||||
|
if len(rc.Spec.Selector) > 0 {
|
||||||
|
t.Errorf("Expect selector be unset, got: %#v", rc.Spec.Selector)
|
||||||
|
}
|
||||||
foundRC = true
|
foundRC = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: k8s & openshift transformer is now separated; either separate the test or combine the transformer
|
||||||
if test.opt.CreateDeploymentConfig {
|
if test.opt.CreateDeploymentConfig {
|
||||||
if dc, ok := obj.(*deployapi.DeploymentConfig); ok {
|
if dc, ok := obj.(*deployapi.DeploymentConfig); ok {
|
||||||
if err := checkPodTemplate(test.komposeObject.ServiceConfigs["app"], *dc.Spec.Template); err != nil {
|
if err := checkPodTemplate(config, *dc.Spec.Template, labels); err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
if err := checkMeta(config, dc.ObjectMeta, name, false); err != nil {
|
||||||
t.Errorf("%v", err)
|
t.Errorf("%v", err)
|
||||||
}
|
}
|
||||||
if (int)(dc.Spec.Replicas) != replicas {
|
if (int)(dc.Spec.Replicas) != replicas {
|
||||||
t.Errorf("Expected %d replicas, got %d", replicas, dc.Spec.Replicas)
|
t.Errorf("Expected %d replicas, got %d", replicas, dc.Spec.Replicas)
|
||||||
}
|
}
|
||||||
|
if len(dc.Spec.Selector) > 0 {
|
||||||
|
t.Errorf("Expect selector be unset, got: %#v", dc.Spec.Selector)
|
||||||
|
}
|
||||||
foundDC = true
|
foundDC = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,10 +74,10 @@ func (k *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
var objects []runtime.Object
|
var objects []runtime.Object
|
||||||
svcnames = append(svcnames, name)
|
svcnames = append(svcnames, name)
|
||||||
|
|
||||||
sc := kubernetes.InitSC(name, service)
|
svc := kubernetes.InitSvc(name, service)
|
||||||
|
|
||||||
if opt.CreateD {
|
if opt.CreateD {
|
||||||
objects = append(objects, kubernetes.InitDC(name, service, opt.Replicas))
|
objects = append(objects, kubernetes.InitD(name, service, opt.Replicas))
|
||||||
}
|
}
|
||||||
if opt.CreateDS {
|
if opt.CreateDS {
|
||||||
objects = append(objects, kubernetes.InitDS(name, service))
|
objects = append(objects, kubernetes.InitDS(name, service))
|
||||||
@ -103,15 +103,15 @@ func (k *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
|
|
||||||
// Configure the service ports.
|
// Configure the service ports.
|
||||||
servicePorts := kubernetes.ConfigServicePorts(name, service)
|
servicePorts := kubernetes.ConfigServicePorts(name, service)
|
||||||
sc.Spec.Ports = servicePorts
|
svc.Spec.Ports = servicePorts
|
||||||
|
|
||||||
// Configure label
|
// Configure label
|
||||||
labels := transformer.ConfigLabels(name)
|
labels := transformer.ConfigLabels(name)
|
||||||
sc.ObjectMeta.Labels = labels
|
svc.ObjectMeta.Labels = labels
|
||||||
|
|
||||||
// Configure annotations
|
// Configure annotations
|
||||||
annotations := transformer.ConfigAnnotations(service)
|
annotations := transformer.ConfigAnnotations(service)
|
||||||
sc.ObjectMeta.Annotations = annotations
|
svc.ObjectMeta.Annotations = annotations
|
||||||
|
|
||||||
// fillTemplate fills the pod template with the value calculated from config
|
// fillTemplate fills the pod template with the value calculated from config
|
||||||
fillTemplate := func(template *api.PodTemplateSpec) {
|
fillTemplate := func(template *api.PodTemplateSpec) {
|
||||||
@ -154,7 +154,7 @@ func (k *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
|
|
||||||
// If ports not provided in configuration we will not make service
|
// If ports not provided in configuration we will not make service
|
||||||
if kubernetes.PortsExist(name, service) {
|
if kubernetes.PortsExist(name, service) {
|
||||||
objects = append(objects, sc)
|
objects = append(objects, svc)
|
||||||
}
|
}
|
||||||
allobjects = append(allobjects, objects...)
|
allobjects = append(allobjects, objects...)
|
||||||
}
|
}
|
||||||
|
|||||||
16
script/test/fixtures/etherpad/output-k8s.json
vendored
16
script/test/fixtures/etherpad/output-k8s.json
vendored
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "etherpad",
|
"name": "etherpad",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "etherpad"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "etherpad"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -103,17 +95,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "mariadb",
|
"name": "mariadb",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
16
script/test/fixtures/flask-redis/output-k8s.json
vendored
16
script/test/fixtures/flask-redis/output-k8s.json
vendored
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "flask",
|
"name": "flask",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "flask"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "flask"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -91,17 +83,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "redis",
|
"name": "redis",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
24
script/test/fixtures/gitlab/output-k8s.json
vendored
24
script/test/fixtures/gitlab/output-k8s.json
vendored
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "gitlab",
|
"name": "gitlab",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "gitlab"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "gitlab"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -135,17 +127,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "postgresql",
|
"name": "postgresql",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "postgresql"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "postgresql"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -221,17 +205,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "redis",
|
"name": "redis",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "node2",
|
"name": "node2",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "node2"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "node2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -80,17 +72,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "node3",
|
"name": "node3",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "node3"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "node3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -151,17 +135,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "redis",
|
"name": "redis",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "redis"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -223,17 +199,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "nginx",
|
"name": "nginx",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "nginx"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "nginx"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -294,17 +262,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "node1",
|
"name": "node1",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "node1"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "node1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
16
script/test/fixtures/wordpress/output-k8s.json
vendored
16
script/test/fixtures/wordpress/output-k8s.json
vendored
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "mariadb",
|
"name": "mariadb",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -99,17 +91,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "wordpress",
|
"name": "wordpress",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "wordpress"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "wordpress"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
16
script/test/fixtures/wordpress/output-os.json
vendored
16
script/test/fixtures/wordpress/output-os.json
vendored
@ -9,17 +9,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "mariadb",
|
"name": "mariadb",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "mariadb"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -99,17 +91,9 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "wordpress",
|
"name": "wordpress",
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
"labels": {
|
|
||||||
"service": "wordpress"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
"selector": {
|
|
||||||
"matchLabels": {
|
|
||||||
"service": "wordpress"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user