forked from LaconicNetwork/kompose
few updates based on review
This commit is contained in:
parent
af9c6585ee
commit
3419ae7fe1
@ -21,7 +21,9 @@ 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 is name of the loader that created KomposeObject
|
||||||
|
// Transformer need to know origin format in order to tell user what tag is not supported in origin format
|
||||||
|
// as they can have different names. For example environment variables are called environment in compose but Env in bundle.
|
||||||
LoadedFrom string
|
LoadedFrom string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,10 +66,10 @@ type Port struct {
|
|||||||
func checkUnsupportedKey(bundleStruct *Bundlefile) []string {
|
func checkUnsupportedKey(bundleStruct *Bundlefile) []string {
|
||||||
// list of all unsupported keys for this loader
|
// list of all unsupported keys for this loader
|
||||||
// this is map to make searching for keys easier
|
// this is map to make searching for keys easier
|
||||||
// also counts how many times was given key found in service
|
// to make sure that unsupported key is not going to be reported twice
|
||||||
// to make sure that we show warning only once for every key
|
// by keeping record if already saw this key in another service
|
||||||
var unsupportedKey = map[string]int{
|
var unsupportedKey = map[string]bool{
|
||||||
"Networks": 0,
|
"Networks": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect all keys found in project
|
// collect all keys found in project
|
||||||
@ -80,25 +80,23 @@ func checkUnsupportedKey(bundleStruct *Bundlefile) []string {
|
|||||||
s := structs.New(service)
|
s := structs.New(service)
|
||||||
|
|
||||||
for _, f := range s.Fields() {
|
for _, f := range s.Fields() {
|
||||||
if f.IsExported() && !f.IsZero() {
|
// Check if given key is among unsupported keys, and skip it if we already saw this key
|
||||||
jsonTagName := strings.Split(f.Tag("json"), ",")[0]
|
if alreadySaw, ok := unsupportedKey[f.Name()]; ok && !alreadySaw {
|
||||||
if jsonTagName == "" {
|
if f.IsExported() && !f.IsZero() {
|
||||||
jsonTagName = f.Name()
|
jsonTagName := strings.Split(f.Tag("json"), ",")[0]
|
||||||
}
|
if jsonTagName == "" {
|
||||||
|
jsonTagName = f.Name()
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
// IsZero returns false for empty array/slice ([])
|
||||||
if counter, ok := unsupportedKey[f.Name()]; ok {
|
// this check if field is Slice, and then it checks its size
|
||||||
if counter == 0 {
|
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
||||||
keysFound = append(keysFound, jsonTagName)
|
if field.Len() == 0 {
|
||||||
|
// array is empty it doesn't matter if it is in unsupportedKey or not
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unsupportedKey[f.Name()]++
|
keysFound = append(keysFound, jsonTagName)
|
||||||
|
unsupportedKey[f.Name()] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,39 +45,39 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
|||||||
|
|
||||||
// list of all unsupported keys for this loader
|
// list of all unsupported keys for this loader
|
||||||
// this is map to make searching for keys easier
|
// this is map to make searching for keys easier
|
||||||
// also counts how many times was given key found in service
|
// to make sure that unsupported key is not going to be reported twice
|
||||||
// to make sure that we show warning only once for every key
|
// by keeping record if already saw this key in another service
|
||||||
var unsupportedKey = map[string]int{
|
var unsupportedKey = map[string]bool{
|
||||||
"CgroupParent": 0,
|
"CgroupParent": false,
|
||||||
"Devices": 0,
|
"Devices": false,
|
||||||
"DependsOn": 0,
|
"DependsOn": false,
|
||||||
"DNS": 0,
|
"DNS": false,
|
||||||
"DNSSearch": 0,
|
"DNSSearch": false,
|
||||||
"DomainName": 0,
|
"DomainName": false,
|
||||||
"EnvFile": 0,
|
"EnvFile": false,
|
||||||
"Extends": 0,
|
"Extends": false,
|
||||||
"ExternalLinks": 0,
|
"ExternalLinks": false,
|
||||||
"ExtraHosts": 0,
|
"ExtraHosts": false,
|
||||||
"Hostname": 0,
|
"Hostname": false,
|
||||||
"Ipc": 0,
|
"Ipc": false,
|
||||||
"Logging": 0,
|
"Logging": false,
|
||||||
"MacAddress": 0,
|
"MacAddress": false,
|
||||||
"MemLimit": 0,
|
"MemLimit": false,
|
||||||
"MemSwapLimit": 0,
|
"MemSwapLimit": false,
|
||||||
"NetworkMode": 0,
|
"NetworkMode": false,
|
||||||
"Pid": 0,
|
"Pid": false,
|
||||||
"SecurityOpt": 0,
|
"SecurityOpt": false,
|
||||||
"ShmSize": 0,
|
"ShmSize": false,
|
||||||
"StopSignal": 0,
|
"StopSignal": false,
|
||||||
"VolumeDriver": 0,
|
"VolumeDriver": false,
|
||||||
"Uts": 0,
|
"Uts": false,
|
||||||
"ReadOnly": 0,
|
"ReadOnly": false,
|
||||||
"StdinOpen": 0,
|
"StdinOpen": false,
|
||||||
"Tty": 0,
|
"Tty": false,
|
||||||
"Ulimits": 0,
|
"Ulimits": false,
|
||||||
"Dockerfile": 0,
|
"Dockerfile": false,
|
||||||
"Net": 0,
|
"Net": false,
|
||||||
"Networks": 0, // there are special checks for Network in checkUnsupportedKey function996607
|
"Networks": false, // there are special checks for Network in checkUnsupportedKey function
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect all keys found in project
|
// collect all keys found in project
|
||||||
@ -98,17 +98,17 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
|||||||
s := structs.New(serviceConfig)
|
s := structs.New(serviceConfig)
|
||||||
|
|
||||||
for _, f := range s.Fields() {
|
for _, f := range s.Fields() {
|
||||||
if f.IsExported() && !f.IsZero() {
|
// Check if given key is among unsupported keys, and skip it if we already saw this key
|
||||||
// IsZero returns false for empty array/slice ([])
|
if alreadySaw, ok := unsupportedKey[f.Name()]; ok && !alreadySaw {
|
||||||
// this check if field is Slice, and then it checks its size
|
if f.IsExported() && !f.IsZero() {
|
||||||
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
// IsZero returns false for empty array/slice ([])
|
||||||
if field.Len() == 0 {
|
// this check if field is Slice, and then it checks its size
|
||||||
// array is empty it doesn't metter if it is in unsupportedKey or not
|
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
||||||
continue
|
if field.Len() == 0 {
|
||||||
|
// array is empty it doesn't matter if it is in unsupportedKey or not
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if counter, ok := unsupportedKey[f.Name()]; ok {
|
|
||||||
//get yaml tag name instad of variable name
|
//get yaml tag name instad of variable name
|
||||||
yamlTagName := strings.Split(f.Tag("yaml"), ",")[0]
|
yamlTagName := strings.Split(f.Tag("yaml"), ",")[0]
|
||||||
if f.Name() == "Networks" {
|
if f.Name() == "Networks" {
|
||||||
@ -120,10 +120,8 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
|||||||
yamlTagName = "networks"
|
yamlTagName = "networks"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if counter == 0 {
|
keysFound = append(keysFound, yamlTagName)
|
||||||
keysFound = append(keysFound, yamlTagName)
|
unsupportedKey[f.Name()] = true
|
||||||
}
|
|
||||||
unsupportedKey[f.Name()]++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,6 +140,21 @@ func TestUnsupportedKeys(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
projectWithNetworks.ServiceConfigs.Add("bar", &config.ServiceConfig{
|
||||||
|
Image: "bar/foo",
|
||||||
|
Build: yaml.Build{
|
||||||
|
Context: "./build",
|
||||||
|
},
|
||||||
|
Hostname: "localhost",
|
||||||
|
Ports: []string{}, // test empty array
|
||||||
|
Networks: &yaml.Networks{
|
||||||
|
Networks: []*yaml.Network{
|
||||||
|
&yaml.Network{
|
||||||
|
Name: "net1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
projectWithNetworks.VolumeConfigs = map[string]*config.VolumeConfig{
|
projectWithNetworks.VolumeConfigs = map[string]*config.VolumeConfig{
|
||||||
"foo": &config.VolumeConfig{
|
"foo": &config.VolumeConfig{
|
||||||
Driver: "storage",
|
Driver: "storage",
|
||||||
|
|||||||
@ -57,17 +57,17 @@ const TIMEOUT = 300
|
|||||||
// list of all unsupported keys for this transformer
|
// list of all unsupported keys for this transformer
|
||||||
// Keys are names of variables in kobject struct.
|
// Keys are names of variables in kobject struct.
|
||||||
// this is map to make searching for keys easier
|
// this is map to make searching for keys easier
|
||||||
// also counts how many times was given key found in kobject
|
// to make sure that unsupported key is not going to be reported twice
|
||||||
// to make sure that we show warning only once for every key
|
// by keeping record if already saw this key in another service
|
||||||
var unsupportedKey = map[string]int{
|
var unsupportedKey = map[string]bool{
|
||||||
"Build": 0,
|
"Build": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkUnsupportedKey checks if given komposeObject contains
|
// checkUnsupportedKey checks if given komposeObject contains
|
||||||
// keys that are not supported by this tranfomer.
|
// keys that are not supported by this tranfomer.
|
||||||
// list of all unsupported keys are stored in unsupportedKey variable
|
// list of all unsupported keys are stored in unsupportedKey variable
|
||||||
// returns list of TODO: ....
|
// returns list of TODO: ....
|
||||||
func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, unsupportedKey map[string]int) []string {
|
func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, unsupportedKey map[string]bool) []string {
|
||||||
// collect all keys found in project
|
// collect all keys found in project
|
||||||
var keysFound []string
|
var keysFound []string
|
||||||
|
|
||||||
@ -77,22 +77,22 @@ func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, u
|
|||||||
s := structs.New(serviceConfig)
|
s := structs.New(serviceConfig)
|
||||||
|
|
||||||
for _, f := range s.Fields() {
|
for _, f := range s.Fields() {
|
||||||
if f.IsExported() && !f.IsZero() {
|
// Check if given key is among unsupported keys, and skip it if we already saw this key
|
||||||
// IsZero returns false for empty array/slice ([])
|
if alreadySaw, ok := unsupportedKey[f.Name()]; ok && !alreadySaw {
|
||||||
// this check if field is Slice, and then it checks its size
|
|
||||||
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
if f.IsExported() && !f.IsZero() {
|
||||||
if field.Len() == 0 {
|
// IsZero returns false for empty array/slice ([])
|
||||||
// array is empty it doesn't metter if it is in unsupportedKey or not
|
// this check if field is Slice, and then it checks its size
|
||||||
continue
|
if field := val.FieldByName(f.Name()); field.Kind() == reflect.Slice {
|
||||||
|
if field.Len() == 0 {
|
||||||
|
// array is empty it doesn't matter if it is in unsupportedKey or not
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//get tag from kobject service configure
|
||||||
if counter, ok := unsupportedKey[f.Name()]; ok {
|
tag := f.Tag(komposeObject.LoadedFrom)
|
||||||
if counter == 0 {
|
keysFound = append(keysFound, tag)
|
||||||
//get tag from kobject service configure
|
unsupportedKey[f.Name()] = true
|
||||||
tag := f.Tag(komposeObject.LoadedFrom)
|
|
||||||
keysFound = append(keysFound, tag)
|
|
||||||
}
|
|
||||||
unsupportedKey[f.Name()]++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,9 +55,9 @@ const TIMEOUT = 300
|
|||||||
// list of all unsupported keys for this transformer
|
// list of all unsupported keys for this transformer
|
||||||
// Keys are names of variables in kobject struct.
|
// Keys are names of variables in kobject struct.
|
||||||
// this is map to make searching for keys easier
|
// this is map to make searching for keys easier
|
||||||
// also counts how many times was given key found in kobject
|
// to make sure that unsupported key is not going to be reported twice
|
||||||
// to make sure that we show warning only once for every key
|
// by keeping record if already saw this key in another service
|
||||||
var unsupportedKey = map[string]int{}
|
var unsupportedKey = map[string]bool{}
|
||||||
|
|
||||||
// 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'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user