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

[customcluster] fix configContent is nil bug #361

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions pkg/cluster-operator/customcluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,22 @@ type ConfigTemplateContent struct {
func GetConfigContent(c *clusterv1.Cluster, kcp *controlplanev1.KubeadmControlPlane, cc *v1alpha1.CustomCluster) *ConfigTemplateContent {
// Add kubespray init config here
configContent := &ConfigTemplateContent{
PodCIDR: c.Spec.ClusterNetwork.Pods.CIDRBlocks[0],
ServiceCIDR: c.Spec.ClusterNetwork.Services.CIDRBlocks[0],
KubeVersion: kcp.Spec.Version,
CNIType: cc.Spec.CNI.Type,
ControlPlaneAddress: cc.Spec.ControlPlaneConfig.Address,
ControlPlaneCertSANs: strings.Join(cc.Spec.ControlPlaneConfig.CertSANs, ","),
ClusterName: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.ClusterName,
DnsDomain: c.Spec.ClusterNetwork.ServiceDomain,
KubeImageRepo: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository,
FeatureGates: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.FeatureGates,
LoadBalancerDomainName: cc.Spec.ControlPlaneConfig.LoadBalancerDomainName,
PodCIDR: c.Spec.ClusterNetwork.Pods.CIDRBlocks[0],
ServiceCIDR: c.Spec.ClusterNetwork.Services.CIDRBlocks[0],
KubeVersion: kcp.Spec.Version,
CNIType: cc.Spec.CNI.Type,
ClusterName: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.ClusterName,
DnsDomain: c.Spec.ClusterNetwork.ServiceDomain,
KubeImageRepo: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository,
FeatureGates: kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.FeatureGates,
}

if cc.Spec.ControlPlaneConfig != nil {
configContent.ControlPlaneCertSANs = strings.Join(cc.Spec.ControlPlaneConfig.CertSANs, ",")
configContent.ControlPlaneAddress = cc.Spec.ControlPlaneConfig.Address
configContent.LoadBalancerDomainName = cc.Spec.ControlPlaneConfig.LoadBalancerDomainName
Copy link
Member

Choose a reason for hiding this comment

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

just one questiom: do we allow these fields to be empty?
ControlPlaneConfig.CertSANs
ControlPlaneConfig.Address
ControlPlaneConfig.LoadBalancerDomainName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, these fields could be left empty under certain circumstances. Here is the interpretation of each field being empty:

ControlPlaneConfig.CertSANs: If this field is empty, it indicates that the user has not specified any additional Subject Alternative Names for the Kubernetes API Server certificate. This is suitable for simple deployments where the API server is accessed from a single and unchanging address, typically the address of the first master node.

ControlPlaneConfig.Address: If this field is empty, Kubespray will default to using the IP address of the first master node listed in the configuration as the Control Plane (API Server) address. This is often the case for straightforward, non-HA deployments where there's no need for a load balancer to distribute traffic among multiple master nodes.

ControlPlaneConfig.LoadBalancerDomainName: If this field is empty, it means that the user has not specified a domain name for a load balancer. This is fine for deployments where a load balancer is not used, or where access to the API Server is only required via IP address.

In summary, if you are deploying in a simple environment, such as for testing or development purposes where a single master node without a load balancer or HA mode is sufficient, you can leave the ControlPlaneConfig fields empty. The system will apply default settings that allow for quick and easy setup of a on-premise Kubernetes cluster. However, for more complex or production environments, it's recommended to carefully consider and appropriately set these fields.

}

return configContent
}

Expand Down