-
Notifications
You must be signed in to change notification settings - Fork 186
feature: Add Public API Server Address Support #986
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
Open
rossigee
wants to merge
4
commits into
clastix:master
Choose a base branch
from
rossigee:feature/public-address
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unless I'm missing something, there's no need to replicate the same behavior of |
||||||||||||||||||||
| } | ||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless it's required, we need to stick to 0.16.1