Skip to content
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

Enabling ipFamilies and ipFamilyPolicy #3087

Merged
merged 15 commits into from
Jul 23, 2024
16 changes: 16 additions & 0 deletions .chloggen/add-ip-families.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: 'collector'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Enabling ipFamilies and ipFamilyPolicy to be configured via OpenTelemetryCollector"

# One or more tracking issues related to the change
issues: [2958]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
6 changes: 6 additions & 0 deletions apis/v1alpha1/opampbridge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ type OpAMPBridgeSpec struct {
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// PodDNSConfig defines the DNS parameters of a pod in addition to those generated from DNSPolicy.
PodDNSConfig v1.PodDNSConfig `json:"podDnsConfig,omitempty"`
// IPFamily represents the IP Family (IPv4 or IPv6). This type is used
// to express the family of an IP expressed by a type (e.g. service.spec.ipFamilies).
// +optional
IpFamilies []v1.IPFamily `json:"ipFamilies,omitempty"`
// IPFamilyPolicy represents the dual-stack-ness requested or required by a Service
IpFamilyPolicy *v1.IPFamilyPolicy `json:"ipFamilyPolicy,omitempty"`
}

// OpAMPBridgeStatus defines the observed state of OpAMPBridge.
Expand Down
10 changes: 10 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions apis/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ type OpenTelemetryCommonFields struct {
AdditionalContainers []v1.Container `json:"additionalContainers,omitempty"`
// PodDNSConfig defines the DNS parameters of a pod in addition to those generated from DNSPolicy.
PodDNSConfig v1.PodDNSConfig `json:"podDnsConfig,omitempty"`
// IPFamily represents the IP Family (IPv4 or IPv6). This type is used
// to express the family of an IP expressed by a type (e.g. service.spec.ipFamilies).
// +kubebuilder:default:={IPv4}
// +optional
// +listType=set
IpFamilies []v1.IPFamily `json:"ipFamilies,omitempty"`
// IPFamilyPolicy represents the dual-stack-ness requested or required by a Service
// +kubebuilder:default:=SingleStack
// +optional
IpFamilyPolicy *v1.IPFamilyPolicy `json:"ipFamilyPolicy,omitempty"`
}

type StatefulSetCommonFields struct {
Expand Down
10 changes: 10 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bundle/manifests/opentelemetry.io_opampbridges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ spec:
type: string
imagePullPolicy:
type: string
ipFamilies:
items:
type: string
type: array
ipFamilyPolicy:
type: string
nodeSelector:
additionalProperties:
type: string
Expand Down
10 changes: 10 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6740,6 +6740,16 @@ spec:
- name
type: object
type: array
ipFamilies:
default:
- IPv4
items:
type: string
type: array
x-kubernetes-list-type: set
ipFamilyPolicy:
default: SingleStack
type: string
lifecycle:
properties:
postStart:
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/opentelemetry.io_opampbridges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ spec:
type: string
imagePullPolicy:
type: string
ipFamilies:
items:
type: string
type: array
ipFamilyPolicy:
type: string
nodeSelector:
additionalProperties:
type: string
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6726,6 +6726,16 @@ spec:
- name
type: object
type: array
ipFamilies:
default:
- IPv4
items:
type: string
type: array
x-kubernetes-list-type: set
ipFamilyPolicy:
default: SingleStack
type: string
lifecycle:
properties:
postStart:
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/opentelemetry.io_targetallocators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,16 @@ spec:
- name
type: object
type: array
ipFamilies:
default:
- IPv4
items:
type: string
type: array
x-kubernetes-list-type: set
ipFamilyPolicy:
default: SingleStack
type: string
lifecycle:
properties:
postStart:
Expand Down
34 changes: 34 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4183,6 +4183,21 @@ typically used to set access tokens or other authorization headers.<br/>
ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>ipFamilies</b></td>
<td>[]string</td>
<td>
IPFamily represents the IP Family (IPv4 or IPv6). This type is used
to express the family of an IP expressed by a type (e.g. service.spec.ipFamilies).<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>ipFamilyPolicy</b></td>
<td>string</td>
<td>
IPFamilyPolicy represents the dual-stack-ness requested or required by a Service<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>nodeSelector</b></td>
<td>map[string]string</td>
Expand Down Expand Up @@ -30936,6 +30951,25 @@ an initContainer will lead to a restart of the Pod. More info:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>ipFamilies</b></td>
<td>[]string</td>
<td>
IPFamily represents the IP Family (IPv4 or IPv6). This type is used
to express the family of an IP expressed by a type (e.g. service.spec.ipFamilies).<br/>
<br/>
<i>Default</i>: [IPv4]<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>ipFamilyPolicy</b></td>
<td>string</td>
<td>
IPFamilyPolicy represents the dual-stack-ness requested or required by a Service<br/>
<br/>
<i>Default</i>: SingleStack<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspeclifecycle-1">lifecycle</a></b></td>
<td>object</td>
Expand Down
4 changes: 4 additions & 0 deletions internal/manifests/collector/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func MonitoringService(params manifests.Params) (*corev1.Service, error) {
Name: "monitoring",
Port: metricsPort,
}},
IPFamilies: params.OtelCol.Spec.IpFamilies,
IPFamilyPolicy: params.OtelCol.Spec.IpFamilyPolicy,
},
}, nil
}
Expand Down Expand Up @@ -175,6 +177,8 @@ func Service(params manifests.Params) (*corev1.Service, error) {
Selector: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
ClusterIP: "",
Ports: ports,
IPFamilies: params.OtelCol.Spec.IpFamilies,
IPFamilyPolicy: params.OtelCol.Spec.IpFamilyPolicy,
},
}, nil
}
Expand Down
40 changes: 40 additions & 0 deletions internal/manifests/collector/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,43 @@ func serviceWithInternalTrafficPolicy(name string, ports []v1beta1.PortsSpec, in
},
}
}

