Skip to content

Commit

Permalink
Merge pull request #457 from justinsb/split_out_docker_config
Browse files Browse the repository at this point in the history
Split out docker config
  • Loading branch information
justinsb authored Sep 17, 2016
2 parents 4e26a95 + a30cc2a commit ce4b3ef
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 16 deletions.
4 changes: 0 additions & 4 deletions upup/pkg/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ type ClusterSpec struct {
//
//TestCluster string `json:",omitempty"`
//
//DockerOptions string `json:",omitempty"`
//DockerStorage string `json:",omitempty"`
//ExtraDockerOpts string `json:",omitempty"`
//
//E2EStorageTestEnvironment string `json:",omitempty"`
//KubeletTestArgs string `json:",omitempty"`
//KubeletTestLogLevel string `json:",omitempty"`
Expand Down
10 changes: 0 additions & 10 deletions upup/pkg/api/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,6 @@ type KubeProxyConfig struct {
//ConntrackTCPEstablishedTimeout unversioned.Duration `json:"conntrackTCPEstablishedTimeout"`
}

type DockerConfig struct {
Bridge string `json:"bridge,omitempty" flag:"bridge"`
LogLevel string `json:"logLevel,omitempty" flag:"log-level"`
IPTables *bool `json:"ipTables,omitempty" flag:"iptables"`
IPMasq *bool `json:"ipMasq,omitempty" flag:"ip-masq"`
Storage string `json:"storage,omitempty" flag:"storage-driver"`
InsecureRegistry string `json:"insecureRegistry,omitempty" flag:"insecure-registry"`
MTU *int `json:"mtu,omitempty" flag:"mtu"`
}

type KubeAPIServerConfig struct {
PathSrvKubernetes string `json:"pathSrvKubernetes,omitempty"`
PathSrvSshproxy string `json:"pathSrvSshproxy,omitempty"`
Expand Down
23 changes: 23 additions & 0 deletions upup/pkg/api/dockerconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package api

import (
"k8s.io/kubernetes/pkg/util/validation/field"
)

type DockerConfig struct {
Bridge *string `json:"bridge,omitempty" flag:"bridge"`
LogLevel *string `json:"logLevel,omitempty" flag:"log-level"`
IPTables *bool `json:"ipTables,omitempty" flag:"iptables"`
IPMasq *bool `json:"ipMasq,omitempty" flag:"ip-masq"`
Storage *string `json:"storage,omitempty" flag:"storage-driver"`
InsecureRegistry *string `json:"insecureRegistry,omitempty" flag:"insecure-registry"`
MTU *int `json:"mtu,omitempty" flag:"mtu"`
}

var validDockerConfigStorageValues = []string{"aufs", "btrfs", "devicemapper", "overlay", "overlay2", "zfs"}

func ValidateDockerConfig(config *DockerConfig, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, IsValidValue(fldPath.Child("storage"), config.Storage, validDockerConfigStorageValues)...)
return allErrs
}
27 changes: 27 additions & 0 deletions upup/pkg/api/dockerconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package api

import (
"k8s.io/kubernetes/pkg/util/validation/field"
"testing"
)

func Test_Validate_DockerConfig_Storage(t *testing.T) {
for _, name := range []string{"aufs", "zfs", "overlay"} {
config := &DockerConfig{Storage: &name}
errs := ValidateDockerConfig(config, field.NewPath("docker"))
if len(errs) != 0 {
t.Fatalf("Unexpected errors validating DockerConfig %q", errs)
}
}

for _, name := range []string{"overlayfs", "", "au"} {
config := &DockerConfig{Storage: &name}
errs := ValidateDockerConfig(config, field.NewPath("docker"))
if len(errs) != 1 {
t.Fatalf("Expected errors validating DockerConfig %q", config)
}
if errs[0].Field != "docker.storage" || errs[0].Type != field.ErrorTypeNotSupported {
t.Fatalf("Not the expected error validating DockerConfig %q", errs)
}
}
}
18 changes: 18 additions & 0 deletions upup/pkg/api/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kubernetes/pkg/util/validation"
"k8s.io/kubernetes/pkg/util/validation/field"
"net"
"net/url"
"strings"
Expand Down Expand Up @@ -344,3 +345,20 @@ func isSubnet(parent *net.IPNet, child *net.IPNet) bool {
func subnetsOverlap(l *net.IPNet, r *net.IPNet) bool {
return l.Contains(r.IP) || r.Contains(l.IP)
}

func IsValidValue(fldPath *field.Path, v *string, validValues []string) field.ErrorList {
allErrs := field.ErrorList{}
if v != nil {
found := false
for _, validValue := range validValues {
if *v == validValue {
found = true
break
}
}
if !found {
allErrs = append(allErrs, field.NotSupported(fldPath, *v, validValues))
}
}
return allErrs
}
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/populatecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestPopulateCluster_Docker_Spec(t *testing.T) {
c := buildMinimalCluster()
c.Spec.Docker = &api.DockerConfig{
MTU: fi.Int(5678),
InsecureRegistry: "myregistry.com:1234",
InsecureRegistry: fi.String("myregistry.com:1234"),
}

err := c.PerformAssignments()
Expand All @@ -89,7 +89,7 @@ func TestPopulateCluster_Docker_Spec(t *testing.T) {
t.Fatalf("Unexpected Docker MTU: %v", full.Spec.Docker.MTU)
}

if full.Spec.Docker.InsecureRegistry != "myregistry.com:1234" {
if fi.StringValue(full.Spec.Docker.InsecureRegistry) != "myregistry.com:1234" {
t.Fatalf("Unexpected Docker InsecureRegistry: %v", full.Spec.Docker.InsecureRegistry)
}
}
Expand Down

0 comments on commit ce4b3ef

Please sign in to comment.