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,
|
Volumes: volumes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if service.ImagePullSecret != "" {
|
||||||
|
pod.ImagePullSecrets = []api.LocalObjectReference{
|
||||||
|
{
|
||||||
|
Name: service.ImagePullSecret,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
dockerCliTypes "github.com/docker/cli/cli/compose/types"
|
||||||
|
|
||||||
"github.com/kubernetes/kompose/pkg/kobject"
|
"github.com/kubernetes/kompose/pkg/kobject"
|
||||||
"github.com/kubernetes/kompose/pkg/loader/compose"
|
"github.com/kubernetes/kompose/pkg/loader/compose"
|
||||||
"github.com/kubernetes/kompose/pkg/transformer"
|
"github.com/kubernetes/kompose/pkg/transformer"
|
||||||
@ -56,12 +58,15 @@ func newServiceConfig() kobject.ServiceConfig {
|
|||||||
Expose: []string{"expose"}, // not supported
|
Expose: []string{"expose"}, // not supported
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
Restart: "always",
|
Restart: "always",
|
||||||
|
ImagePullSecret: "regcred",
|
||||||
Stdin: true,
|
Stdin: true,
|
||||||
Tty: true,
|
Tty: true,
|
||||||
TmpFs: []string{"/tmp"},
|
TmpFs: []string{"/tmp"},
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
|
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
|
||||||
GroupAdd: []int64{1003, 1005},
|
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) {
|
if !equalStringSlice(config.Args, container.Args) {
|
||||||
return fmt.Errorf("Found different container args: %#v vs. %#v", 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)
|
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
|
// 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 {
|
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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,12 +289,12 @@ func TestKomposeConvert(t *testing.T) {
|
|||||||
expectedNumObjs int
|
expectedNumObjs int
|
||||||
}{
|
}{
|
||||||
// objects generated are deployment, service nework policies (2) and pvc
|
// 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)": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, Replicas: replicas, IsReplicaSetFlag: true}, 6},
|
||||||
"Convert to Deployments (D) with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true}, 5},
|
"Convert to Deployments (D) with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true}, 6},
|
||||||
"Convert to DaemonSets (DS)": {newKomposeObject(), kobject.ConvertOptions{CreateDS: true}, 5},
|
"Convert to DaemonSets (DS)": {newKomposeObject(), kobject.ConvertOptions{CreateDS: true}, 6},
|
||||||
// objects generated are deployment, daemonset, ReplicationController, service and pvc
|
// 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": {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}, 6},
|
"Convert to D, DS, and RC with v3 replicas": {newKomposeObject(), kobject.ConvertOptions{CreateD: true, CreateDS: true, CreateRC: true}, 7},
|
||||||
// TODO: add more tests
|
// TODO: add more tests
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,21 +586,21 @@ func TestMultipleContainersInPod(t *testing.T) {
|
|||||||
"app1": createConfig("app1", &containerName),
|
"app1": createConfig("app1", &containerName),
|
||||||
"app2": createConfig("app2", &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)": {
|
"Converted multiple containers to Deployments (D)": {
|
||||||
kobject.KomposeObject{
|
kobject.KomposeObject{
|
||||||
ServiceConfigs: map[string]kobject.ServiceConfig{
|
ServiceConfigs: map[string]kobject.ServiceConfig{
|
||||||
"app1": createConfig("app1", &containerName),
|
"app1": createConfig("app1", &containerName),
|
||||||
"app2": createConfig("app2", &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)": {
|
"Converted multiple containers (ContainerName are nil) to Deployments (D)": {
|
||||||
kobject.KomposeObject{
|
kobject.KomposeObject{
|
||||||
ServiceConfigs: map[string]kobject.ServiceConfig{
|
ServiceConfigs: map[string]kobject.ServiceConfig{
|
||||||
"app1": createConfig("app1", nil),
|
"app1": createConfig("app1", nil),
|
||||||
"app2": createConfig("app2", 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
|
// TODO: add more tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user