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

Refactor code for apiserver alternative names #1603

Merged
merged 6 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions docs/api_reference/v1beta1.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "v1beta1 API Reference"
date = 2021-10-28T12:33:26+05:00
date = 2021-10-29T14:08:40+05:00
weight = 11
+++
## v1beta1
Expand Down Expand Up @@ -67,6 +67,7 @@ APIEndpoint is the endpoint used to communicate with the Kubernetes API
| ----- | ----------- | ------ | -------- |
| host | Host is the hostname or IP on which API is running. | string | true |
| port | Port is the port used to reach to the API. Default value is 6443. | int | false |
| alternativeNames | AlternativeNames is a list of Subject Alternative Names for the API Server signing cert. | []string | false |

[Back to Group](#v1beta1)

Expand Down Expand Up @@ -414,7 +415,6 @@ KubeOneCluster is KubeOne Cluster API Schema
| ----- | ----------- | ------ | -------- |
| name | Name is the name of the cluster. | string | true |
| controlPlane | ControlPlane describes the control plane nodes and how to access them. | [ControlPlaneConfig](#controlplaneconfig) | true |
| alternativeNames | AlternativeNames is a list of Subject Alternative Names for the API Server signing cert. | []string | false |
| apiEndpoint | APIEndpoint are pairs of address and port used to communicate with the Kubernetes API. | [APIEndpoint](#apiendpoint) | true |
| cloudProvider | CloudProvider configures the cloud provider specific features. | [CloudProviderSpec](#cloudproviderspec) | true |
| versions | Versions defines which Kubernetes version will be installed. | [VersionConfig](#versionconfig) | true |
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/aws/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = aws_elb.control_plane.dns_name
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/azure/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = azurerm_public_ip.lbip.ip_address
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/digitalocean/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = digitalocean_loadbalancer.control_plane.ip
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/digitalocean/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/gce/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = google_compute_address.lb_ip.address
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/gce/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/hetzner/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = hcloud_load_balancer.load_balancer.ipv4
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/hetzner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/openstack/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = openstack_networking_floatingip_v2.lb.address
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/openstack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/packet/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = packet_device.lb.access_public_ipv4
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/packet/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/vsphere/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "kubeone_api" {

value = {
endpoint = var.api_vip != "" ? var.api_vip : vsphere_virtual_machine.control_plane[0].default_ip_address
additional_names = var.additional_names
apiserver_alternative_names = var.apiserver_alternative_names
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform/vsphere/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "cluster_name" {
type = string
}

variable "additional_names" {
variable "apiserver_alternative_names" {
description = "subject alternative names for the API Server signing cert."
default = []
type = list(string)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kubeone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type KubeOneCluster struct {
Name string `json:"name"`
// ControlPlane describes the control plane nodes and how to access them.
ControlPlane ControlPlaneConfig `json:"controlPlane"`
// AlternativeNames is a list of Subject Alternative Names for the API Server signing cert.
AlternativeNames []string `json:"alternativeNames,omitempty"`
// APIEndpoint are pairs of address and port used to communicate with the Kubernetes API.
APIEndpoint APIEndpoint `json:"apiEndpoint"`
// CloudProvider configures the cloud provider specific features.
Expand Down Expand Up @@ -154,6 +152,8 @@ type APIEndpoint struct {
// Port is the port used to reach to the API.
// Default value is 6443.
Port int `json:"port,omitempty"`
// AlternativeNames is a list of Subject Alternative Names for the API Server signing cert.
AlternativeNames []string `json:"alternativeNames,omitempty"`
}

// CloudProviderSpec describes the cloud provider that is running the machines.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kubeone/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,7 @@ func Convert_kubeone_Features_To_v1alpha1_Features(in *kubeoneapi.Features, out
func Convert_kubeone_Addons_To_v1alpha1_Addons(in *kubeoneapi.Addons, out *Addons, conv conversion.Scope) error {
return autoConvert_kubeone_Addons_To_v1alpha1_Addons(in, out, conv)
}

func Convert_kubeone_APIEndpoint_To_v1alpha1_APIEndpoint(in *kubeoneapi.APIEndpoint, out *APIEndpoint, s conversion.Scope) error {
return autoConvert_kubeone_APIEndpoint_To_v1alpha1_APIEndpoint(in, out, s)
}
17 changes: 6 additions & 11 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.

4 changes: 2 additions & 2 deletions pkg/apis/kubeone/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type KubeOneCluster struct {
Name string `json:"name"`
// ControlPlane describes the control plane nodes and how to access them.
ControlPlane ControlPlaneConfig `json:"controlPlane"`
// AlternativeNames is a list of Subject Alternative Names for the API Server signing cert.
AlternativeNames []string `json:"alternativeNames,omitempty"`
// APIEndpoint are pairs of address and port used to communicate with the Kubernetes API.
APIEndpoint APIEndpoint `json:"apiEndpoint"`
// CloudProvider configures the cloud provider specific features.
Expand Down Expand Up @@ -154,6 +152,8 @@ type APIEndpoint struct {
// Port is the port used to reach to the API.
// Default value is 6443.
Port int `json:"port,omitempty"`
// AlternativeNames is a list of Subject Alternative Names for the API Server signing cert.
AlternativeNames []string `json:"alternativeNames,omitempty"`
}

// CloudProviderSpec describes the cloud provider that is running the machines.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kubeone/v1beta1/zz_generated.conversion.go

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

12 changes: 6 additions & 6 deletions pkg/apis/kubeone/v1beta1/zz_generated.deepcopy.go

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

11 changes: 2 additions & 9 deletions pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func ValidateKubeOneCluster(c kubeone.KubeOneCluster) field.ErrorList {
}
allErrs = append(allErrs, ValidateControlPlaneConfig(c.ControlPlane, field.NewPath("controlPlane"))...)
allErrs = append(allErrs, ValidateAPIEndpoint(c.APIEndpoint, field.NewPath("apiEndpoint"))...)
allErrs = append(allErrs, ValidateAlternativeNames(c.AlternativeNames, field.NewPath("alternativeNames"))...)
allErrs = append(allErrs, ValidateCloudProviderSpec(c.CloudProvider, field.NewPath("provider"))...)
allErrs = append(allErrs, ValidateVersionConfig(c.Versions, field.NewPath("versions"))...)
allErrs = append(allErrs, ValidateCloudProviderSupportsKubernetes(c, field.NewPath(""))...)
Expand Down Expand Up @@ -90,22 +89,16 @@ func ValidateAPIEndpoint(a kubeone.APIEndpoint, fldPath *field.Path) field.Error
allErrs = append(allErrs, field.Invalid(fldPath.Child("port"), a.Port, "apiEndpoint.Port must be lower than 65535"))
}

return allErrs
}

// ValidateAlternativeNames validates provided AlternativeNames
func ValidateAlternativeNames(altNames []string, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

visited := make(map[string]bool)
for _, altName := range altNames {
for _, altName := range a.AlternativeNames {
if visited[altName] {
allErrs = append(allErrs, field.Invalid(fldPath, altName, "duplicates are not allowed in alternative names"))
break
} else {
visited[altName] = true
}
}

return allErrs
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/kubeone/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/templates/kubeadm/v1beta2/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewConfig(s *state.State, host kubeoneapi.HostConfig) ([]runtime.Object, er
},
}

certSANS := certificate.GetCertificateSANs(cluster.APIEndpoint.Host, cluster.AlternativeNames)
certSANS := certificate.GetCertificateSANs(cluster.APIEndpoint.Host, cluster.APIEndpoint.AlternativeNames)

clusterConfig := &kubeadmv1beta2.ClusterConfiguration{
TypeMeta: metav1.TypeMeta{
Expand Down
2 changes: 1 addition & 1 deletion pkg/templates/kubeadm/v1beta3/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewConfig(s *state.State, host kubeoneapi.HostConfig) ([]runtime.Object, er
},
}

certSANS := certificate.GetCertificateSANs(cluster.APIEndpoint.Host, cluster.AlternativeNames)
certSANS := certificate.GetCertificateSANs(cluster.APIEndpoint.Host, cluster.APIEndpoint.AlternativeNames)
clusterConfig := &kubeadmv1beta3.ClusterConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "kubeadm.k8s.io/v1beta3",
Expand Down
Loading