Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ computePlane:
operator: Exists
interval: 30s
path: /metrics
port: metrics
port: worker-metrics
labels: {}
2 changes: 1 addition & 1 deletion deploy/stacks/observability/environments/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ defaultMonitors:
operator: Exists
interval: 30s
path: /metrics
port: metrics
port: worker-metrics
labels: {}
9 changes: 9 additions & 0 deletions deploy/stacks/observability/tests/profile-defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ profile_release_json() {
cat "$output_file"
}

# profile_releases_csv returns the sorted release names enabled for an observability profile.
profile_releases_csv() {
local profile="$1"
shift
Expand All @@ -59,6 +60,7 @@ profile_releases_csv() {
paste -sd, -
}

# render_monitors renders default monitor manifests for an observability profile.
render_monitors() {
local profile="$1"
local output_name="$2"
Expand All @@ -74,6 +76,7 @@ render_monitors() {
template --output-dir "$output_dir" >/dev/null
}

# monitor_targets_csv returns the sorted monitor kinds and names rendered in an output directory.
monitor_targets_csv() {
local output_dir="$1"
local file
Expand Down Expand Up @@ -353,6 +356,12 @@ assert_yaml_value "$worker_monitor_manifest" \
assert_yaml_value "$worker_monitor_manifest" \
'.spec.selector.matchExpressions[0].operator' Exists \
'worker pod label expression operator'
assert_yaml_value "$worker_monitor_manifest" \
'.spec.podMetricsEndpoints[0].port' worker-metrics \
'worker metrics port'
assert_yaml_value "$work_dir/compute-monitor-values.yaml" \
'.computePlane.worker.port' worker-metrics \
'compute worker metrics Helmfile value'

# The application chart owns its Service labels. Compare them with the shared
# ServiceMonitor selector so an application label change cannot silently break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec:
protocol: TCP
- port: 8888
protocol: TCP
- port: worker-metrics
protocol: TCP
- port: 10103
protocol: TCP
- port: 18888
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -2479,6 +2480,7 @@ func TestGetInternalPersistentStorageConfig(t *testing.T) {
}
}

// TestGetNetworkPoliciesDataEmptyDDCSIPList verifies generated network policies without DDCS CIDRs.
func TestGetNetworkPoliciesDataEmptyDDCSIPList(t *testing.T) {
expNPNames := []string{
EgressNetworkPolicyNameKey,
Expand All @@ -2501,7 +2503,15 @@ func TestGetNetworkPoliciesDataEmptyDDCSIPList(t *testing.T) {
got, err := bc.getNetworkPoliciesData(newTestContext(), nb)
require.NoError(t, err)
assert.Len(t, got, len(expNPNames))
assertNetworkPolicyAllowsTCPPort(t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, 8888)
assertNetworkPolicyAllowsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromInt32(8888),
)
assertNetworkPolicyAllowsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromString("worker-metrics"),
)
assertNetworkPolicyOmitsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromInt32(9089),
)
b := &bytes.Buffer{}
require.NoError(t, err)
for _, k := range expNPNames {
Expand All @@ -2511,6 +2521,7 @@ func TestGetNetworkPoliciesDataEmptyDDCSIPList(t *testing.T) {
assert.Equal(t, stripSPDXHeaders(readTestdataFile(t, filepath.Join("testdata", "netpols.yaml"))), stripSPDXHeaders(b.String()))
}

// TestGetNetworkPoliciesDataWithDDCSIPList verifies generated network policies with DDCS CIDRs.
func TestGetNetworkPoliciesDataWithDDCSIPList(t *testing.T) {
expNPNames := []string{
EgressNetworkPolicyNameKey,
Expand All @@ -2534,7 +2545,15 @@ func TestGetNetworkPoliciesDataWithDDCSIPList(t *testing.T) {
got, err := bc.getNetworkPoliciesData(newTestContext(), nb)
require.NoError(t, err)
assert.Len(t, got, len(expNPNames))
assertNetworkPolicyAllowsTCPPort(t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, 8888)
assertNetworkPolicyAllowsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromInt32(8888),
)
assertNetworkPolicyAllowsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromString("worker-metrics"),
)
assertNetworkPolicyOmitsTCPPort(
t, got[IngressNetworkPolicyNameKey], IngressNetworkPolicyNameKey, intstr.FromInt32(9089),
)
b := &bytes.Buffer{}
require.NoError(t, err)
for _, k := range expNPNames {
Expand All @@ -2544,7 +2563,8 @@ func TestGetNetworkPoliciesDataWithDDCSIPList(t *testing.T) {
assert.Equal(t, stripSPDXHeaders(readTestdataFile(t, filepath.Join("testdata", "netpols_with_ddcs.yaml"))), stripSPDXHeaders(b.String()))
}

func assertNetworkPolicyAllowsTCPPort(t *testing.T, policyYAML, policyName string, port int32) {
// assertNetworkPolicyAllowsTCPPort verifies a policy allows a numeric or named TCP destination port.
func assertNetworkPolicyAllowsTCPPort(t *testing.T, policyYAML, policyName string, port intstr.IntOrString) {
t.Helper()

var policy netv1.NetworkPolicy
Expand All @@ -2556,13 +2576,34 @@ func assertNetworkPolicyAllowsTCPPort(t *testing.T, policyYAML, policyName strin
if networkPolicyPort.Port == nil || networkPolicyPort.Protocol == nil {
continue
}
if networkPolicyPort.Port.IntVal == port && *networkPolicyPort.Protocol == corev1.ProtocolTCP {
if *networkPolicyPort.Port == port && *networkPolicyPort.Protocol == corev1.ProtocolTCP {
return
}
}
}

assert.Failf(t, "missing TCP port", "%s should allow TCP port %d", policyName, port)
assert.Failf(t, "missing TCP port", "%s should allow TCP port %q", policyName, port.String())
}

// assertNetworkPolicyOmitsTCPPort verifies a policy does not explicitly declare a numeric or named TCP port.
func assertNetworkPolicyOmitsTCPPort(t *testing.T, policyYAML, policyName string, port intstr.IntOrString) {
t.Helper()

var policy netv1.NetworkPolicy
require.NoError(t, yaml.Unmarshal([]byte(policyYAML), &policy))
require.Equal(t, policyName, policy.Name)

for _, ingressRule := range policy.Spec.Ingress {
for _, networkPolicyPort := range ingressRule.Ports {
if networkPolicyPort.Port == nil || networkPolicyPort.Protocol == nil {
continue
}
assert.Falsef(t,
*networkPolicyPort.Port == port && *networkPolicyPort.Protocol == corev1.ProtocolTCP,
"%s should not explicitly declare TCP port %q", policyName, port.String(),
)
}
}
}

func TestGetEffectiveK8sNetworkCIDRs(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ spec:
protocol: TCP
- port: 8888
protocol: TCP
- port: worker-metrics
protocol: TCP
- port: 10103
protocol: TCP
- port: 18888
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ spec:
protocol: TCP
- port: 8888
protocol: TCP
- port: worker-metrics
protocol: TCP
- port: 10103
protocol: TCP
- port: 18888
Expand Down

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

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

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

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

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

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

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

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

Loading
Loading