Skip to content
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ $(KIND): $(LOCALBIN)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) CGO_ENABLED=0 go install -ldflags="-s -w" sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.1
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) CGO_ENABLED=0 go install -ldflags="-s -w" sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) CGO_ENABLED=0 go install -ldflags="-s -w" sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) CGO_ENABLED=0 go install -ldflags="-s -w" sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.1

Unless it's required, we need to stick to 0.16.1


.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
Expand Down
27 changes: 27 additions & 0 deletions api/v1alpha1/tenantcontrolplane_public_address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2025 Clastix Labs
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import "cmp"

// PublicControlPlaneAddress returns the public address for the cluster-info ConfigMap.
// If PublicAPIServerAddress is specified, it returns that value; otherwise, it falls back
// to the assigned control plane address. This allows using DNS names in cluster-info
// instead of LoadBalancer IPs. The port is always taken from NetworkProfile.Port.
func (in *TenantControlPlane) PublicControlPlaneAddress() (string, int32, error) {
port := cmp.Or(in.Spec.NetworkProfile.Port, 6443)

// If PublicAPIServerAddress is specified, use it for cluster-info
if publicAddress := in.Spec.ControlPlane.Service.PublicAPIServerAddress; len(publicAddress) > 0 {
return publicAddress, port, nil
}

// Fall back to the assigned control plane address, but use configured port
assignedAddress, _, err := in.AssignedControlPlaneAddress()
if err != nil {
return "", 0, err
}

return assignedAddress, port, nil
Comment on lines +20 to +26
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Fall back to the assigned control plane address, but use configured port
assignedAddress, _, err := in.AssignedControlPlaneAddress()
if err != nil {
return "", 0, err
}
return assignedAddress, port, nil
// Fall back to the assigned control plane address
return in.AssignedControlPlaneAddress()

Unless I'm missing something, there's no need to replicate the same behavior of AssignedControlPlaneAddress.

}
127 changes: 127 additions & 0 deletions api/v1alpha1/tenantcontrolplane_public_address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright 2025 Clastix Labs
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("TenantControlPlane PublicControlPlaneAddress", func() {
var tcp *TenantControlPlane

BeforeEach(func() {
tcp = &TenantControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-tcp",
Namespace: "test-namespace",
},
Spec: TenantControlPlaneSpec{
NetworkProfile: NetworkProfileSpec{
Port: 6443,
},
ControlPlane: ControlPlane{
Service: ServiceSpec{
ServiceType: ServiceTypeLoadBalancer,
},
},
},
Status: TenantControlPlaneStatus{
ControlPlaneEndpoint: "192.168.1.100:6443",
},
}
})

Context("when PublicAPIServerAddress is not specified", func() {
It("should fall back to AssignedControlPlaneAddress", func() {
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("192.168.1.100"))
Expect(port).To(Equal(int32(6443)))
})

It("should use default port 6443 when NetworkProfile.Port is not set", func() {
tcp.Spec.NetworkProfile.Port = 0
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("192.168.1.100"))
Expect(port).To(Equal(int32(6443)))
})

It("should use custom port when NetworkProfile.Port is set", func() {
tcp.Spec.NetworkProfile.Port = 8443
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("192.168.1.100"))
Expect(port).To(Equal(int32(8443)))
})
})

Context("when PublicAPIServerAddress is specified", func() {
BeforeEach(func() {
tcp.Spec.ControlPlane.Service.PublicAPIServerAddress = "k8s-api.example.com"
})

It("should return the public address instead of assigned address", func() {
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("k8s-api.example.com"))
Expect(port).To(Equal(int32(6443)))
})

It("should use default port 6443 when NetworkProfile.Port is not set", func() {
tcp.Spec.NetworkProfile.Port = 0
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("k8s-api.example.com"))
Expect(port).To(Equal(int32(6443)))
})

It("should use custom port when NetworkProfile.Port is set", func() {
tcp.Spec.NetworkProfile.Port = 8443
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("k8s-api.example.com"))
Expect(port).To(Equal(int32(8443)))
})

It("should still work when ControlPlaneEndpoint is empty", func() {
tcp.Status.ControlPlaneEndpoint = ""
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("k8s-api.example.com"))
Expect(port).To(Equal(int32(6443)))
})
})

Context("when PublicAPIServerAddress is empty string", func() {
BeforeEach(func() {
tcp.Spec.ControlPlane.Service.PublicAPIServerAddress = ""
})

It("should fall back to AssignedControlPlaneAddress", func() {
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("192.168.1.100"))
Expect(port).To(Equal(int32(6443)))
})
})

Context("error handling", func() {
It("should return error when both PublicAPIServerAddress is empty and ControlPlaneEndpoint is not available", func() {
tcp.Status.ControlPlaneEndpoint = ""
_, _, err := tcp.PublicControlPlaneAddress()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("the Tenant Control Plane is not yet exposed"))
})

It("should return error when ControlPlaneEndpoint is malformed and PublicAPIServerAddress is empty", func() {
tcp.Status.ControlPlaneEndpoint = "invalid-endpoint"
_, _, err := tcp.PublicControlPlaneAddress()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("cannot split host port"))
})
})
})
5 changes: 5 additions & 0 deletions api/v1alpha1/tenantcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ type ServiceSpec struct {
AdditionalMetadata AdditionalMetadata `json:"additionalMetadata,omitempty"`
// ServiceType allows specifying how to expose the Tenant Control Plane.
ServiceType ServiceType `json:"serviceType"`
// PublicAPIServerAddress allows specifying a custom hostname for the API server.
// If set, this address will be used in cluster-info ConfigMaps and kubeconfigs
// instead of the LoadBalancer IP, enabling the use of DNS names that match certificate SANs.
// +optional
PublicAPIServerAddress string `json:"publicAPIServerAddress,omitempty"`
}

