Skip to content

Commit

Permalink
Merge pull request #912 from BenTheElder/bespoke-config
Browse files Browse the repository at this point in the history
roll our own strict config loading
  • Loading branch information
k8s-ci-robot authored Oct 15, 2019
2 parents c151aa0 + 53bd2eb commit f97b720
Show file tree
Hide file tree
Showing 26 changed files with 335 additions and 721 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.13

require (
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053
github.com/google/gofuzz v1.0.0
github.com/google/uuid v1.1.1
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.3
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b // indirect
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
sigs.k8s.io/kustomize/v3 v3.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652 h1:VKvJ/mQ4BgCjZUDggYFxTe0qv9jPMHsZPD4Xt91Y5H4=
gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20190313235455-40a48860b5ab/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbuQba2w+SXqezo=
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
Expand Down
6 changes: 0 additions & 6 deletions hack/update/generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ cd "${REPO_ROOT}"

# build the generators using the tools module
cd "hack/tools"
"${REPO_ROOT}/hack/go_container.sh" go build -o /out/defaulter-gen k8s.io/code-generator/cmd/defaulter-gen
"${REPO_ROOT}/hack/go_container.sh" go build -o /out/deepcopy-gen k8s.io/code-generator/cmd/deepcopy-gen
"${REPO_ROOT}/hack/go_container.sh" go build -o /out/conversion-gen k8s.io/code-generator/cmd/conversion-gen
# go back to the root
cd "${REPO_ROOT}"

Expand All @@ -47,11 +45,7 @@ cd "${FAKE_REPOPATH}"

# run the generators
bin/deepcopy-gen -i ./pkg/internal/apis/config/ -O zz_generated.deepcopy --go-header-file hack/tools/boilerplate.go.txt
bin/defaulter-gen -i ./pkg/internal/apis/config/ -O zz_generated.default --go-header-file hack/tools/boilerplate.go.txt

bin/deepcopy-gen -i ./pkg/apis/config/v1alpha3 -O zz_generated.deepcopy --go-header-file hack/tools/boilerplate.go.txt
bin/defaulter-gen -i ./pkg/apis/config/v1alpha3 -O zz_generated.default --go-header-file hack/tools/boilerplate.go.txt
bin/conversion-gen -i ./pkg/internal/apis/config/v1alpha3 -O zz_generated.conversion --go-header-file hack/tools/boilerplate.go.txt

# set module mode back, return to repo root and gofmt to ensure we format generated code
export GO111MODULE="on"
Expand Down
23 changes: 9 additions & 14 deletions pkg/apis/config/v1alpha3/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// this comment makes golint ignore this file, feel free to edit the file.
// Code generated by not-actually-generated-but-go-away-golint. DO NOT EDIT.
// https://github.com/kubernetes/code-generator/issues/30

package v1alpha3

import (
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/kind/pkg/apis/config/defaults"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

// SetDefaults_Cluster sets uninitialized fields to their default value.
func SetDefaults_Cluster(obj *Cluster) {
// SetDefaultsCluster sets uninitialized fields to their default value.
func SetDefaultsCluster(obj *Cluster) {
// default to a one node cluster
if len(obj.Nodes) == 0 {
obj.Nodes = []Node{
Expand All @@ -41,6 +31,11 @@ func SetDefaults_Cluster(obj *Cluster) {
},
}
}
// default the nodes
for i := range obj.Nodes {
a := &obj.Nodes[i]
SetDefaultsNode(a)
}
if obj.Networking.IPFamily == "" {
obj.Networking.IPFamily = "ipv4"
}
Expand Down Expand Up @@ -70,8 +65,8 @@ func SetDefaults_Cluster(obj *Cluster) {
}
}

// SetDefaults_Node sets uninitialized fields to their default value.
func SetDefaults_Node(obj *Node) {
// SetDefaultsNode sets uninitialized fields to their default value.
func SetDefaultsNode(obj *Node) {
if obj.Image == "" {
obj.Image = defaults.Image
}
Expand Down
55 changes: 0 additions & 55 deletions pkg/apis/config/v1alpha3/register.go

This file was deleted.

54 changes: 28 additions & 26 deletions pkg/apis/config/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,40 @@ limitations under the License.
package v1alpha3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/kind/pkg/container/cri"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Cluster contains kind cluster configuration
type Cluster struct {
// TypeMeta representing the type of the object and its API schema version.
metav1.TypeMeta `json:",inline"`
TypeMeta `yaml:",inline" json:",inline"`

// Nodes contains the list of nodes defined in the `kind` Cluster
// If unset this will default to a single control-plane node
// Note that if more than one control plane is specified, an external
// control plane load balancer will be provisioned implicitly
Nodes []Node `json:"nodes,omitempty"`
Nodes []Node `yaml:"nodes,omitempty" json:"nodes,omitempty"`

/* Advanced fields */

// Networking contains cluster wide network settings
Networking Networking `json:"networking,omitempty"`
Networking Networking `yaml:"networking,omitempty" json:"networking,omitempty"`

// KubeadmConfigPatches are applied to the generated kubeadm config as
// strategic merge patches to `kustomize build` internally
// https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md
// This should be an inline yaml blob-string
KubeadmConfigPatches []string `json:"kubeadmConfigPatches,omitempty"`
KubeadmConfigPatches []string `yaml:"kubeadmConfigPatches,omitempty" json:"kubeadmConfigPatches,omitempty"`

// KubeadmConfigPatchesJSON6902 are applied to the generated kubeadm config
// as patchesJson6902 to `kustomize build`
KubeadmConfigPatchesJSON6902 []PatchJSON6902 `json:"kubeadmConfigPatchesJson6902,omitempty"`
KubeadmConfigPatchesJSON6902 []PatchJSON6902 `yaml:"kubeadmConfigPatchesJson6902,omitempty" json:"kubeadmConfigPatchesJson6902,omitempty"`
}

// TypeMeta partially copies apimachinery/pkg/apis/meta/v1.TypeMeta
// No need for a direct dependence; the fields are stable.
type TypeMeta struct {
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
}

// Node contains settings for a node in the `kind` Cluster.
Expand All @@ -59,22 +61,22 @@ type Node struct {
// created by kind
//
// Defaults to "control-plane"
Role NodeRole `json:"role,omitempty"`
Role NodeRole `yaml:"role,omitempty" json:"role,omitempty"`

// Image is the node image to use when creating this node
// If unset a default image will be used, see defaults.Image
Image string `json:"image,omitempty"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`

/* Advanced fields */

// TODO: cri-like types should be inline instead
// ExtraMounts describes additional mount points for the node container
// These may be used to bind a hostPath
ExtraMounts []cri.Mount `json:"extraMounts,omitempty"`
ExtraMounts []cri.Mount `yaml:"extraMounts,omitempty" json:"extraMounts,omitempty"`

// ExtraPortMappings describes additional port mappings for the node container
// binded to a host Port
ExtraPortMappings []cri.PortMapping `json:"extraPortMappings,omitempty"`
ExtraPortMappings []cri.PortMapping `yaml:"extraPortMappings,omitempty" json:"extraPortMappings,omitempty"`
}

// NodeRole defines possible role for nodes in a Kubernetes cluster managed by `kind`
Expand All @@ -93,24 +95,24 @@ const (
// Networking contains cluster wide network settings
type Networking struct {
// IPFamily is the network cluster model, currently it can be ipv4 or ipv6
IPFamily ClusterIPFamily `json:"ipFamily,omitempty"`
IPFamily ClusterIPFamily `yaml:"ipFamily,omitempty" json:"ipFamily,omitempty"`
// APIServerPort is the listen port on the host for the Kubernetes API Server
// Defaults to a random port on the host
APIServerPort int32 `json:"apiServerPort,omitempty"`
APIServerPort int32 `yaml:"apiServerPort,omitempty" json:"apiServerPort,omitempty"`
// APIServerAddress is the listen address on the host for the Kubernetes
// API Server. This should be an IP address.
//
// Defaults to 127.0.0.1
APIServerAddress string `json:"apiServerAddress,omitempty"`
APIServerAddress string `yaml:"apiServerAddress,omitempty" json:"apiServerAddress,omitempty"`
// PodSubnet is the CIDR used for pod IPs
// kind will select a default if unspecified
PodSubnet string `json:"podSubnet,omitempty"`
PodSubnet string `yaml:"podSubnet,omitempty" json:"podSubnet,omitempty"`
// ServiceSubnet is the CIDR used for services VIPs
// kind will select a default if unspecified for IPv6
ServiceSubnet string `json:"serviceSubnet,omitempty"`
ServiceSubnet string `yaml:"serviceSubnet,omitempty" json:"serviceSubnet,omitempty"`
// If DisableDefaultCNI is true, kind will not install the default CNI setup.
// Instead the user should install their own CNI after creating the cluster.
DisableDefaultCNI bool `json:"disableDefaultCNI,omitempty"`
DisableDefaultCNI bool `yaml:"disableDefaultCNI,omitempty" json:"disableDefaultCNI,omitempty"`
}

// ClusterIPFamily defines cluster network IP family
Expand All @@ -127,14 +129,14 @@ const (
// https://tools.ietf.org/html/rfc6902
type PatchJSON6902 struct {
// these fields specify the patch target resource
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
Group string `yaml:"group" json:"group"`
Version string `yaml:"version" json:"version"`
Kind string `yaml:"kind" json:"kind"`
// Name and Namespace are optional
// NOTE: technically name is required now, but we default it elsewhere
// Third party users of this type / library would need to set it.
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Namespace string `yaml:"name,omitempty" json:"namespace,omitempty"`
// Patch should contain the contents of the json patch as a string
Patch string `json:"patch"`
Patch string `yaml:"patch" json:"patch"`
}
25 changes: 16 additions & 9 deletions pkg/apis/config/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions pkg/apis/config/v1alpha3/zz_generated.default.go

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/cluster/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func WithConfigFile(path string) ClusterOption {
// WithV1Alpha3 configures creating the cluster with a v1alpha3 config
func WithV1Alpha3(cluster *v1alpha3.Cluster) ClusterOption {
return func(o *internaltypes.ClusterOptions) (*internaltypes.ClusterOptions, error) {
cfg, err := internalencoding.V1Alpha3ToInternal(cluster)
o.Config = cfg
return o, err
o.Config = internalencoding.V1Alpha3ToInternal(cluster)
return o, nil
}
}

Expand Down
Loading

0 comments on commit f97b720

Please sign in to comment.