forked from LaconicNetwork/kompose
checkUnsupportedKeys for transformers
This commit is contained in:
committed by
Ratnadeep Debnath
parent
e4f9b59b4d
commit
f20e6f3fa9
@@ -18,11 +18,13 @@ package kubernetes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/fatih/structs"
|
||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||
"github.com/kubernetes-incubator/kompose/pkg/transformer"
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
@@ -52,6 +54,52 @@ type Kubernetes struct {
|
||||
// used when undeploying resources from kubernetes
|
||||
const TIMEOUT = 300
|
||||
|
||||
// list of all unsupported keys for this transformer
|
||||
// Keys are names of variables in kobject struct.
|
||||
// this is map to make searching for keys easier
|
||||
// also counts how many times was given key found in kobject
|
||||
// to make sure that we show warning only once for every key
|
||||
var unsupportedKey = map[string]int{
|
||||
"Build": 0,
|
||||
}
|
||||
|
||||
// checkUnsupportedKey checks if given komposeObject contains
|
||||
// keys that are not supported by this tranfomer.
|
||||
// list of all unsupported keys are stored in unsupportedKey variable
|
||||
// returns list of TODO: ....
|
||||
func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, unsupportedKey map[string]int) []string {
|
||||
// collect all keys found in project
|
||||
var keysFound []string
|
||||
|
||||
for _, serviceConfig := range komposeObject.ServiceConfigs {
|
||||
// this reflection is used in check for empty arrays
|
||||
val := reflect.ValueOf(serviceConfig)
|
||||
s := structs.New(serviceConfig)
|
||||
|
||||
for _, f := range s.Fields() {
|
||||
if f.IsExported() && !f.IsZero() {
|
||||
// IsZero returns false for empty array/slice ([])
|
||||
// this check if field is Slice, and then it checks its size
|
||||
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
||||
if field.Len() == 0 {
|
||||
// array is empty it doesn't metter if it is in unsupportedKey or not
|
||||
continue
|
||||
}
|
||||
}
|
||||
if counter, ok := unsupportedKey[f.Name()]; ok {
|
||||
if counter == 0 {
|
||||
//get tag from kobject service configure
|
||||
tag := f.Tag(komposeObject.LoadedFrom)
|
||||
keysFound = append(keysFound, tag)
|
||||
}
|
||||
unsupportedKey[f.Name()]++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return keysFound
|
||||
}
|
||||
|
||||
// Init RC object
|
||||
func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController {
|
||||
rc := &api.ReplicationController{
|
||||
@@ -351,6 +399,12 @@ func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Po
|
||||
// Transform maps komposeObject to k8s objects
|
||||
// returns object that are already sorted in the way that Services are first
|
||||
func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) []runtime.Object {
|
||||
|
||||
noSupKeys := k.CheckUnsupportedKey(&komposeObject, unsupportedKey)
|
||||
for _, keyName := range noSupKeys {
|
||||
logrus.Warningf("Kubernetes provider doesn't support %s key - ignoring", keyName)
|
||||
}
|
||||
|
||||
// this will hold all the converted data
|
||||
var allobjects []runtime.Object
|
||||
|
||||
|
||||
Reference in New Issue
Block a user