// AddonSpec defines the spec for every addon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6738,6 +6738,12 @@ versions:
type: string
type: object
type: object
publicAPIServerAddress:
description: |-
PublicAPIServerAddress allows specifying a custom hostname for the API server.
If set, this address will be used in cluster-info ConfigMaps and kubeconfigs
instead of the LoadBalancer IP, enabling the use of DNS names that match certificate SANs.
type: string
serviceType:
description: ServiceType allows specifying how to expose the Tenant Control Plane.
enum:
Expand Down
2 changes: 1 addition & 1 deletion charts/kamaji/crds/kamaji.clastix.io_datastores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: kamaji-system/kamaji-serving-cert
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.19.0
name: datastores.kamaji.clastix.io
spec:
group: kamaji.clastix.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: kamaji-system/kamaji-serving-cert
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.19.0
name: kubeconfiggenerators.kamaji.clastix.io
spec:
group: kamaji.clastix.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: kamaji-system/kamaji-serving-cert
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.19.0
name: tenantcontrolplanes.kamaji.clastix.io
spec:
group: kamaji.clastix.io
Expand Down Expand Up @@ -6746,6 +6746,12 @@ spec:
type: string
type: object
type: object
publicAPIServerAddress:
description: |-
PublicAPIServerAddress allows specifying a custom hostname for the API server.
If set, this address will be used in cluster-info ConfigMaps and kubeconfigs
instead of the LoadBalancer IP, enabling the use of DNS names that match certificate SANs.
type: string
serviceType:
description: ServiceType allows specifying how to expose the Tenant Control Plane.
enum:
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 @@ -28609,6 +28609,15 @@ Defining the options for the Tenant Control Plane Service resource.
AdditionalMetadata defines which additional metadata, such as labels and annotations, must be attached to the created resource.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>publicAPIServerAddress</b></td>
<td>string</td>
<td>
PublicAPIServerAddress allows specifying a custom hostname for the API server.
If set, this address will be used in cluster-info ConfigMaps and kubeconfigs
instead of the LoadBalancer IP, enabling the use of DNS names that match certificate SANs.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down
101 changes: 101 additions & 0 deletions e2e/tcp_public_address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2022 Clastix Labs
// SPDX-License-Identifier: Apache-2.0

package e2e

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
)

var _ = Describe("TenantControlPlane PublicAPIServerAddress", func() {
var tcp *kamajiv1alpha1.TenantControlPlane

BeforeEach(func() {
tcp = &kamajiv1alpha1.TenantControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "tcp-public-address-test",
Namespace: "default",
},
Spec: kamajiv1alpha1.TenantControlPlaneSpec{
ControlPlane: kamajiv1alpha1.ControlPlane{
Service: kamajiv1alpha1.ServiceSpec{
ServiceType: kamajiv1alpha1.ServiceTypeLoadBalancer,
},
},
Kubernetes: kamajiv1alpha1.KubernetesSpec{
Version: "v1.30.0",
},
NetworkProfile: kamajiv1alpha1.NetworkProfileSpec{
Port: 6443,
},
DataStore: "default",
},
}
})

Context("when PublicAPIServerAddress is not specified", func() {
It("should not set public address in spec", func() {
Expect(tcp.Spec.ControlPlane.Service.PublicAPIServerAddress).To(BeEmpty())
})
})

Context("when PublicAPIServerAddress is specified", func() {
BeforeEach(func() {
tcp.Spec.ControlPlane.Service.PublicAPIServerAddress = "k8s-api.example.com"
})

It("should set the public address", func() {
Expect(tcp.Spec.ControlPlane.Service.PublicAPIServerAddress).To(Equal("k8s-api.example.com"))
})

It("should create the TenantControlPlane successfully", func() {
Expect(k8sClient.Create(ctx, tcp)).To(Succeed())

// Check that the TCP is created
Eventually(func() error {
return k8sClient.Get(ctx, types.NamespacedName{Name: tcp.Name, Namespace: tcp.Namespace}, tcp)
}, 10, 1).Should(Succeed())

// Check that the public address is returned by PublicControlPlaneAddress
address, port, err := tcp.PublicControlPlaneAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal("k8s-api.example.com"))
Expect(port).To(Equal(int32(6443)))
})

It("should generate kubeconfigs with the public address for controller-manager and scheduler", func() {
tcp.Spec.ControlPlane.Service.PublicAPIServerAddress = "k8s-api.example.com"
Expect(k8sClient.Create(ctx, tcp)).To(Succeed())

// Wait for kubeconfig secrets to be created
Eventually(func() bool {
cmSecret := &corev1.Secret{}
err := k8sClient.Get(ctx, types.NamespacedName{
Name: tcp.Name + "-controller-manager-kubeconfig",
Namespace: tcp.Namespace,
}, cmSecret)
if err != nil {
return false
}

schedSecret := &corev1.Secret{}
err = k8sClient.Get(ctx, types.NamespacedName{
Name: tcp.Name + "-scheduler-kubeconfig",
Namespace: tcp.Namespace,
}, schedSecret)
return err == nil
}, 300, 5).Should(BeTrue())

// Note: Full validation of kubeconfig contents would require parsing YAML
// and checking the server URL, but this test ensures the feature is exercised
// during TCP creation.
})
})
})
Loading