func TestServiceWithIpFamily(t *testing.T) {
t.Run("should return IPFamilies for IPV4 and IPV6", func(t *testing.T) {
params := deploymentParams()
params.OtelCol.Spec.IpFamilies = []v1.IPFamily{
"IPv4",
"IPv6",
}
actual, err := Service(params)
assert.NoError(t, err)
assert.Equal(t, actual.Spec.IPFamilies, []v1.IPFamily{
"IPv4",
"IPv6",
})
})
t.Run("should return IPPolicy SingleStack", func(t *testing.T) {
params := deploymentParams()
baseIpFamily := v1.IPFamilyPolicySingleStack
params.OtelCol.Spec.IpFamilyPolicy = &baseIpFamily
actual, err := Service(params)
assert.NoError(t, err)
assert.Equal(t, actual.Spec.IPFamilyPolicy, params.OtelCol.Spec.IpFamilyPolicy)
})
t.Run("should return IPPolicy PreferDualStack", func(t *testing.T) {
params := deploymentParams()
baseIpFamily := v1.IPFamilyPolicyPreferDualStack
params.OtelCol.Spec.IpFamilyPolicy = &baseIpFamily
actual, err := Service(params)
assert.NoError(t, err)
assert.Equal(t, actual.Spec.IPFamilyPolicy, params.OtelCol.Spec.IpFamilyPolicy)
})
t.Run("should return IPPolicy RequireDualStack ", func(t *testing.T) {
params := deploymentParams()
baseIpFamily := v1.IPFamilyPolicyRequireDualStack
params.OtelCol.Spec.IpFamilyPolicy = &baseIpFamily
actual, err := Service(params)
assert.NoError(t, err)
assert.Equal(t, actual.Spec.IPFamilyPolicy, params.OtelCol.Spec.IpFamilyPolicy)
})
}
6 changes: 4 additions & 2 deletions internal/manifests/opampbridge/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func Service(params manifests.Params) *corev1.Service {
Labels: labels,
},
Spec: corev1.ServiceSpec{
Selector: selector,
Ports: ports,
Selector: selector,
Ports: ports,
IPFamilies: params.OpAMPBridge.Spec.IpFamilies,
IPFamilyPolicy: params.OpAMPBridge.Spec.IpFamilyPolicy,
},
}
}
2 changes: 2 additions & 0 deletions internal/manifests/targetallocator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func Service(params Params) *corev1.Service {
Port: 80,
TargetPort: intstr.FromString("http"),
}},
IPFamilies: params.TargetAllocator.Spec.IpFamilies,
IPFamilyPolicy: params.TargetAllocator.Spec.IpFamilyPolicy,
},
}
}
60 changes: 60 additions & 0 deletions tests/e2e/smoke-ip-families/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: simplest-ipfamily-collector
status:
readyReplicas: 1

---

apiVersion: v1
kind: Service
metadata:
name: simplest-ipfamily-collector-headless
spec:
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- appProtocol: grpc
name: jaeger-grpc
port: 14250
protocol: TCP
targetPort: 14250
- appProtocol: grpc
name: otlp-grpc
port: 4317
protocol: TCP
targetPort: 4317
- appProtocol: http
name: otlp-http
port: 4318
protocol: TCP
targetPort: 4318

---

apiVersion: v1
kind: Service
metadata:
name: simplest-ipfamily-collector
spec:
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- appProtocol: grpc
name: jaeger-grpc
port: 14250
protocol: TCP
targetPort: 14250
- appProtocol: grpc
name: otlp-grpc
port: 4317
protocol: TCP
targetPort: 4317
- appProtocol: http
name: otlp-http
port: 4318
protocol: TCP
targetPort: 4318
28 changes: 28 additions & 0 deletions tests/e2e/smoke-ip-families/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: simplest-ipfamily
spec:
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
config:
receivers:
jaeger:
protocols:
grpc:
otlp:
protocols:
grpc:
http:
processors:

exporters:
debug:

service:
pipelines:
traces:
receivers: [jaeger, otlp]
processors: []
exporters: [debug]
Loading
Loading