Skip to content

Commit b76098e

Browse files
bussyjdOisinKyne
authored andcommitted
test(controller): guard resourceFor NetworkPolicy GVR mapping (rc16 regression)
main carries the fix (#628 / d16d167: NetworkPolicyGVR + the resourceFor case + the fake-client harness entry) but no test pinning it. Add TestResourceFor_NetworkPolicyUsesNetworkPolicyGVR, salvaged from the superseded #630, so a future refactor can't silently route the agent-isolation NetworkPolicy back to the ConfigMap default — a fake client tolerates the wrong GVR, which is how the rc16 regression hid.
1 parent 93527a4 commit b76098e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

internal/serviceoffercontroller/agent_netpol_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package serviceoffercontroller
22

33
import (
4+
"context"
45
"encoding/json"
56
"strings"
67
"testing"
78

89
"github.com/ObolNetwork/obol-stack/internal/monetizeapi"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
911
)
1012

1113
// TestBuildAgentNetworkPolicy_IsolationInvariants pins the security shape
@@ -122,3 +124,32 @@ func TestAgentManifests_IncludesNetworkPolicy(t *testing.T) {
122124
t.Error("agentManifests must include the agent-isolation NetworkPolicy")
123125
}
124126
}
127+
128+
// TestResourceFor_NetworkPolicyUsesNetworkPolicyGVR guards the rc16 regression:
129+
// buildAgentNetworkPolicy added a NetworkPolicy to the agent manifest set, but
130+
// resourceFor had no case for it and fell through to the ConfigMap default. On
131+
// a real apiserver that fails ("NetworkPolicy cannot be handled as a
132+
// ConfigMap") and wedges every agent reconcile, so the remote-signer (and the
133+
// agent's wallet) never provision. A fake client tolerates the wrong GVR, so
134+
// the regression hid in unit tests — this asserts the object lands under the
135+
// NetworkPolicy GVR, not ConfigMap.
136+
func TestResourceFor_NetworkPolicyUsesNetworkPolicyGVR(t *testing.T) {
137+
agent := &monetizeapi.Agent{}
138+
agent.Name = "quant"
139+
agent.Namespace = "agent-quant"
140+
c := newProvisioningTestController(t, agent)
141+
142+
np := buildAgentNetworkPolicy(agent)
143+
if _, err := c.resourceFor(np).Create(context.Background(), np, metav1.CreateOptions{}); err != nil {
144+
t.Fatalf("create agent NetworkPolicy via resourceFor: %v", err)
145+
}
146+
147+
if _, err := c.client.Resource(monetizeapi.NetworkPolicyGVR).Namespace("agent-quant").
148+
Get(context.Background(), "agent-isolation", metav1.GetOptions{}); err != nil {
149+
t.Fatalf("agent-isolation not stored under NetworkPolicyGVR — resourceFor mis-mapped it: %v", err)
150+
}
151+
if _, err := c.client.Resource(monetizeapi.ConfigMapGVR).Namespace("agent-quant").
152+
Get(context.Background(), "agent-isolation", metav1.GetOptions{}); err == nil {
153+
t.Fatal("agent-isolation was created as a ConfigMap — resourceFor regressed to the ConfigMap default")
154+
}
155+
}

0 commit comments

Comments
 (0)