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
1 change: 1 addition & 0 deletions CHANGES/1380.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop hardcoding IPFamilies/IPFamilyPolicy on the api, content, database, and otel Services, letting Kubernetes default them from the cluster's own Service CIDR instead (matching pulp-web and the redis Service). Fixes Service creation failures on single-stack IPv6 clusters.
5 changes: 2 additions & 3 deletions config/samples/external_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ metadata:
app.kubernetes.io/component: cache
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
# Let Kubernetes default this from the cluster Service CIDR.
# Required for IPv6-only clusters.
ports:
- name: redis-6379
port: 6379
Expand Down
5 changes: 2 additions & 3 deletions controllers/repo_manager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,15 @@ func serviceAPIObject(pulp pulpv1.Pulp) *corev1.Service {
func serviceAPISpec(pulp pulpv1.Pulp) corev1.ServiceSpec {

serviceInternalTrafficPolicyCluster := corev1.ServiceInternalTrafficPolicyType("Cluster")
ipFamilyPolicyType := corev1.IPFamilyPolicyType("SingleStack")
serviceAffinity := corev1.ServiceAffinity("None")
servicePortProto := corev1.Protocol("TCP")
targetPort := intstr.IntOrString{IntVal: 24817}
serviceType := corev1.ServiceType("ClusterIP")

return corev1.ServiceSpec{
InternalTrafficPolicy: &serviceInternalTrafficPolicyCluster,
IPFamilies: []corev1.IPFamily{"IPv4"},
IPFamilyPolicy: &ipFamilyPolicyType,
// Let Kubernetes default this from the cluster Service CIDR.
// Required for IPv6-only clusters.
Ports: []corev1.ServicePort{{
Name: "api-24817",
Port: 24817,
Expand Down
5 changes: 2 additions & 3 deletions controllers/repo_manager/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,15 @@ func serviceContentObject(pulp pulpv1.Pulp) *corev1.Service {
func serviceContentSpec(pulp pulpv1.Pulp) corev1.ServiceSpec {

serviceInternalTrafficPolicyCluster := corev1.ServiceInternalTrafficPolicyType("Cluster")
ipFamilyPolicyType := corev1.IPFamilyPolicyType("SingleStack")
serviceAffinity := corev1.ServiceAffinity("None")
servicePortProto := corev1.Protocol("TCP")
targetPort := intstr.IntOrString{IntVal: 24816}
serviceType := corev1.ServiceType("ClusterIP")

return corev1.ServiceSpec{
InternalTrafficPolicy: &serviceInternalTrafficPolicyCluster,
IPFamilies: []corev1.IPFamily{"IPv4"},
IPFamilyPolicy: &ipFamilyPolicyType,
// Let Kubernetes default this from the cluster Service CIDR.
// Required for IPv6-only clusters.
Ports: []corev1.ServicePort{{
Name: "content-24816",
Port: 24816,
Expand Down
5 changes: 2 additions & 3 deletions controllers/repo_manager/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ func labelsForDatabasePods(m *pulpv1.Pulp) map[string]string {
// serviceForDatabase returns a service object for postgres pods
func serviceForDatabase(m *pulpv1.Pulp) *corev1.Service {
serviceInternalTrafficPolicyCluster := corev1.ServiceInternalTrafficPolicyType("Cluster")
ipFamilyPolicyType := corev1.IPFamilyPolicyType("SingleStack")
serviceAffinity := corev1.ServiceAffinity("None")
servicePortProto := corev1.Protocol("TCP")
targetPort := intstr.IntOrString{IntVal: 5432}
Expand All @@ -492,8 +491,8 @@ func serviceForDatabase(m *pulpv1.Pulp) *corev1.Service {
ClusterIP: "None",
ClusterIPs: []string{"None"},
InternalTrafficPolicy: &serviceInternalTrafficPolicyCluster,
IPFamilies: []corev1.IPFamily{"IPv4"},
IPFamilyPolicy: &ipFamilyPolicyType,
// Let Kubernetes default this from the cluster Service CIDR.
// Required for IPv6-only clusters.
Ports: []corev1.ServicePort{{
Port: 5432,
Protocol: servicePortProto,
Expand Down
52 changes: 52 additions & 0 deletions controllers/repo_manager/service_ipfamily_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package repo_manager

import (
"testing"

pulpv1 "github.com/pulp/pulp-operator/apis/repo-manager.pulpproject.org/v1"
)

// These Services used to hardcode IPFamilies: ["IPv4"] and IPFamilyPolicy:
// SingleStack, which the API server rejects on a single-stack IPv6 cluster
// (pulp/pulp-operator#1380). Leaving both fields unset lets Kubernetes
// default them from the cluster's own Service CIDR instead, the same way
// pulp-web and the redis Service already do.
//
// This can only be verified at the unit level, not via the Ginkgo/envtest
// suite in controller_test.go: envtest's own control plane only has IPv4
// configured, so a live Service fetched after creation resolves to the same
// ["IPv4"]/SingleStack value whether the operator hardcodes it or omits it
// and lets the cluster decide.

func TestServiceAPISpec_DoesNotHardcodeIPFamily(t *testing.T) {
spec := serviceAPISpec(pulpv1.Pulp{})

if spec.IPFamilies != nil {
t.Errorf("serviceAPISpec().IPFamilies = %v, want nil", spec.IPFamilies)
}
if spec.IPFamilyPolicy != nil {
t.Errorf("serviceAPISpec().IPFamilyPolicy = %v, want nil", *spec.IPFamilyPolicy)
}
}

func TestServiceContentSpec_DoesNotHardcodeIPFamily(t *testing.T) {
spec := serviceContentSpec(pulpv1.Pulp{})

if spec.IPFamilies != nil {
t.Errorf("serviceContentSpec().IPFamilies = %v, want nil", spec.IPFamilies)
}
if spec.IPFamilyPolicy != nil {
t.Errorf("serviceContentSpec().IPFamilyPolicy = %v, want nil", *spec.IPFamilyPolicy)
}
}

func TestServiceForDatabase_DoesNotHardcodeIPFamily(t *testing.T) {
svc := serviceForDatabase(&pulpv1.Pulp{})

if svc.Spec.IPFamilies != nil {
t.Errorf("serviceForDatabase().Spec.IPFamilies = %v, want nil", svc.Spec.IPFamilies)
}
if svc.Spec.IPFamilyPolicy != nil {
t.Errorf("serviceForDatabase().Spec.IPFamilyPolicy = %v, want nil", *svc.Spec.IPFamilyPolicy)
}
}
5 changes: 2 additions & 3 deletions controllers/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ service:
// serviceOtel defines a service to expose otel metrics
func ServiceOtel(resources FunctionResources) client.Object {
serviceInternalTrafficPolicyCluster := corev1.ServiceInternalTrafficPolicyType("Cluster")
ipFamilyPolicyType := corev1.IPFamilyPolicyType("SingleStack")
serviceAffinity := corev1.ServiceAffinity("None")
servicePortProto := corev1.Protocol("TCP")
targetPort := intstr.IntOrString{IntVal: settings.OtelContainerPort}
Expand All @@ -197,8 +196,8 @@ func ServiceOtel(resources FunctionResources) client.Object {
},
Spec: corev1.ServiceSpec{
InternalTrafficPolicy: &serviceInternalTrafficPolicyCluster,
IPFamilies: []corev1.IPFamily{"IPv4"},
IPFamilyPolicy: &ipFamilyPolicyType,
// Let Kubernetes default this from the cluster Service CIDR.
// Required for IPv6-only clusters.
Ports: []corev1.ServicePort{{
Name: "otel-" + strconv.Itoa(settings.OtelContainerPort),
Port: settings.OtelContainerPort,
Expand Down
41 changes: 41 additions & 0 deletions controllers/telemetry_ipfamily_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package controllers

import (
"testing"

pulpv1 "github.com/pulp/pulp-operator/apis/repo-manager.pulpproject.org/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
)

// ServiceOtel used to hardcode IPFamilies: ["IPv4"] and IPFamilyPolicy:
// SingleStack, which the API server rejects on a single-stack IPv6 cluster
// (pulp/pulp-operator#1380). Leaving both fields unset lets Kubernetes
// default them from the cluster's own Service CIDR instead, the same way
// pulp-web and the redis Service already do.
//
// This can only be verified at the unit level, not via an envtest-based
// suite: envtest's own control plane only has IPv4 configured, so a live
// Service fetched after creation resolves to the same ["IPv4"]/SingleStack
// value whether the operator hardcodes it or omits it and lets the cluster
// decide.
func TestServiceOtel_DoesNotHardcodeIPFamily(t *testing.T) {
scheme := runtime.NewScheme()
_ = clientgoscheme.AddToScheme(scheme)
_ = pulpv1.AddToScheme(scheme)

pulp := &pulpv1.Pulp{ObjectMeta: metav1.ObjectMeta{Name: "pulp", Namespace: "default"}}
resources := FunctionResources{Pulp: pulp, Scheme: scheme}

obj := ServiceOtel(resources)
svc := obj.(*corev1.Service)

if svc.Spec.IPFamilies != nil {
t.Errorf("ServiceOtel().Spec.IPFamilies = %v, want nil", svc.Spec.IPFamilies)
}
if svc.Spec.IPFamilyPolicy != nil {
t.Errorf("ServiceOtel().Spec.IPFamilyPolicy = %v, want nil", *svc.Spec.IPFamilyPolicy)
}
}
Loading