forked from LaconicNetwork/kompose
add support for golangci-lint (#1373)
This commit is contained in:
@@ -197,7 +197,6 @@ func (b *Bundle) LoadFile(files []string) (kobject.KomposeObject, error) {
|
||||
}
|
||||
|
||||
for name, service := range bundle.Services {
|
||||
|
||||
serviceConfig := kobject.ServiceConfig{}
|
||||
serviceConfig.Command = service.Command
|
||||
serviceConfig.Args = service.Args
|
||||
|
||||
@@ -83,5 +83,4 @@ func TestUnsupportedKeys(t *testing.T) {
|
||||
t.Errorf("ERROR: Expecting unsupported keys: ['%s']. Got: ['%s']", strings.Join(test.expectedUnsupportedKeys, "', '"), strings.Join(keys, "', '"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ type Compose struct {
|
||||
// list of all unsupported keys are stored in unsupportedKey variable
|
||||
// returns list of unsupported YAML keys from docker-compose
|
||||
func checkUnsupportedKey(composeProject *project.Project) []string {
|
||||
|
||||
// list of all unsupported keys for this loader
|
||||
// this is map to make searching for keys easier
|
||||
// to make sure that unsupported key is not going to be reported twice
|
||||
@@ -132,7 +131,6 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
||||
if !findUnsupportedLinksFlag {
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
keysFound = append(keysFound, yamlTagName)
|
||||
@@ -146,7 +144,6 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
||||
|
||||
// LoadFile loads a compose file into KomposeObject
|
||||
func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
|
||||
|
||||
// Load the json / yaml file in order to get the version value
|
||||
var version string
|
||||
|
||||
@@ -183,9 +180,8 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
|
||||
}
|
||||
return komposeObject, nil
|
||||
default:
|
||||
return kobject.KomposeObject{}, fmt.Errorf("Version %s of Docker Compose is not supported. Please use version 1, 2 or 3", version)
|
||||
return kobject.KomposeObject{}, fmt.Errorf("version %s of Docker Compose is not supported. Please use version 1, 2 or 3", version)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getVersionFromFile(file string) (string, error) {
|
||||
|
||||
@@ -34,10 +34,6 @@ import (
|
||||
api "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func durationPtr(value time.Duration) *time.Duration {
|
||||
return &value
|
||||
}
|
||||
|
||||
func durationTypesPtr(value time.Duration) *types.Duration {
|
||||
target := types.Duration(value)
|
||||
return &target
|
||||
@@ -85,7 +81,6 @@ func TestLoadV3Volumes(t *testing.T) {
|
||||
if output[0] != expected {
|
||||
t.Errorf("Expected %s, got %s", expected, output[0])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLoadV3Ports(t *testing.T) {
|
||||
@@ -400,7 +395,6 @@ func TestUnsupportedKeys(t *testing.T) {
|
||||
t.Errorf("ERROR: Expecting unsupported keys: ['%s']. Got: ['%s']", strings.Join(test.expectedUnsupportedKeys, "', '"), strings.Join(keys, "', '"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNormalizeServiceNames(t *testing.T) {
|
||||
@@ -463,14 +457,11 @@ func TestCheckLabelsPorts(t *testing.T) {
|
||||
err = checkLabelsPorts(testcase.noOfPort, testcase.labels, testcase.svcName)
|
||||
if testcase.expectError && err == nil {
|
||||
t.Log("Expected error, got ", err)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPlacementCustomLabels(t *testing.T) {
|
||||
|
||||
placement := types.Placement{
|
||||
Constraints: []string{
|
||||
"node.labels.something == anything",
|
||||
@@ -484,5 +475,4 @@ func TestCheckPlacementCustomLabels(t *testing.T) {
|
||||
if output["something"] != expected["something"] {
|
||||
t.Errorf("Expected %s, got %s", expected, output)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -168,5 +168,4 @@ func ReadFile(fileName string) ([]byte, error) {
|
||||
return StdinData, nil
|
||||
}
|
||||
return ioutil.ReadFile(fileName)
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import (
|
||||
// Parse Docker Compose with libcompose (only supports v1 and v2). Eventually we will
|
||||
// switch to using only libcompose once v3 is supported.
|
||||
func parseV1V2(files []string) (kobject.KomposeObject, error) {
|
||||
|
||||
// Gather the appropriate context for parsing
|
||||
context := &project.Context{}
|
||||
context.ComposeFiles = files
|
||||
@@ -169,7 +168,6 @@ func loadPorts(composePorts []string, expose []string) ([]kobject.Ports, error)
|
||||
|
||||
// Uses libcompose's APIProject type and converts it to a Kompose object for us to understand
|
||||
func libComposeToKomposeMapping(composeObject *project.Project) (kobject.KomposeObject, error) {
|
||||
|
||||
// Initialize what's going to be returned
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
@@ -336,7 +334,6 @@ func retrieveVolume(svcName string, komposeObject kobject.KomposeObject) (volume
|
||||
cv.PVCName = dv.PVCName
|
||||
}
|
||||
volume = append(volume, cv)
|
||||
|
||||
}
|
||||
// iterating over dependent volumes
|
||||
for _, dv := range dVols {
|
||||
@@ -366,7 +363,6 @@ func checkVolDependent(dv kobject.Volumes, volume []kobject.Volumes) bool {
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
// ParseVols parse volumes
|
||||
@@ -409,7 +405,6 @@ func getGroupAdd(group []string) ([]int64, error) {
|
||||
return nil, errors.Wrap(err, "unable to get group_add key")
|
||||
}
|
||||
groupAdd = append(groupAdd, int64(j))
|
||||
|
||||
}
|
||||
return groupAdd, nil
|
||||
}
|
||||
|
||||
Executable → Regular
+3
-13
@@ -60,7 +60,6 @@ func buildEnvironment() (map[string]string, error) {
|
||||
// v3 of Docker Compose into a suitable format. In this case, whatever is returned
|
||||
// by docker/cli's ServiceConfig
|
||||
func parseV3(files []string) (kobject.KomposeObject, error) {
|
||||
|
||||
// In order to get V3 parsing to work, we have to go through some preliminary steps
|
||||
// for us to hack up github.com/docker/cli in order to correctly convert to a kobject.KomposeObject
|
||||
|
||||
@@ -163,7 +162,6 @@ func loadV3Placement(constraints []string) map[string]string {
|
||||
// TODO: Refactor it similar to loadV3Ports
|
||||
// See: https://docs.docker.com/compose/compose-file/#long-syntax-3
|
||||
func loadV3Volumes(volumes []types.ServiceVolumeConfig) []string {
|
||||
|
||||
var volArray []string
|
||||
for _, vol := range volumes {
|
||||
// There will *always* be Source when parsing
|
||||
@@ -197,11 +195,10 @@ func loadV3Ports(ports []types.ServicePortConfig, expose []string) []kobject.Por
|
||||
HostPort: int32(port.Published),
|
||||
ContainerPort: int32(port.Target),
|
||||
HostIP: "",
|
||||
Protocol: api.Protocol(strings.ToUpper(string(port.Protocol))),
|
||||
Protocol: api.Protocol(strings.ToUpper(port.Protocol)),
|
||||
})
|
||||
|
||||
exist[cast.ToString(port.Target)+strings.ToUpper(string(port.Protocol))] = true
|
||||
|
||||
exist[cast.ToString(port.Target)+strings.ToUpper(port.Protocol)] = true
|
||||
}
|
||||
|
||||
if expose != nil {
|
||||
@@ -233,7 +230,6 @@ func loadV3Ports(ports []types.ServicePortConfig, expose []string) []kobject.Por
|
||||
a Kubernetes-compatible format.
|
||||
*/
|
||||
func parseHealthCheckReadiness(labels types.Labels) (kobject.HealthCheck, error) {
|
||||
|
||||
// initialize with CMD as default to not break at return (will be ignored if no test is informed)
|
||||
test := []string{"CMD"}
|
||||
var timeout, interval, retries, startPeriod int32
|
||||
@@ -293,7 +289,6 @@ func parseHealthCheckReadiness(labels types.Labels) (kobject.HealthCheck, error)
|
||||
a Kubernetes-compatible format.
|
||||
*/
|
||||
func parseHealthCheck(composeHealthCheck types.HealthCheckConfig) (kobject.HealthCheck, error) {
|
||||
|
||||
var timeout, interval, retries, startPeriod int32
|
||||
|
||||
// Here we convert the timeout from 1h30s (example) to 36030 seconds.
|
||||
@@ -336,7 +331,6 @@ func parseHealthCheck(composeHealthCheck types.HealthCheckConfig) (kobject.Healt
|
||||
}
|
||||
|
||||
func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.KomposeObject, error) {
|
||||
|
||||
// Step 1. Initialize what's going to be returned
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||
@@ -348,7 +342,6 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
|
||||
// Here we "clean up" the service configuration so we return something that includes
|
||||
// all relevant information as well as avoid the unsupported keys as well.
|
||||
for _, composeServiceConfig := range composeObject.Services {
|
||||
|
||||
// Standard import
|
||||
// No need to modify before importation
|
||||
name := composeServiceConfig.Name
|
||||
@@ -500,7 +493,6 @@ func parseV3Network(composeServiceConfig *types.ServiceConfig, serviceConfig *ko
|
||||
|
||||
func parseV3Resources(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) error {
|
||||
if (composeServiceConfig.Deploy.Resources != types.Resources{}) {
|
||||
|
||||
// memory:
|
||||
// TODO: Refactor yaml.MemStringorInt in kobject.go to int64
|
||||
// cpu:
|
||||
@@ -533,7 +525,6 @@ func parseV3Resources(composeServiceConfig *types.ServiceConfig, serviceConfig *
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func parseV3Environment(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) {
|
||||
@@ -648,7 +639,7 @@ func getV3VolumeLabels(name string, volumes *map[string]types.VolumeConfig) (str
|
||||
|
||||
func mergeComposeObject(oldCompose *types.Config, newCompose *types.Config) (*types.Config, error) {
|
||||
if oldCompose == nil || newCompose == nil {
|
||||
return nil, fmt.Errorf("Merge multiple compose error, compose config is nil")
|
||||
return nil, fmt.Errorf("merge multiple compose error, compose config is nil")
|
||||
}
|
||||
oldComposeServiceNameMap := make(map[string]int, len(oldCompose.Services))
|
||||
for index, service := range oldCompose.Services {
|
||||
@@ -895,7 +886,6 @@ func checkUnsupportedKeyForV3(composeObject *types.Config) []string {
|
||||
|
||||
if service.CredentialSpec.Registry != "" || service.CredentialSpec.File != "" {
|
||||
keysFound = append(keysFound, "credential_spec")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,8 @@ func GetLoader(format string) (Loader, error) {
|
||||
case "compose":
|
||||
l = new(compose.Compose)
|
||||
default:
|
||||
return nil, fmt.Errorf("Input file format %s is not supported", format)
|
||||
return nil, fmt.Errorf("input file format %s is not supported", format)
|
||||
}
|
||||
|
||||
return l, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user