forked from LaconicNetwork/kompose
clean code
This commit is contained in:
parent
e867d35e39
commit
d532b29d95
@ -449,7 +449,7 @@ func Convert(c *cli.Context) {
|
||||
file = dabFile
|
||||
}
|
||||
|
||||
//komposeObject.Loader(file, inputFormat)
|
||||
// loader parses input from file into komposeObject.
|
||||
switch inputFormat {
|
||||
case "bundle":
|
||||
komposeObject = loader.LoadBundle(file)
|
||||
@ -475,7 +475,7 @@ func Convert(c *cli.Context) {
|
||||
|
||||
validateFlags(opt, singleOutput, dabFile, inputFile)
|
||||
|
||||
// Convert komposeObject to K8S controllers
|
||||
// transformer maps komposeObject to provider(K8S, OpenShift) primitives
|
||||
mServices, mDeployments, mDaemonSets, mReplicationControllers, mDeploymentConfigs, svcnames := transformer.Transform(komposeObject, opt)
|
||||
|
||||
// Print output
|
||||
|
||||
@ -19,7 +19,6 @@ package kobject
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fatih/structs"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
var unsupportedKey = map[string]int{
|
||||
@ -176,32 +175,12 @@ const (
|
||||
ProtocolUDP Protocol = "UDP"
|
||||
)
|
||||
|
||||
// loader takes input and converts to KomposeObject
|
||||
//func (k *KomposeObject) Loader(file string, inp string) {
|
||||
// switch inp {
|
||||
// case "bundle":
|
||||
// //k.loadBundleFile(file)
|
||||
// loader.LoadBundle(k, file)
|
||||
// case "compose":
|
||||
// //k.loadComposeFile(file)
|
||||
// loader.LoadCompose(k, file)
|
||||
// default:
|
||||
// logrus.Fatalf("Input file format is not supported")
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
// transformer takes KomposeObject and converts to K8S / OpenShift primitives
|
||||
//func (k *KomposeObject) Transformer(opt ConvertOptions) {
|
||||
// transformer.Transform(k, opt)
|
||||
//}
|
||||
|
||||
func CheckUnsupportedKey(service interface{}) {
|
||||
s := structs.New(service)
|
||||
for _, f := range s.Fields() {
|
||||
if f.IsExported() && !f.IsZero() {
|
||||
if count, ok := unsupportedKey[f.Name()]; ok && count == 0 {
|
||||
fmt.Println("WARNING: Unsupported key " + f.Name() + " - ignoring")
|
||||
fmt.Println("WARNING: Unsupported key " + composeOptions[f.Name()] + " - ignoring")
|
||||
unsupportedKey[f.Name()]++
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func loadPortsfromBundle(service bundlefile.Service) ([]kobject.Ports, string) {
|
||||
}
|
||||
|
||||
// load Bundlefile into KomposeObject
|
||||
func LoadBundle(file string) (kobject.KomposeObject) {
|
||||
func LoadBundle(file string) kobject.KomposeObject {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ func loadPortsFromCompose(composePorts []string) ([]kobject.Ports, string) {
|
||||
}
|
||||
|
||||
// load Docker Compose file into KomposeObject
|
||||
func LoadCompose(file string) (kobject.KomposeObject) {
|
||||
func LoadCompose(file string) kobject.KomposeObject {
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
}
|
||||
|
||||
@ -174,39 +174,6 @@ func initDS(name string, service kobject.ServiceConfig) *extensions.DaemonSet {
|
||||
return ds
|
||||
}
|
||||
|
||||
// initDeploymentConfig initialize OpenShifts DeploymentConfig object
|
||||
func initDeploymentConfig(name string, service kobject.ServiceConfig, replicas int) *deployapi.DeploymentConfig {
|
||||
dc := &deployapi.DeploymentConfig{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "DeploymentConfig",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: map[string]string{"service": name},
|
||||
},
|
||||
Spec: deployapi.DeploymentConfigSpec{
|
||||
Replicas: int32(replicas),
|
||||
Selector: map[string]string{"service": name},
|
||||
//UniqueLabelKey: p.Name,
|
||||
Template: &api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{"service": name},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: name,
|
||||
Image: service.Image,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return dc
|
||||
}
|
||||
|
||||
// Configure the environment variables.
|
||||
func configEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
|
||||
envs := []api.EnvVar{}
|
||||
|
||||
@ -15,3 +15,44 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
package transformer
|
||||
|
||||
import (
|
||||
"github.com/skippbox/kompose/pkg/kobject"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
)
|
||||
|
||||
// initDeploymentConfig initialize OpenShifts DeploymentConfig object
|
||||
func initDeploymentConfig(name string, service kobject.ServiceConfig, replicas int) *deployapi.DeploymentConfig {
|
||||
dc := &deployapi.DeploymentConfig{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "DeploymentConfig",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: map[string]string{"service": name},
|
||||
},
|
||||
Spec: deployapi.DeploymentConfigSpec{
|
||||
Replicas: int32(replicas),
|
||||
Selector: map[string]string{"service": name},
|
||||
//UniqueLabelKey: p.Name,
|
||||
Template: &api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{"service": name},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: name,
|
||||
Image: service.Image,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return dc
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user