mirror of https://github.com/docker/compose.git
Fix linter
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
f1976eca07
commit
5306f38f70
|
@ -1,17 +1,17 @@
|
|||
package compose
|
||||
|
||||
const (
|
||||
LABEL_DOCKER_COMPOSE_PREFIX = "com.docker.compose"
|
||||
LABEL_SERVICE = LABEL_DOCKER_COMPOSE_PREFIX + ".service"
|
||||
LABEL_VERSION = LABEL_DOCKER_COMPOSE_PREFIX + ".version"
|
||||
LABEL_CONTAINER_NUMBER = LABEL_DOCKER_COMPOSE_PREFIX + ".container-number"
|
||||
LABEL_ONE_OFF = LABEL_DOCKER_COMPOSE_PREFIX + ".oneoff"
|
||||
LABEL_NETWORK = LABEL_DOCKER_COMPOSE_PREFIX + ".network"
|
||||
LABEL_SLUG = LABEL_DOCKER_COMPOSE_PREFIX + ".slug"
|
||||
LABEL_VOLUME = LABEL_DOCKER_COMPOSE_PREFIX + ".volume"
|
||||
LABEL_CONFIG_HASH = LABEL_DOCKER_COMPOSE_PREFIX + ".config-hash"
|
||||
LABEL_PROJECT = LABEL_DOCKER_COMPOSE_PREFIX + ".project"
|
||||
LABEL_WORKING_DIR = LABEL_DOCKER_COMPOSE_PREFIX + ".working_dir"
|
||||
LABEL_CONFIG_FILES = LABEL_DOCKER_COMPOSE_PREFIX + ".config_files"
|
||||
LABEL_ENVIRONMENT_FILE = LABEL_DOCKER_COMPOSE_PREFIX + ".environment_file"
|
||||
LabelDockerComposePrefix = "com.docker.compose"
|
||||
LabelService = LabelDockerComposePrefix + ".service"
|
||||
LabelVersion = LabelDockerComposePrefix + ".version"
|
||||
LabelContainerNumber = LabelDockerComposePrefix + ".container-number"
|
||||
LabelOneOff = LabelDockerComposePrefix + ".oneoff"
|
||||
LabelNetwork = LabelDockerComposePrefix + ".network"
|
||||
LabelSlug = LabelDockerComposePrefix + ".slug"
|
||||
LabelVolume = LabelDockerComposePrefix + ".volume"
|
||||
LabelConfigHash = LabelDockerComposePrefix + ".config-hash"
|
||||
LabelProject = LabelDockerComposePrefix + ".project"
|
||||
LabelWorkingDir = LabelDockerComposePrefix + ".working_dir"
|
||||
LabelConfigFiles = LabelDockerComposePrefix + ".config_files"
|
||||
LabelEnvironmentFile = LabelDockerComposePrefix + ".environment_file"
|
||||
)
|
||||
|
|
|
@ -2,6 +2,9 @@ package convert
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
|
@ -9,13 +12,11 @@ import (
|
|||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MapToKubernetesObjects(model *compose.Project) (map[string]runtime.Object, error) {
|
||||
objects := map[string]runtime.Object{}
|
||||
for _, service := range model.Services {
|
||||
for _, service := range model.Services {
|
||||
objects[fmt.Sprintf("%s-service.yaml", service.Name)] = mapToService(model, service)
|
||||
if service.Deploy != nil && service.Deploy.Mode == "global" {
|
||||
daemonset, err := mapToDaemonset(service, model)
|
||||
|
@ -94,13 +95,13 @@ func mapToDeployment(service types.ServiceConfig, model *compose.Project) (*apps
|
|||
|
||||
return &apps.Deployment{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: service.Name,
|
||||
Name: service.Name,
|
||||
Labels: labels,
|
||||
},
|
||||
Spec: apps.DeploymentSpec{
|
||||
Replicas: toReplicas(service.Deploy),
|
||||
Strategy: toDeploymentStrategy(service.Deploy),
|
||||
Template: podTemplate,
|
||||
Spec: apps.DeploymentSpec{
|
||||
Replicas: toReplicas(service.Deploy),
|
||||
Strategy: toDeploymentStrategy(service.Deploy),
|
||||
Template: podTemplate,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
@ -126,7 +127,6 @@ func mapToDaemonset(service types.ServiceConfig, model *compose.Project) (*apps.
|
|||
}, nil
|
||||
}
|
||||
|
||||
|
||||
func toReplicas(deploy *types.DeployConfig) *int32 {
|
||||
v := int32(1)
|
||||
if deploy != nil {
|
||||
|
@ -156,11 +156,11 @@ func toDeploymentStrategy(deploy *types.DeployConfig) apps.DeploymentStrategy {
|
|||
func mapToPVC(service types.ServiceConfig, vol types.ServiceVolumeConfig) runtime.Object {
|
||||
return &core.PersistentVolumeClaim{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: vol.Source,
|
||||
Labels: map[string]string{"com.docker.compose.service": service.Name},
|
||||
Name: vol.Source,
|
||||
Labels: map[string]string{"com.docker.compose.service": service.Name},
|
||||
},
|
||||
Spec: core.PersistentVolumeClaimSpec{
|
||||
VolumeName: vol.Source,
|
||||
Spec: core.PersistentVolumeClaimSpec{
|
||||
VolumeName: vol.Source,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,15 @@ package convert
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
|
@ -31,14 +32,14 @@ func toPodTemplate(serviceConfig types.ServiceConfig, labels map[string]string,
|
|||
return apiv1.PodTemplateSpec{}, err
|
||||
}
|
||||
|
||||
var limits apiv1.ResourceList = nil
|
||||
var limits apiv1.ResourceList
|
||||
if serviceConfig.Deploy != nil && serviceConfig.Deploy.Resources.Limits != nil {
|
||||
limits, err = toResource(serviceConfig.Deploy.Resources.Limits)
|
||||
if err != nil {
|
||||
return apiv1.PodTemplateSpec{}, err
|
||||
}
|
||||
}
|
||||
var requests apiv1.ResourceList = nil
|
||||
var requests apiv1.ResourceList
|
||||
if serviceConfig.Deploy != nil && serviceConfig.Deploy.Resources.Reservations != nil {
|
||||
requests, err = toResource(serviceConfig.Deploy.Resources.Reservations)
|
||||
if err != nil {
|
||||
|
@ -54,10 +55,10 @@ func toPodTemplate(serviceConfig types.ServiceConfig, labels map[string]string,
|
|||
if err != nil {
|
||||
return apiv1.PodTemplateSpec{}, err
|
||||
}
|
||||
/* pullPolicy, err := toImagePullPolicy(serviceConfig.Image, x-kubernetes-pull-policy)
|
||||
if err != nil {
|
||||
return apiv1.PodTemplateSpec{}, err
|
||||
} */
|
||||
/* pullPolicy, err := toImagePullPolicy(serviceConfig.Image, x-kubernetes-pull-policy)
|
||||
if err != nil {
|
||||
return apiv1.PodTemplateSpec{}, err
|
||||
} */
|
||||
tpl.ObjectMeta = metav1.ObjectMeta{
|
||||
Labels: labels,
|
||||
Annotations: serviceConfig.Labels,
|
||||
|
|
|
@ -2,15 +2,16 @@ package convert
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/compose-spec/compose-go/loader"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func loadYAML(yaml string) (*compose.Project, error) {
|
||||
|
@ -256,7 +257,7 @@ services:
|
|||
assert.Len(t, podTemplate.Spec.Containers[0].VolumeMounts, 2)
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithRelativeVolumes(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithRelativeVolumes(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("on windows, source path validation is broken (and actually, source validation for windows workload is broken too). Skip it for now, as we don't support it yet")
|
||||
return
|
||||
|
@ -401,7 +402,7 @@ services:
|
|||
assert.Equal(t, expectedMount, podTemplate.Spec.Containers[0].VolumeMounts[0])
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithFileBasedSecret(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithFileBasedSecret(t *testing.T) {
|
||||
podTemplate := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -442,7 +443,7 @@ secrets:
|
|||
assert.Equal(t, expectedMount, podTemplate.Spec.Containers[0].VolumeMounts[0])
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithTwoFileBasedSecrets(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithTwoFileBasedSecrets(t *testing.T) {
|
||||
podTemplate := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -603,7 +604,7 @@ services:
|
|||
assert.Equal(t, expectedMount, podTemplate.Spec.Containers[0].VolumeMounts[0])
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithFileBasedConfig(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithFileBasedConfig(t *testing.T) {
|
||||
podTemplate := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -653,7 +654,7 @@ configs:
|
|||
assert.Equal(t, expectedMount, podTemplate.Spec.Containers[0].VolumeMounts[0])
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithTargetlessFileBasedConfig(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithTargetlessFileBasedConfig(t *testing.T) {
|
||||
podTemplate := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -746,7 +747,7 @@ configs:
|
|||
assert.Equal(t, expectedMount, podTemplate.Spec.Containers[0].VolumeMounts[0])
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithTwoConfigsSameMountPoint(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithTwoConfigsSameMountPoint(t *testing.T) {
|
||||
podTemplate := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -897,7 +898,7 @@ configs:
|
|||
assert.Equal(t, expectedMounts, podTemplate.Spec.Containers[0].VolumeMounts)
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithPullSecret(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithPullSecret(t *testing.T) {
|
||||
podTemplateWithSecret := podTemplate(t, `
|
||||
version: "3"
|
||||
services:
|
||||
|
@ -919,7 +920,7 @@ services:
|
|||
assert.Nil(t, podTemplateNoSecret.Spec.ImagePullSecrets)
|
||||
}
|
||||
|
||||
func /*FIXME Test*/ToPodWithPullPolicy(t *testing.T) {
|
||||
func /*FIXME Test*/ ToPodWithPullPolicy(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
stack string
|
||||
|
|
|
@ -2,12 +2,13 @@ package convert
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/helm-prototype/pkg/compose"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
|
|
@ -3,16 +3,17 @@ package helm
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"gopkg.in/yaml.v3"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
func Write(project string, objects map[string]runtime.Object, target string) error {
|
||||
out := Outputer{ target }
|
||||
out := Outputer{target}
|
||||
|
||||
if err := out.Write("README.md", []byte("This chart was created by converting a Compose file")); err != nil {
|
||||
return err
|
||||
|
@ -38,7 +39,6 @@ home:
|
|||
var chartData bytes.Buffer
|
||||
_ = t.Execute(&chartData, ChartDetails{project})
|
||||
|
||||
|
||||
if err := out.Write("Chart.yaml", chartData.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -93,4 +93,4 @@ func jsonToYaml(j []byte, spaces int) ([]byte, error) {
|
|||
|
||||
// Marshal this object into YAML.
|
||||
// return yaml.Marshal(jsonObj)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue