forked from LaconicNetwork/kompose
Fix kompose.image-pull-secret invalid issue when use compose configs (#1414)
This commit is contained in:
parent
b2dee807a2
commit
e8966d9e2c
@ -185,6 +185,14 @@ func (k *Kubernetes) InitPodSpecWithConfigMap(name string, image string, service
|
||||
},
|
||||
Volumes: volumes,
|
||||
}
|
||||
|
||||
if service.ImagePullSecret != "" {
|
||||
pod.ImagePullSecrets = []api.LocalObjectReference{
|
||||
{
|
||||
Name: service.ImagePullSecret,
|
||||
},
|
||||
}
|
||||
}
|
||||
return pod
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
dockerCliTypes "github.com/docker/cli/cli/compose/types"
|
||||
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
"github.com/kubernetes/kompose/pkg/loader/compose"
|
||||
"github.com/kubernetes/kompose/pkg/transformer"
|
||||
@ -38,30 +40,33 @@ import (
|
||||
|
||||
func newServiceConfig() kobject.ServiceConfig {
|
||||
return kobject.ServiceConfig{
|
||||
Name: "app",
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456}, kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: api.ProtocolUDP}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
VolList: []string{"/tmp/volume"},
|
||||
Network: []string{"network1", "network2"}, // supported
|
||||
Labels: nil,
|
||||
Annotations: map[string]string{"abc": "def"},
|
||||
CPUQuota: 1, // not supported
|
||||
CapAdd: []string{"cap_add"},
|
||||
CapDrop: []string{"cap_drop"},
|
||||
Expose: []string{"expose"}, // not supported
|
||||
Privileged: true,
|
||||
Restart: "always",
|
||||
Stdin: true,
|
||||
Tty: true,
|
||||
TmpFs: []string{"/tmp"},
|
||||
Replicas: 2,
|
||||
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
|
||||
GroupAdd: []int64{1003, 1005},
|
||||
Name: "app",
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456}, kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: api.ProtocolUDP}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
VolList: []string{"/tmp/volume"},
|
||||
Network: []string{"network1", "network2"}, // supported
|
||||
Labels: nil,
|
||||
Annotations: map[string]string{"abc": "def"},
|
||||
CPUQuota: 1, // not supported
|
||||
CapAdd: []string{"cap_add"},
|
||||
CapDrop: []string{"cap_drop"},
|
||||
Expose: []string{"expose"}, // not supported
|
||||
Privileged: true,
|
||||
Restart: "always",
|
||||
ImagePullSecret: "regcred",
|
||||
Stdin: true,
|
||||
Tty: true,
|
||||
TmpFs: []string{"/tmp"},
|
||||
Replicas: 2,
|
||||
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
|
||||
GroupAdd: []int64{1003, 1005},
|
||||
Configs: []dockerCliTypes.ServiceConfigObjConfig{{Source: "config", Target: "/etc/world"}},
|
||||
ConfigsMetaData: map[string]dockerCliTypes.ConfigObjConfig{"config": dockerCliTypes.ConfigObjConfig{Name: "myconfig", File: "kubernetes_test.go"}},
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +168,7 @@ func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec
|
||||
if !equalStringSlice(config.Args, container.Args) {
|
||||
return fmt.Errorf("Found different container args: %#v vs. %#v", config.Args, container.Args)
|
||||
}
|
||||
if len(template.Spec.Volumes) == 0 || len(template.Spec.Volumes[0].Name) == 0 || template.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim == nil {
|
||||
if len(template.Spec.Volumes) == 0 || len(template.Spec.Volumes[0].Name) == 0 || template.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim == nil && template.Spec.Volumes[0].ConfigMap == nil {
|
||||
return fmt.Errorf("Found incorrect volumes: %v vs. %#v", config.Volumes, template.Spec.Volumes)
|
||||
}
|
||||
// We only set controller labels here and k8s server will take care of other defaults, such as selectors
|
||||
@ -183,6 +188,9 @@ func checkPodTemplate(config kobject.ServiceConfig, template api.PodTemplateSpec
|
||||
if config.Tty != template.Spec.Containers[0].TTY {
|
||||
return fmt.Errorf("Found different values for TTY: %#v vs. %#v", config.Tty, template.Spec.Containers[0].TTY)
|
||||
}
|
||||
if config.ImagePullSecret != template.Spec.ImagePullSecrets[0].Name {
|
||||
return fmt.Errorf("Found different values for ImagePullSecrets: %#v vs. %#v", config.ImagePullSecret, template.Spec.ImagePullSecrets[0].Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -281,12 +289,12 @@ func TestKomposeConvert(t *testing.T) {
|
||||
expectedNumObjs int
|
||||
}{
|
||||
// objects generated are deployment, service nework policies (2) and pvc
|
||||
"Convert to Deployments (D)": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, Replicas: replicas, IsReplicaSetFlag: true}, 5},
|
||||
"Convert to Deployments (D) with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true}, 5},
|
||||
"Convert to DaemonSets (DS)": {newKomposeObject(), kobject.ConvertOptions{CreateDS: true}, 5},
|
||||
"Convert to Deployments (D)": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, Replicas: replicas, IsReplicaSetFlag: true}, 6},
|
||||
"Convert to Deployments (D) with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true}, 6},
|
||||
"Convert to DaemonSets (DS)": {newKomposeObject(), kobject.ConvertOptions{CreateDS: true}, 6},
|
||||
// objects generated are deployment, daemonset, ReplicationController, service and pvc
|
||||
"Convert to D, DS, and RC": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true, Replicas: replicas, IsReplicaSetFlag: true}, 6},
|
||||
"Convert to D, DS, and RC with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true}, 6},
|
||||
"Convert to D, DS, and RC": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true, Replicas: replicas, IsReplicaSetFlag: true}, 7},
|
||||
"Convert to D, DS, and RC with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true}, 7},
|
||||
// TODO: add more tests
|
||||
}
|
||||
|
||||
@ -578,21 +586,21 @@ func TestMultipleContainersInPod(t *testing.T) {
|
||||
"app1": createConfig("app1", &containerName),
|
||||
"app2": createConfig("app2", &containerName),
|
||||
},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true}, 2, []string{"app1", "app2"}},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true}, 3, []string{"app1", "app2"}},
|
||||
"Converted multiple containers to Deployments (D)": {
|
||||
kobject.KomposeObject{
|
||||
ServiceConfigs: map[string]kobject.ServiceConfig{
|
||||
"app1": createConfig("app1", &containerName),
|
||||
"app2": createConfig("app2", &containerName),
|
||||
},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true, CreateD: true}, 3, []string{"app1", "app2"}},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true, CreateD: true}, 4, []string{"app1", "app2"}},
|
||||
"Converted multiple containers (ContainerName are nil) to Deployments (D)": {
|
||||
kobject.KomposeObject{
|
||||
ServiceConfigs: map[string]kobject.ServiceConfig{
|
||||
"app1": createConfig("app1", nil),
|
||||
"app2": createConfig("app2", nil),
|
||||
},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true, CreateD: true}, 3, []string{"name", "name"}},
|
||||
}, kobject.ConvertOptions{MultipleContainerMode: true, CreateD: true}, 4, []string{"name", "name"}},
|
||||
// TODO: add more tests
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user