-
Notifications
You must be signed in to change notification settings - Fork 169
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
base: master
Are you sure you want to change the base?
Conversation
Add PublicAPIServerAddress field to ServiceSpec for specifying custom API server hostnames. Implement PublicControlPlaneAddress method to return public address with fallback to assigned address. Integrate public address usage in kubeconfig generation for controller-manager and scheduler. Add comprehensive tests for the functionality.
- Regenerate CRDs to include the new PublicAPIServerAddress field in ServiceSpec. - Update API reference docs to document the new field.
✅ Deploy Preview for kamaji-documentation canceled.
|
prometherion
left a comment
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.
I'm a bit lost here: it seems the proposed public API Server address is not pushed into the kubeadm functions, such as:
kamaji/internal/resources/kubeadm_config.go
Line 106 in 99fb71e
| TenantControlPlaneEndpoint: r.getControlPlaneEndpoint(tenantControlPlane.Spec.ControlPlane.Ingress, address, port), |
and the following one for kubeconfig
kamaji/internal/resources/kubeconfig.go
Line 234 in 99fb71e
| config.InitConfiguration.ControlPlaneEndpoint = fmt.Sprintf("%s.%s.svc:%d", tenantControlPlane.Name, tenantControlPlane.Namespace, tenantControlPlane.Spec.NetworkProfile.Port) |
| 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 |
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.
| 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
| // 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 |
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.
| // 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.
| // Post-process the kubeconfig to use the public API server address for | ||
| // controller manager and scheduler components instead of localhost/IP address | ||
| if strings.Contains(r.KubeConfigFileName, "controller-manager") || strings.Contains(r.KubeConfigFileName, "scheduler") { | ||
| kubeconfig, kcErr = r.replaceServerURLWithPublicAddress(kubeconfig, tenantControlPlane) | ||
| if kcErr != nil { | ||
| logger.Error(kcErr, "cannot replace server URL in kubeconfig") | ||
| return kcErr | ||
| } | ||
| } |
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 I'm missing something, this is not required: Kamaji leverages the concept of using loopback to communicate with the API Server; otherwise, we would end up with extra network hops with potential egress traffic.
| func (r *KubeconfigResource) usePublicAPIServerAddress(config *kubeadm.Configuration, tenantControlPlane *kamajiv1alpha1.TenantControlPlane) error { | ||
| // Use the public API server endpoint configured in the TenantControlPlane | ||
| // instead of localhost for controller manager and scheduler kubeconfigs. | ||
| // This ensures that internal control plane components connect using the proper hostname | ||
| // which matches the certificate SANs, rather than failing with x509 certificate errors. | ||
|
|
||
| // Note: We don't modify the kubeadm configuration here because LocalAPIEndpoint.AdvertiseAddress | ||
| // must be an IP address according to kubeadm validation. Instead, we'll post-process | ||
| // the generated kubeconfig to replace the server URL with the hostname. |
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.
Same discussion as we said before: Scheduler and Controller Manager must rely on the loopback address.
Add Public API Server Address Support
Overview
This PR introduces support for specifying a custom public API server address for TenantControlPlane instances. This allows using DNS hostnames in cluster-info ConfigMaps and kubeconfigs instead of LoadBalancer IPs, enabling better certificate SAN matching and avoiding x509 certificate errors.
Key Changes
API Changes
PublicAPIServerAddressfield toServiceSpecin the TenantControlPlane APIImplementation
PublicControlPlaneAddress()method toTenantControlPlanestructcmp.Orfor default port (6443)Tests
PublicControlPlaneAddress()methodDocumentation
Usage Example
Benefits
Breaking Changes
None. The field is optional and defaults to existing behavior.
Related Issues