From 98db58d425360192597a5a8248f9a2b868cb2edb Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Mon, 29 Jun 2026 11:07:09 +0200 Subject: [PATCH 1/2] Let the K8S cluster decide on ipFamily usage [noissue] --- config/samples/external_cache.yaml | 5 ++--- controllers/repo_manager/api.go | 5 ++--- controllers/repo_manager/content.go | 5 ++--- controllers/repo_manager/database.go | 5 ++--- controllers/telemetry.go | 5 ++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/config/samples/external_cache.yaml b/config/samples/external_cache.yaml index 7677b13df..917479ef8 100644 --- a/config/samples/external_cache.yaml +++ b/config/samples/external_cache.yaml @@ -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 diff --git a/controllers/repo_manager/api.go b/controllers/repo_manager/api.go index cc3ff7ede..dd99b7279 100644 --- a/controllers/repo_manager/api.go +++ b/controllers/repo_manager/api.go @@ -144,7 +144,6 @@ 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} @@ -152,8 +151,8 @@ func serviceAPISpec(pulp pulpv1.Pulp) corev1.ServiceSpec { 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, diff --git a/controllers/repo_manager/content.go b/controllers/repo_manager/content.go index 342becd43..ecf468a1c 100644 --- a/controllers/repo_manager/content.go +++ b/controllers/repo_manager/content.go @@ -115,7 +115,6 @@ 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} @@ -123,8 +122,8 @@ func serviceContentSpec(pulp pulpv1.Pulp) corev1.ServiceSpec { 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, diff --git a/controllers/repo_manager/database.go b/controllers/repo_manager/database.go index 60e967cdd..b9250860e 100644 --- a/controllers/repo_manager/database.go +++ b/controllers/repo_manager/database.go @@ -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} @@ -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, diff --git a/controllers/telemetry.go b/controllers/telemetry.go index d9f4b166d..776e923e1 100644 --- a/controllers/telemetry.go +++ b/controllers/telemetry.go @@ -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} @@ -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, From 2a118d1bfb275b53ba20498ffe009f4f640e00e9 Mon Sep 17 00:00:00 2001 From: "Joseph S. Tate" Date: Thu, 5 Nov 2026 08:12:29 -0800 Subject: [PATCH 2/2] Add test coverage and a changelog fragment for pulp/pulp-operator#1651 #1651 (by @macwinnie) dropped the hardcoded IPFamilies: ["IPv4"] and IPFamilyPolicy: SingleStack from the api, content, database, and otel Services, letting Kubernetes default them from the cluster's own Service CIDR instead, the same way pulp-web and the redis Service already do. That fixes #1380 (Services fail to create on a single-stack IPv6 cluster) with no new CRD field at all, but the original PR had no tests and went stale without maintainer review. Add unit tests confirming each of the four Service builders leaves IPFamilies/IPFamilyPolicy unset. These can't be verified through the existing Ginkgo/envtest 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. This is one of two possible approaches to #1380. A companion branch instead adds explicit spec.ip_family_policy/spec.ip_families CR fields for users who want deliberate control rather than just inheriting whatever the cluster defaults to. closes #1380 Assisted By: Hermes Agent (claude-sonnet-5-5) --- CHANGES/1380.bugfix | 1 + .../repo_manager/service_ipfamily_test.go | 52 +++++++++++++++++++ controllers/telemetry_ipfamily_test.go | 41 +++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 CHANGES/1380.bugfix create mode 100644 controllers/repo_manager/service_ipfamily_test.go create mode 100644 controllers/telemetry_ipfamily_test.go diff --git a/CHANGES/1380.bugfix b/CHANGES/1380.bugfix new file mode 100644 index 000000000..b4fffc246 --- /dev/null +++ b/CHANGES/1380.bugfix @@ -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. diff --git a/controllers/repo_manager/service_ipfamily_test.go b/controllers/repo_manager/service_ipfamily_test.go new file mode 100644 index 000000000..8daba0d8a --- /dev/null +++ b/controllers/repo_manager/service_ipfamily_test.go @@ -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) + } +} diff --git a/controllers/telemetry_ipfamily_test.go b/controllers/telemetry_ipfamily_test.go new file mode 100644 index 000000000..9d7545446 --- /dev/null +++ b/controllers/telemetry_ipfamily_test.go @@ -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) + } +}