Abstracted port checking function

To reduce the inconsistency of message printing created a
function which can be called from both kubernetes and openshift
This commit is contained in:
Suraj Deshmukh 2016-08-16 11:25:27 +05:30
parent 2fd923ce49
commit c281bfdda8
3 changed files with 12 additions and 6 deletions

View File

@ -213,3 +213,12 @@ func convertToVersion(objs []runtime.Object) ([]runtime.Object, error) {
return ret, nil return ret, nil
} }
func PortsExist(name string, service kobject.ServiceConfig) bool {
if len(service.Port) == 0 {
logrus.Warningf("[%s] Service cannot be created because of missing port.", name)
return false
} else {
return true
}
}

View File

@ -314,11 +314,10 @@ 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 len(ports) == 0 { if PortsExist(name, service) {
logrus.Warningf("[%s] Service cannot be created because of missing port.", name)
} else {
objects = append(objects, sc) objects = append(objects, sc)
} }
allobjects = append(allobjects, objects...) allobjects = append(allobjects, objects...)
} }

View File

@ -153,9 +153,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 len(ports) == 0 { if kubernetes.PortsExist(name, service) {
logrus.Warningf("[%s] Service cannot be created because of missing port.", name)
} else {
objects = append(objects, sc) objects = append(objects, sc)
} }
allobjects = append(allobjects, objects...) allobjects = append(allobjects, objects...)