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

Improve the new KubeOneCluster API and add missing fields #379

Merged
merged 3 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 13 additions & 9 deletions pkg/apis/kubeone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package kubeone

import (
"encoding/json"

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

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -27,6 +28,8 @@ import (
type KubeOneCluster struct {
metav1.TypeMeta `json:",inline"`

// Name is the name of the cluster
Name string
// Hosts describes the control plane nodes and how to access them
Hosts []HostConfig `json:"hosts,omitempty"`
// APIEndpoints are pairs of address and port used to communicate with the Kubernetes API
Expand All @@ -45,6 +48,8 @@ type KubeOneCluster struct {
MachineController *MachineControllerConfig `json:"machineController,omitempty"`
// Features enables and configures additional cluster features
Features Features `json:"features,omitempty"`
// Credentials used for machine-controller and external CCM
Credentials map[string]string `json:"credentials,omitempty"`
}

// HostConfig describes a single control plane node.
Expand All @@ -69,7 +74,7 @@ type APIEndpoint struct {
Host string `json:"host"`

// Port is the port used to reach to the API
Port string `json:"port"`
Port int `json:"port"`
}

// CloudProviderName represents the name of a provider
Expand Down Expand Up @@ -123,20 +128,19 @@ type WorkerConfig struct {

// ProviderSpec describes a worker node
type ProviderSpec struct {
CloudProviderSpec *runtime.RawExtension `json:"cloudProviderSpec"`
Labels map[string]string `json:"labels"`
SSHPublicKeys []string `json:"sshPublicKeys"`
OperatingSystem string `json:"operatingSystem"`
OperatingSystemSpec *runtime.RawExtension `json:"operatingSystemSpec"`
CloudProviderSpec json.RawMessage `json:"cloudProviderSpec"`
Labels map[string]string `json:"labels"`
SSHPublicKeys []string `json:"sshPublicKeys"`
OperatingSystem string `json:"operatingSystem"`
OperatingSystemSpec json.RawMessage `json:"operatingSystemSpec"`
}

// MachineControllerConfig configures kubermatic machine-controller deployment
type MachineControllerConfig struct {
Deploy bool `json:"deploy"`
// Provider is provider to be used for machine-controller
// Defaults and must be same as chosen cloud provider, unless cloud provider is set to None
Provider CloudProviderName `json:"provider"`
Credentials map[string]string `json:"credentials"`
Provider CloudProviderName `json:"provider"`
}

// Features controls what features will be enabled on the cluster
Expand Down
115 changes: 0 additions & 115 deletions pkg/apis/kubeone/v1alpha1/credentials.go

This file was deleted.

38 changes: 28 additions & 10 deletions pkg/apis/kubeone/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ func SetDefaults_KubeOneCluster(obj *KubeOneCluster) {
SetDefaults_APIEndpoints(obj)
SetDefaults_ClusterNetwork(obj)
SetDefaults_MachineController(obj)
SetDefaults_Features(obj)
}

func SetDefaults_Hosts(obj *KubeOneCluster) {
// No hosts, so skip defaulting
if len(obj.Hosts) == 0 {
return
}

// Set first host to be the leader
obj.Hosts[0].IsLeader = true

Expand All @@ -54,13 +60,33 @@ func SetDefaults_Hosts(obj *KubeOneCluster) {
}

func SetDefaults_APIEndpoints(obj *KubeOneCluster) {
// If no API endpoint is provided, assume the public address is an endpoint
if len(obj.APIEndpoints) == 0 {
if len(obj.Hosts) == 0 {
// No hosts, so can't default to the first one
return
}
obj.APIEndpoints = []APIEndpoint{
{
Host: obj.Hosts[0].PublicAddress,
Port: 6443,
},
}
} else {
// There's APIEndpoint provided, default host and port
for i := range obj.APIEndpoints {
if len(obj.APIEndpoints[i].Host) == 0 {
if len(obj.Hosts) > 0 {
// Can only default to the first host if it exists
obj.APIEndpoints[i].Host = obj.Hosts[0].PublicAddress
}
}
if obj.APIEndpoints[i].Port == 0 {
obj.APIEndpoints[i].Port = 6443
}
}
}

}

func SetDefaults_ClusterNetwork(obj *KubeOneCluster) {
Expand All @@ -77,17 +103,9 @@ func SetDefaults_MachineController(obj *KubeOneCluster) {
}
}

// If ProviderName is not None default to cloud provider and ensure user have not
// manually provided machine-controller provider different than cloud provider.
// If ProviderName is None, take user input or default to None.
if obj.CloudProvider.Name != CloudProviderNameNone {
if obj.MachineController.Provider == "" {
obj.MachineController.Provider = obj.CloudProvider.Name
}
if obj.MachineController.Provider == "" {
obj.MachineController.Provider = obj.CloudProvider.Name
}

// TODO(xmudrii): error
obj.MachineController.Credentials, _ = obj.MachineController.Provider.ProviderCredentials()
}

func SetDefaults_Features(obj *KubeOneCluster) {
Expand Down
22 changes: 13 additions & 9 deletions pkg/apis/kubeone/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package v1alpha1

import (
"encoding/json"

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

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -27,6 +28,8 @@ import (
type KubeOneCluster struct {
metav1.TypeMeta `json:",inline"`

// Name is the name of the cluster
Name string
// Hosts describes the control plane nodes and how to access them
Hosts []HostConfig `json:"hosts,omitempty"`
// APIEndpoints are pairs of address and port used to communicate with the Kubernetes API
Expand All @@ -45,6 +48,8 @@ type KubeOneCluster struct {
MachineController *MachineControllerConfig `json:"machineController,omitempty"`
// Features enables and configures additional cluster features
Features Features `json:"features,omitempty"`
// Credentials used for machine-controller and external CCM
Credentials map[string]string `json:"credentials,omitempty"`
}

// HostConfig describes a single control plane node.
Expand All @@ -69,7 +74,7 @@ type APIEndpoint struct {
Host string `json:"host"`

// Port is the port used to reach to the API
Port string `json:"port"`
Port int `json:"port"`
}

// CloudProviderName represents the name of a provider
Expand Down Expand Up @@ -123,20 +128,19 @@ type WorkerConfig struct {

// ProviderSpec describes a worker node
type ProviderSpec struct {
CloudProviderSpec *runtime.RawExtension `json:"cloudProviderSpec"`
Labels map[string]string `json:"labels"`
SSHPublicKeys []string `json:"sshPublicKeys"`
OperatingSystem string `json:"operatingSystem"`
OperatingSystemSpec *runtime.RawExtension `json:"operatingSystemSpec"`
CloudProviderSpec json.RawMessage `json:"cloudProviderSpec"`
Labels map[string]string `json:"labels"`
SSHPublicKeys []string `json:"sshPublicKeys"`
OperatingSystem string `json:"operatingSystem"`
OperatingSystemSpec json.RawMessage `json:"operatingSystemSpec"`
}

// MachineControllerConfig configures kubermatic machine-controller deployment
type MachineControllerConfig struct {
Deploy bool `json:"deploy"`
// Provider is provider to be used for machine-controller
// Defaults and must be same as chosen cloud provider, unless cloud provider is set to None
Provider CloudProviderName `json:"provider"`
Credentials map[string]string `json:"credentials"`
Provider CloudProviderName `json:"provider"`
}

// Features controls what features will be enabled on the cluster
Expand Down
15 changes: 9 additions & 6 deletions pkg/apis/kubeone/v1alpha1/zz_generated.conversion.go

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

Loading