forked from LaconicNetwork/kompose
checkUnsupportedKeys for transformers
This commit is contained in:
parent
e4f9b59b4d
commit
f20e6f3fa9
@ -21,6 +21,8 @@ import "k8s.io/kubernetes/pkg/api"
|
|||||||
// KomposeObject holds the generic struct of Kompose transformation
|
// KomposeObject holds the generic struct of Kompose transformation
|
||||||
type KomposeObject struct {
|
type KomposeObject struct {
|
||||||
ServiceConfigs map[string]ServiceConfig
|
ServiceConfigs map[string]ServiceConfig
|
||||||
|
// name of the loader that was created KomposeObject
|
||||||
|
LoadedFrom string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConvertOptions struct {
|
type ConvertOptions struct {
|
||||||
@ -40,29 +42,30 @@ type ConvertOptions struct {
|
|||||||
|
|
||||||
// ServiceConfig holds the basic struct of a container
|
// ServiceConfig holds the basic struct of a container
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
|
// use tags to mark from what element this value comes
|
||||||
ContainerName string
|
ContainerName string
|
||||||
Image string
|
Image string `compose:"image",bundle:"Image"`
|
||||||
Environment []EnvVar
|
Environment []EnvVar `compose:"environment",bundle:"Env"`
|
||||||
Port []Ports
|
Port []Ports `compose:"ports",bundle:"Ports"`
|
||||||
Command []string
|
Command []string `compose:"command",bundle:"Command"`
|
||||||
WorkingDir string
|
WorkingDir string `compose:"",bundle:"WorkingDir"`
|
||||||
Args []string
|
Args []string `compose:"args",bundle:"Args"`
|
||||||
Volumes []string
|
Volumes []string `compose:"volumes",bundle:"Volumes"`
|
||||||
Network []string
|
Network []string `compose:"network",bundle:"Networks"`
|
||||||
Labels map[string]string
|
Labels map[string]string `compose:"labels",bundle:"Labels"`
|
||||||
Annotations map[string]string
|
Annotations map[string]string `compose:"",bundle:""`
|
||||||
CPUSet string
|
CPUSet string `compose:"cpuset",bundle:""`
|
||||||
CPUShares int64
|
CPUShares int64 `compose:"cpu_shares",bundle:""`
|
||||||
CPUQuota int64
|
CPUQuota int64 `compose:"cpu_quota",bundle:""`
|
||||||
CapAdd []string
|
CapAdd []string `compose:"cap_add",bundle:""`
|
||||||
CapDrop []string
|
CapDrop []string `compose:"cap_drop",bundle:""`
|
||||||
Expose []string
|
Expose []string `compose:"expose",bundle:""`
|
||||||
Privileged bool
|
Privileged bool `compose:"privileged",bundle:""`
|
||||||
Restart string
|
Restart string `compose:"restart",bundle:""`
|
||||||
User string
|
User string `compose:"user",bundle:"User"`
|
||||||
VolumesFrom []string
|
VolumesFrom []string `compose:"volumes_from",bundle:""`
|
||||||
ServiceType string
|
ServiceType string `compose:"kompose.service.type",bundle:""`
|
||||||
Build string
|
Build string `compose:"build",bundle:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnvVar holds the environment variable struct of a container
|
// EnvVar holds the environment variable struct of a container
|
||||||
|
|||||||
@ -18,11 +18,13 @@ package kubernetes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/fatih/structs"
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/transformer"
|
"github.com/kubernetes-incubator/kompose/pkg/transformer"
|
||||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||||
@ -52,6 +54,52 @@ type Kubernetes struct {
|
|||||||
// used when undeploying resources from kubernetes
|
// used when undeploying resources from kubernetes
|
||||||
const TIMEOUT = 300
|
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
|
// Init RC object
|
||||||
func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController {
|
func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController {
|
||||||
rc := &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
|
// Transform maps komposeObject to k8s objects
|
||||||
// returns object that are already sorted in the way that Services are first
|
// 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 {
|
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
|
// this will hold all the converted data
|
||||||
var allobjects []runtime.Object
|
var allobjects []runtime.Object
|
||||||
|
|
||||||
|
|||||||
@ -33,11 +33,12 @@ import (
|
|||||||
oclient "github.com/openshift/origin/pkg/client"
|
oclient "github.com/openshift/origin/pkg/client"
|
||||||
ocliconfig "github.com/openshift/origin/pkg/cmd/cli/config"
|
ocliconfig "github.com/openshift/origin/pkg/cmd/cli/config"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||||
deploymentconfigreaper "github.com/openshift/origin/pkg/deploy/cmd"
|
deploymentconfigreaper "github.com/openshift/origin/pkg/deploy/cmd"
|
||||||
imageapi "github.com/openshift/origin/pkg/image/api"
|
imageapi "github.com/openshift/origin/pkg/image/api"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OpenShift struct {
|
type OpenShift struct {
|
||||||
@ -51,6 +52,13 @@ type OpenShift struct {
|
|||||||
// used when undeploying resources from OpenShift
|
// used when undeploying resources from OpenShift
|
||||||
const TIMEOUT = 300
|
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{}
|
||||||
|
|
||||||
// getImageTag get tag name from image name
|
// getImageTag get tag name from image name
|
||||||
// if no tag is specified return 'latest'
|
// if no tag is specified return 'latest'
|
||||||
func getImageTag(image string) string {
|
func getImageTag(image string) string {
|
||||||
@ -151,6 +159,10 @@ func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceCon
|
|||||||
// Transform maps komposeObject to openshift objects
|
// Transform maps komposeObject to openshift objects
|
||||||
// returns objects that are already sorted in the way that Services are first
|
// returns objects that are already sorted in the way that Services are first
|
||||||
func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) []runtime.Object {
|
func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) []runtime.Object {
|
||||||
|
noSupKeys := o.Kubernetes.CheckUnsupportedKey(&komposeObject, unsupportedKey)
|
||||||
|
for _, keyName := range noSupKeys {
|
||||||
|
logrus.Warningf("OpenShift provider doesn't support %s key - ignoring", keyName)
|
||||||
|
}
|
||||||
// this will hold all the converted data
|
// this will hold all the converted data
|
||||||
var allobjects []runtime.Object
|
var allobjects []runtime.Object
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user