1
0
Fork 0

chore: update docker and k8s

This commit is contained in:
Ludovic Fernandez 2019-08-05 18:24:03 +02:00 committed by Traefiker Bot
parent 2b5c7f9e91
commit c2d440a914
1283 changed files with 67741 additions and 27918 deletions

View file

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"strconv"
"strings"
"reflect"
@ -11,6 +12,7 @@ import (
"github.com/docker/docker/pkg/urlutil"
"github.com/docker/libcompose/utils"
composeYaml "github.com/docker/libcompose/yaml"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
@ -25,14 +27,37 @@ var (
}
)
// CreateConfig unmarshals bytes to config and creates config based on version
func getComposeMajorVersion(version string) (int, error) {
if version == "" {
return 1, nil
}
parts := strings.Split(version, ".")
if len(parts) == 1 {
return strconv.Atoi(version)
} else if len(parts) == 2 {
return strconv.Atoi(parts[0])
} else {
return -1, fmt.Errorf("Invalid version string, expected single integer or dot delimited int.int. Got: %s", version)
}
}
// CreateConfig unmarshals bytes of a YAML manifest file and returns a new
// Config. Initialize any defaults that can't be parsed (but are optional)
// across various file formats. Most of these can remain unused.
//
// This function only handles parsing YAML in the general case. Any other file
// format validation should be handled by the caller.
func CreateConfig(bytes []byte) (*Config, error) {
var config Config
if err := yaml.Unmarshal(bytes, &config); err != nil {
return nil, err
}
if config.Version != "2" {
major, err := getComposeMajorVersion(config.Version)
if err != nil {
return nil, err
}
if major < 2 {
var baseRawServices RawServiceMap
if err := yaml.Unmarshal(bytes, &baseRawServices); err != nil {
return nil, err
@ -102,14 +127,22 @@ func Merge(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup
}
}
major, err := getComposeMajorVersion(config.Version)
if err != nil {
return "", nil, nil, nil, err
}
var serviceConfigs map[string]*ServiceConfig
if config.Version == "2" {
switch major {
case 3:
logrus.Fatal("Note: Compose file version 3 is not yet implemented")
case 2:
var err error
serviceConfigs, err = MergeServicesV2(existingServices, environmentLookup, resourceLookup, file, baseRawServices, options)
if err != nil {
return "", nil, nil, nil, err
}
} else {
default:
serviceConfigsV1, err := MergeServicesV1(existingServices, environmentLookup, resourceLookup, file, baseRawServices, options)
if err != nil {
return "", nil, nil, nil, err

View file

@ -219,7 +219,11 @@ var servicesSchemaDataV2 = `{
"properties": {
"context": {"type": "string"},
"dockerfile": {"type": "string"},
"args": {"$ref": "#/definitions/list_or_dict"}
"args": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"$ref": "#/definitions/list_of_strings"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"network": {"type": "string"},
"target": {"type": "string"}
},
"additionalProperties": false
}

View file

@ -32,15 +32,19 @@ type (
portsFormatChecker struct{}
)
func (checker environmentFormatChecker) IsFormat(input string) bool {
func (checker environmentFormatChecker) IsFormat(input interface{}) bool {
// If the value is a boolean, a warning should be given
// However, we can't determine type since gojsonschema converts the value to a string
// Adding a function with an interface{} parameter to gojsonschema is probably the best way to handle this
return true
}
func (checker portsFormatChecker) IsFormat(input string) bool {
_, _, err := nat.ParsePortSpecs([]string{input})
func (checker portsFormatChecker) IsFormat(input interface{}) bool {
in, ok := input.(string)
if !ok {
return true
}
_, _, err := nat.ParsePortSpecs([]string{in})
return err == nil
}

View file

@ -201,7 +201,7 @@ func generateErrorMessages(serviceMap RawServiceMap, schema map[string]interface
if err.Context().String() == "(root)" {
switch err.Type() {
case "additional_property_not_allowed":
validationErrors = append(validationErrors, fmt.Sprintf("Invalid service name '%s' - only [a-zA-Z0-9\\._\\-] characters are allowed", err.Field()))
validationErrors = append(validationErrors, fmt.Sprintf("Invalid service name '%s' - only [a-zA-Z0-9\\._\\-] characters are allowed", err.Details()["property"]))
default:
validationErrors = append(validationErrors, err.Description())
}
@ -213,7 +213,7 @@ func generateErrorMessages(serviceMap RawServiceMap, schema map[string]interface
switch err.Type() {
case "additional_property_not_allowed":
validationErrors = append(validationErrors, unsupportedConfigMessage(key, result.Errors()[i+1]))
validationErrors = append(validationErrors, unsupportedConfigMessage(result.Errors()[i].Details()["property"].(string), result.Errors()[i]))
case "number_one_of":
validationErrors = append(validationErrors, fmt.Sprintf("Service '%s' configuration key '%s' %s", serviceName, key, oneOfMessage(serviceMap, schema, err, result.Errors()[i+1])))