Skip to content

Commit

Permalink
feat: cluster domain customisation (#594)
Browse files Browse the repository at this point in the history
* feat(api): customising cluster domain option

Signed-off-by: Dario Tranchitella <[email protected]>

* feat(helm): customising cluster domain option

Signed-off-by: Dario Tranchitella <[email protected]>

* docs: customising cluster domain option

Signed-off-by: Dario Tranchitella <[email protected]>

---------

Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion authored Oct 6, 2024
1 parent a21f199 commit 7e08b9a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 28 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/tenantcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ type NetworkProfileSpec struct {
// Address where API server of will be exposed.
// In case of LoadBalancer Service, this can be empty in order to use the exposed IP provided by the cloud controller manager.
Address string `json:"address,omitempty"`
// The default domain name used for DNS resolution within the cluster.
//+kubebuilder:default="cluster.local"
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="changing the cluster domain is not supported"
//+kubebuilder:validation:Pattern=.*\..*
ClusterDomain string `json:"clusterDomain,omitempty"`
// AllowAddressAsExternalIP will include tenantControlPlane.Spec.NetworkProfile.Address in the section of
// ExternalIPs of the Kubernetes Service (only ClusterIP or NodePort)
AllowAddressAsExternalIP bool `json:"allowAddressAsExternalIP,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions charts/kamaji/crds/kamaji.clastix.io_tenantcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6550,6 +6550,14 @@ spec:
items:
type: string
type: array
clusterDomain:
default: cluster.local
description: The default domain name used for DNS resolution within the cluster.
pattern: .*\..*
type: string
x-kubernetes-validations:
- message: changing the cluster domain is not supported
rule: self == oldSelf
dnsServiceIPs:
default:
- 10.96.0.10
Expand Down
9 changes: 9 additions & 0 deletions docs/content/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13924,6 +13924,15 @@ ExternalIPs of the Kubernetes Service (only ClusterIP or NodePort)<br/>
Use this field to add additional hostnames when exposing the Tenant Control Plane with third solutions.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>clusterDomain</b></td>
<td>string</td>
<td>
The default domain name used for DNS resolution within the cluster.<br/>
<br/>
<i>Default</i>: cluster.local<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>dnsServiceIPs</b></td>
<td>[]string</td>
Expand Down
2 changes: 1 addition & 1 deletion internal/kubeadm/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func CreateKubeadmInitConfiguration(params Parameters) (*Configuration, error) {
},
}
conf.Networking = kubeadmapi.Networking{
DNSDomain: "cluster.local",
DNSDomain: params.TenantControlPlaneClusterDomain,
PodSubnet: params.TenantControlPlanePodCIDR,
ServiceSubnet: params.TenantControlPlaneServiceCIDR,
}
Expand Down
33 changes: 17 additions & 16 deletions internal/kubeadm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ func (c *Configuration) Checksum() string {
}

type Parameters struct {
TenantControlPlaneName string
TenantControlPlaneNamespace string
TenantControlPlaneEndpoint string
TenantControlPlaneAddress string
TenantControlPlaneCertSANs []string
TenantControlPlanePort int32
TenantControlPlanePodCIDR string
TenantControlPlaneServiceCIDR string
TenantDNSServiceIPs []string
TenantControlPlaneVersion string
TenantControlPlaneCGroupDriver string
ETCDs []string
CertificatesDir string
KubeconfigDir string
KubeProxyOptions *AddonOptions
CoreDNSOptions *AddonOptions
TenantControlPlaneName string
TenantControlPlaneNamespace string
TenantControlPlaneEndpoint string
TenantControlPlaneAddress string
TenantControlPlaneCertSANs []string
TenantControlPlanePort int32
TenantControlPlaneClusterDomain string
TenantControlPlanePodCIDR string
TenantControlPlaneServiceCIDR string
TenantDNSServiceIPs []string
TenantControlPlaneVersion string
TenantControlPlaneCGroupDriver string
ETCDs []string
CertificatesDir string
KubeconfigDir string
KubeProxyOptions *AddonOptions
CoreDNSOptions *AddonOptions
}

type AddonOptions struct {
Expand Down
23 changes: 12 additions & 11 deletions internal/resources/kubeadm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ func (r *KubeadmConfigResource) mutate(ctx context.Context, tenantControlPlane *
r.resource.SetLabels(utilities.KamajiLabels(tenantControlPlane.GetName(), r.GetName()))

params := kubeadm.Parameters{
TenantControlPlaneAddress: address,
TenantControlPlanePort: port,
TenantControlPlaneName: tenantControlPlane.GetName(),
TenantControlPlaneNamespace: tenantControlPlane.GetNamespace(),
TenantControlPlaneEndpoint: r.getControlPlaneEndpoint(tenantControlPlane.Spec.ControlPlane.Ingress, address, port),
TenantControlPlaneCertSANs: tenantControlPlane.Spec.NetworkProfile.CertSANs,
TenantControlPlanePodCIDR: tenantControlPlane.Spec.NetworkProfile.PodCIDR,
TenantControlPlaneServiceCIDR: tenantControlPlane.Spec.NetworkProfile.ServiceCIDR,
TenantControlPlaneVersion: tenantControlPlane.Spec.Kubernetes.Version,
ETCDs: r.ETCDs,
CertificatesDir: r.TmpDirectory,
TenantControlPlaneAddress: address,
TenantControlPlanePort: port,
TenantControlPlaneName: tenantControlPlane.GetName(),
TenantControlPlaneNamespace: tenantControlPlane.GetNamespace(),
TenantControlPlaneEndpoint: r.getControlPlaneEndpoint(tenantControlPlane.Spec.ControlPlane.Ingress, address, port),
TenantControlPlaneCertSANs: tenantControlPlane.Spec.NetworkProfile.CertSANs,
TenantControlPlaneClusterDomain: tenantControlPlane.Spec.NetworkProfile.ClusterDomain,
TenantControlPlanePodCIDR: tenantControlPlane.Spec.NetworkProfile.PodCIDR,
TenantControlPlaneServiceCIDR: tenantControlPlane.Spec.NetworkProfile.ServiceCIDR,
TenantControlPlaneVersion: tenantControlPlane.Spec.Kubernetes.Version,
ETCDs: r.ETCDs,
CertificatesDir: r.TmpDirectory,
}

config, err := kubeadm.CreateKubeadmInitConfiguration(params)
Expand Down

0 comments on commit 7e08b9a

Please sign in to comment.