Skip to content

Commit

Permalink
roll our own config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Oct 3, 2019
1 parent bab9ba1 commit d0f4a5a
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 665 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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
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.

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
73 changes: 73 additions & 0 deletions pkg/internal/apis/config/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

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

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

func Convertv1alpha3(in *v1alpha3.Cluster) *Cluster {
out := &Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: runtime.APIVersionInternal,
},
Nodes: make([]Node, len(in.Nodes)),
KubeadmConfigPatches: in.KubeadmConfigPatches,
KubeadmConfigPatchesJSON6902: make([]PatchJSON6902, len(in.KubeadmConfigPatchesJSON6902)),
}

for i := range in.Nodes {
convertv1alpha3Node(&in.Nodes[i], &out.Nodes[i])
}

convertv1alpha3Networking(&in.Networking, &out.Networking)

for i := range in.KubeadmConfigPatchesJSON6902 {
convertv1alphaPatchJSON6902(&in.KubeadmConfigPatchesJSON6902[i], &out.KubeadmConfigPatchesJSON6902[i])
}

return out
}

func convertv1alpha3Node(in *v1alpha3.Node, out *Node) {
out.Role = NodeRole(in.Role)
out.Image = in.Image
out.ExtraMounts = in.ExtraMounts
out.ExtraPortMappings = in.ExtraPortMappings
}

func convertv1alphaPatchJSON6902(in *v1alpha3.PatchJSON6902, out *PatchJSON6902) {
out.Group = in.Group
out.Version = in.Version
out.Kind = in.Kind
out.Name = in.Name
out.Namespace = in.Namespace
out.Patch = in.Patch
}

func convertv1alpha3Networking(in *v1alpha3.Networking, out *Networking) {
out.IPFamily = ClusterIPFamily(in.IPFamily)
out.APIServerPort = in.APIServerPort
out.APIServerAddress = in.APIServerAddress
out.PodSubnet = in.PodSubnet
out.ServiceSubnet = in.ServiceSubnet
out.DisableDefaultCNI = in.DisableDefaultCNI
}
19 changes: 9 additions & 10 deletions pkg/internal/apis/config/default.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha3 contains conversions for the v1alpha3 config types
// +k8s:conversion-gen=sigs.k8s.io/kind/pkg/internal/apis/config
// +k8s:conversion-gen-external-types=sigs.k8s.io/kind/pkg/apis/config/v1alpha3
package v1alpha3
package encoding

import (
"sigs.k8s.io/kind/pkg/apis/config/v1alpha3"

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

// V1Alpha3ToInternal converts to the internal API version
func V1Alpha3ToInternal(cluster *v1alpha3.Cluster) *config.Cluster {
v1alpha3.SetDefaultsCluster(cluster)
return config.Convertv1alpha3(cluster)
}
Loading

0 comments on commit d0f4a5a

Please sign in to comment.