Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement v1alpha3 #373

Merged
merged 19 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hack/update-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ go generate ./...
deepcopy-gen -i ./pkg/cluster/config/ -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/ -O zz_generated.default --go-header-file hack/boilerplate.go.txt

deepcopy-gen -i ./pkg/cluster/config/v1alpha1 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/v1alpha1 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
conversion-gen -i ./pkg/cluster/config/v1alpha1 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt

deepcopy-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.deepcopy --go-header-file hack/boilerplate.go.txt
defaulter-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.default --go-header-file hack/boilerplate.go.txt
conversion-gen -i ./pkg/cluster/config/v1alpha2 -O zz_generated.conversion --go-header-file hack/boilerplate.go.txt

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

# gofmt the tree
find . -path "./vendor" -prune -o -name "*.go" -type f -print0 | xargs -0 gofmt -s -w
4 changes: 2 additions & 2 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ get_golint() {
GOLINT="${GOLINT:-$(get_golint)}"

# we need to do this because golint ./... matches vendor...
# we also further filter out generated k8s api code in the config v1alpha1 package
# we also further filter out generated k8s api code in the config packages
# which unfortunately fails lint due to apimachinery conventions ...
# TODO(fabrizio pandini): makes this smarter (skip only one file)
# TODO(bentheelder): we also have to skip hack/tools for now because this is just
# for go modules tracking of tools and has otherwise invalid imports
# TODO(bentheelder): find a solution that does not depend on GO111MODULE="off"
GO111MODULE="off" go list ./... | \
grep -v '^hack/tools$' |\
grep -v '^sigs.k8s.io/kind/pkg/cluster/config/v1alpha1$' | \
grep -v '^sigs.k8s.io/kind/pkg/cluster/config/v1alpha2$' | \
grep -v '^sigs.k8s.io/kind/pkg/cluster/config/v1alpha3$' | \
grep -v '^sigs.k8s.io/kind/pkg/cluster/config$' | \
xargs -L1 "${GOLINT}" -set_exit_status
4 changes: 2 additions & 2 deletions pkg/cluster/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

// SetDefaults_Config sets uninitialized fields to their default value.
func SetDefaults_Config(obj *Config) {
// SetDefaults_Cluster sets uninitialized fields to their default value.
func SetDefaults_Cluster(obj *Cluster) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I didn't think defaults were usually applied as part of the internal API version? Although I could definitely be wrong 😄 (/me goes away to dig into Kubernetes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to default the internal type as well currently because its used by library consumers 🤔

if len(obj.Nodes) == 0 {
obj.Nodes = []Node{
{
Expand Down
14 changes: 7 additions & 7 deletions pkg/cluster/config/encoding/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"sigs.k8s.io/kind/pkg/cluster/config"
"sigs.k8s.io/kind/pkg/cluster/config/v1alpha1"
"sigs.k8s.io/kind/pkg/cluster/config/v1alpha2"
"sigs.k8s.io/kind/pkg/cluster/config/v1alpha3"
)

// Scheme is the runtime.Scheme to which all `kind` config API versions and types are registered.
Expand All @@ -43,16 +43,16 @@ func init() {
// AddToScheme builds the scheme using all known `kind` API versions.
func AddToScheme(scheme *runtime.Scheme) {
utilruntime.Must(config.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(v1alpha3.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1alpha2.SchemeGroupVersion))
utilruntime.Must(scheme.SetVersionPriority(v1alpha3.SchemeGroupVersion))
}

// Load reads the file at path and attempts to convert into a `kind` Config; the file
// can be one of the different API versions defined in scheme.
// If path == "" then the default config is returned
func Load(path string) (*config.Config, error) {
var latestPublicConfig = &v1alpha2.Config{}
func Load(path string) (*config.Cluster, error) {
var latestPublicConfig = &v1alpha3.Cluster{}

if path != "" {
// read in file
Expand All @@ -63,7 +63,7 @@ func Load(path string) (*config.Config, error) {

// decode data into a internal api Config object because
// to leverage on conversion functions for all the api versions
var cfg = &config.Config{}
var cfg = &config.Cluster{}
err = runtime.DecodeInto(Codecs.UniversalDecoder(), contents, cfg)
if err != nil {
return nil, errors.Wrap(err, "decoding failure")
Expand All @@ -77,7 +77,7 @@ func Load(path string) (*config.Config, error) {
Scheme.Default(latestPublicConfig)

// converts to internal config
var cfg = &config.Config{}
var cfg = &config.Cluster{}
Scheme.Convert(latestPublicConfig, cfg, nil)

// unmarshal the file content into a `kind` Config
Expand Down
12 changes: 0 additions & 12 deletions pkg/cluster/config/encoding/scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ func TestLoadCurrent(t *testing.T) {
ExpectReplicas: []string{"control-plane"}, // no config (empty config path) should return a single node cluster
ExpectError: false,
},
{
TestName: "v1alpha1 minimal",
Path: "./testdata/v1alpha1/valid-minimal.yaml",
ExpectReplicas: []string{"control-plane"},
ExpectError: false,
},
{
TestName: "v1alpha1 with lifecyclehooks",
Path: "./testdata/v1alpha1/valid-with-lifecyclehooks.yaml",
ExpectReplicas: []string{"control-plane"},
ExpectError: false,
},
{
TestName: "v1alpha2 minimal",
Path: "./testdata/v1alpha2/valid-minimal.yaml",
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/cluster/config/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
}
}

func fuzzConfig(obj *config.Config, c fuzz.Continue) {
func fuzzConfig(obj *config.Cluster, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// Pinning values for fields that get defaults if fuzz value is empty string or nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/config/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
localSchemeBuilder.Register(addKnownTypes, addDefaultingFuncs)
}

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Config{},
&Cluster{},
)

return nil
Expand Down
64 changes: 30 additions & 34 deletions pkg/cluster/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,54 @@ import (

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

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

// Nodes contains the list of nodes defined in the `kind` Config
Nodes []Node `json:"nodes,"`
}
// Nodes contains the list of nodes defined in the `kind` Cluster
Nodes []Node `json:"nodes"`
BenTheElder marked this conversation as resolved.
Show resolved Hide resolved

/* Advanced fields */

// Node contains settings for a node in the `kind` Config.
// A node in kind config represent a container that will be provisioned with all the components
// required for the assigned role in the Kubernetes cluster.
// If replicas is set, the desired node replica number will be generated.
type Node struct {
// Replicas is the number of desired node replicas.
// Defaults to 1
Replicas *int32
// Role defines the role of the node in the in the Kubernetes cluster managed by `kind`
// Defaults to "control-plane"
Role NodeRole
// Image is the node image to use when running the cluster
// TODO(bentheelder): split this into image and tag?
Image string
// 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
KubeadmConfigPatches []string `json:"kubeadmConfigPatches,omitempty"`

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

// Node contains settings for a node in the `kind` Cluster.
// A node in kind config represent a container that will be provisioned with all the components
// required for the assigned role in the Kubernetes cluster
type Node struct {
// Role defines the role of the node in the in the Kubernetes cluster
// created by kind
//
// Defaults to "control-plane"
Role NodeRole `json:"role,omitempty"`

// Image is the node image to use when creating this node
Image string `json:"image,omitempty"`

/* Advanced fields */

// ExtraMounts describes additional mount points for the node container
// These may be used to bind a hostpath
// These may be used to bind a hostPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bind a hostPath into a single node container?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ER isn't it implied that they're bound to the current node?

ExtraMounts []cri.Mount `json:"extraMounts,omitempty"`
}

// NodeRole defines possible role for nodes in a Kubernetes cluster managed by `kind`
type NodeRole string

const (
// ControlPlaneRole identifies a node that hosts a Kubernetes control-plane
// NB. in single node clusters, control-plane nodes act also as a worker nodes
// ControlPlaneRole identifies a node that hosts a Kubernetes control-plane.
// NOTE: in single node clusters, control-plane nodes act also as a worker nodes
BenTheElder marked this conversation as resolved.
Show resolved Hide resolved
ControlPlaneRole NodeRole = "control-plane"
// WorkerRole identifies a node that hosts a Kubernetes worker
WorkerRole NodeRole = "worker"
// ExternalEtcdRole identifies a node that hosts an external-etcd instance.
// WARNING: this node type is not yet implemented!
// Please note that `kind` nodes hosting external etcd are not kubernetes nodes
ExternalEtcdRole NodeRole = "external-etcd"
// ExternalLoadBalancerRole identifies a node that hosts an external load balancer for API server
// in HA configurations.
// WARNING: this node type is not yet implemented!
// Please note that `kind` nodes hosting external load balancer are not kubernetes nodes
ExternalLoadBalancerRole NodeRole = "external-load-balancer"
)
70 changes: 0 additions & 70 deletions pkg/cluster/config/v1alpha1/conversion.go

This file was deleted.

81 changes: 0 additions & 81 deletions pkg/cluster/config/v1alpha1/types.go

This file was deleted.

Loading