Skip to content

Commit 1e3b317

Browse files
committed
Remove k8s.io/kubernetes from project dependency
Signed-off-by: Dyanngg <[email protected]>
1 parent 4f308f4 commit 1e3b317

21 files changed

+488
-668
lines changed

conformance/conformance_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,53 @@ limitations under the License.
1818
package conformance_test
1919

2020
import (
21-
"flag"
2221
"strings"
2322
"testing"
2423

25-
"sigs.k8s.io/network-policy-api/apis/v1alpha1"
26-
"sigs.k8s.io/network-policy-api/conformance/tests"
27-
"sigs.k8s.io/network-policy-api/conformance/utils/flags"
28-
"sigs.k8s.io/network-policy-api/conformance/utils/suite"
29-
3024
"k8s.io/apimachinery/pkg/util/sets"
25+
"k8s.io/client-go/kubernetes"
3126
_ "k8s.io/client-go/plugin/pkg/client/auth"
32-
"k8s.io/kubernetes/test/e2e/framework"
33-
e2econfig "k8s.io/kubernetes/test/e2e/framework/config"
27+
"k8s.io/client-go/tools/clientcmd"
3428
"sigs.k8s.io/controller-runtime/pkg/client"
3529
"sigs.k8s.io/controller-runtime/pkg/client/config"
30+
31+
"sigs.k8s.io/network-policy-api/apis/v1alpha1"
32+
"sigs.k8s.io/network-policy-api/conformance/tests"
33+
"sigs.k8s.io/network-policy-api/conformance/utils/flags"
34+
"sigs.k8s.io/network-policy-api/conformance/utils/suite"
3635
)
3736

3837
func TestConformance(t *testing.T) {
3938
cfg, err := config.GetConfig()
4039
if err != nil {
4140
t.Fatalf("Error loading Kubernetes config: %v", err)
4241
}
43-
client, err := client.New(cfg, client.Options{})
42+
c, err := client.New(cfg, client.Options{})
4443
if err != nil {
4544
t.Fatalf("Error initializing Kubernetes client: %v", err)
4645
}
4746

48-
v1alpha1.AddToScheme(client.Scheme())
47+
kubeConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).ClientConfig()
48+
if err != nil {
49+
t.Fatalf("error building Kube config for client-go: %v", err)
50+
}
51+
clientset, err := kubernetes.NewForConfig(kubeConfig)
52+
if err != nil {
53+
t.Fatalf("error when creating Kubernetes ClientSet: %v", err)
54+
}
55+
56+
v1alpha1.AddToScheme(c.Scheme())
4957

5058
supportedFeatures := parseSupportedFeatures(*flags.SupportedFeatures)
5159
exemptFeatures := parseSupportedFeatures(*flags.ExemptFeatures)
5260

53-
// Register test flags, then parse flags.
54-
handleFlags()
55-
5661
t.Logf("Running conformance tests with cleanup: %t\n debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]",
5762
*flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures)
5863

5964
cSuite := suite.New(suite.Options{
60-
Client: client,
65+
Client: c,
66+
ClientSet: clientset,
67+
KubeConfig: *cfg,
6168
Debug: *flags.ShowDebug,
6269
CleanupBaseResources: *flags.CleanupBaseResources,
6370
SupportedFeatures: supportedFeatures,
@@ -81,10 +88,3 @@ func parseSupportedFeatures(f string) sets.Set[suite.SupportedFeature] {
8188
}
8289
return res
8390
}
84-
85-
// handleFlags sets up all flags and parses the command line.
86-
func handleFlags() {
87-
e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
88-
framework.RegisterCommonFlags(flag.CommandLine)
89-
flag.Parse()
90-
}

conformance/tests/admin-network-policy-core-egress-sctp-rules.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"testing"
2222

2323
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2425
v1 "k8s.io/api/core/v1"
25-
"k8s.io/kubernetes/test/e2e/framework"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727

2828
"sigs.k8s.io/network-policy-api/apis/v1alpha1"
@@ -55,15 +55,15 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
5555
Namespace: "network-policy-conformance-gryffindor",
5656
Name: "harry-potter-0",
5757
}, serverPod)
58-
framework.ExpectNoError(err, "unable to fetch the server pod")
58+
require.NoErrorf(t, err, "unable to fetch the server pod")
5959
// luna-lovegood-0 is our client pod in ravenclaw namespace
6060
// ensure egress is ALLOWED to gryffindor from ravenclaw
6161
// egressRule at index0 will take precedence over egressRule at index1; thus ALLOW takes precedence over DENY since rules are ordered
62-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
62+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
6363
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, true)
6464
assert.Equal(t, true, success)
6565
// luna-lovegood-1 is our client pod in ravenclaw namespace
66-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
66+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
6767
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, true)
6868
assert.Equal(t, true, success)
6969
})
@@ -78,15 +78,15 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
7878
Namespace: "network-policy-conformance-hufflepuff",
7979
Name: "cedric-diggory-1",
8080
}, serverPod)
81-
framework.ExpectNoError(err, "unable to fetch the server pod")
81+
require.NoErrorf(t, err, "unable to fetch the server pod")
8282
// luna-lovegood-0 is our client pod in ravenclaw namespace
8383
// ensure egress is ALLOWED to hufflepuff from ravenclaw at port 9003; egressRule at index5 should take effect
84-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
84+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
8585
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, true)
8686
assert.Equal(t, true, success)
8787
// luna-lovegood-1 is our client pod in ravenclaw namespace
8888
// ensure egress is DENIED to hufflepuff from ravenclaw for rest of the traffic; egressRule at index6 should take effect
89-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
89+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
9090
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, false)
9191
assert.Equal(t, true, success)
9292
})
@@ -101,26 +101,26 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
101101
Namespace: "network-policy-conformance-gryffindor",
102102
Name: "harry-potter-1",
103103
}, serverPod)
104-
framework.ExpectNoError(err, "unable to fetch the server pod")
104+
require.NoErrorf(t, err, "unable to fetch the server pod")
105105
anp := &v1alpha1.AdminNetworkPolicy{}
106106
err = s.Client.Get(ctx, client.ObjectKey{
107107
Name: "egress-sctp",
108108
}, anp)
109-
framework.ExpectNoError(err, "unable to fetch the admin network policy")
109+
require.NoErrorf(t, err, "unable to fetch the admin network policy")
110110
// swap rules at index0 and index1
111111
allowRule := anp.DeepCopy().Spec.Egress[0]
112112
anp.Spec.Egress[0] = anp.DeepCopy().Spec.Egress[1]
113113
anp.Spec.Egress[1] = allowRule
114114
err = s.Client.Update(ctx, anp)
115-
framework.ExpectNoError(err, "unable to update the admin network policy")
115+
require.NoErrorf(t, err, "unable to update the admin network policy")
116116
// luna-lovegood-0 is our client pod in gryffindor namespace
117117
// ensure egress is DENIED to gryffindor from ravenclaw
118118
// egressRule at index0 will take precedence over egressRule at index1; thus DENY takes precedence over ALLOW since rules are ordered
119-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
119+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
120120
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, false)
121121
assert.Equal(t, true, success)
122122
// luna-lovegood-1 is our client pod in ravenclaw namespace
123-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
123+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
124124
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, false)
125125
assert.Equal(t, true, success)
126126
})
@@ -135,15 +135,15 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
135135
Namespace: "network-policy-conformance-slytherin",
136136
Name: "draco-malfoy-0",
137137
}, serverPod)
138-
framework.ExpectNoError(err, "unable to fetch the server pod")
138+
require.NoErrorf(t, err, "unable to fetch the server pod")
139139
// luna-lovegood-0 is our client pod in ravenclaw namespace
140140
// ensure egress to slytherin is DENIED from ravenclaw at port 9003; egressRule at index3 should take effect
141-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
141+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
142142
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, false)
143143
assert.Equal(t, true, success)
144144
// luna-lovegood-1 is our client pod in ravenclaw namespace
145145
// ensure egress to slytherin is ALLOWED from ravenclaw for rest of the traffic; matches no rules hence allowed
146-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
146+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
147147
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, true)
148148
assert.Equal(t, true, success)
149149
})
@@ -158,26 +158,26 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
158158
Namespace: "network-policy-conformance-gryffindor",
159159
Name: "harry-potter-1",
160160
}, serverPod)
161-
framework.ExpectNoError(err, "unable to fetch the server pod")
161+
require.NoErrorf(t, err, "unable to fetch the server pod")
162162
anp := &v1alpha1.AdminNetworkPolicy{}
163163
err = s.Client.Get(ctx, client.ObjectKey{
164164
Name: "egress-sctp",
165165
}, anp)
166-
framework.ExpectNoError(err, "unable to fetch the admin network policy")
166+
require.NoErrorf(t, err, "unable to fetch the admin network policy")
167167
// swap rules at index0 and index2
168168
denyRule := anp.DeepCopy().Spec.Egress[0]
169169
anp.Spec.Egress[0] = anp.DeepCopy().Spec.Egress[2]
170170
anp.Spec.Egress[2] = denyRule
171171
err = s.Client.Update(ctx, anp)
172-
framework.ExpectNoError(err, "unable to update the admin network policy")
172+
require.NoErrorf(t, err, "unable to update the admin network policy")
173173
// luna-lovegood-0 is our client pod in ravenclaw namespace
174174
// ensure egress is PASSED from gryffindor to ravenclaw
175175
// egressRule at index0 will take precedence over egressRule at index1&index2; thus PASS takes precedence over ALLOW/DENY since rules are ordered
176-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
176+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
177177
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, true)
178178
assert.Equal(t, true, success)
179179
// luna-lovegood-1 is our client pod in ravenclaw namespace
180-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
180+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
181181
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, true)
182182
assert.Equal(t, true, success)
183183
})
@@ -192,26 +192,26 @@ var AdminNetworkPolicyEgressSCTP = suite.ConformanceTest{
192192
Namespace: "network-policy-conformance-slytherin",
193193
Name: "draco-malfoy-0",
194194
}, serverPod)
195-
framework.ExpectNoError(err, "unable to fetch the server pod")
195+
require.NoErrorf(t, err, "unable to fetch the server pod")
196196
anp := &v1alpha1.AdminNetworkPolicy{}
197197
err = s.Client.Get(ctx, client.ObjectKey{
198198
Name: "egress-sctp",
199199
}, anp)
200-
framework.ExpectNoError(err, "unable to fetch the admin network policy")
200+
require.NoErrorf(t, err, "unable to fetch the admin network policy")
201201
// swap rules at index3 and index4
202202
denyRule := anp.DeepCopy().Spec.Egress[3]
203203
anp.Spec.Egress[3] = anp.DeepCopy().Spec.Egress[4]
204204
anp.Spec.Egress[4] = denyRule
205205
err = s.Client.Update(ctx, anp)
206-
framework.ExpectNoError(err, "unable to update the admin network policy")
206+
require.NoErrorf(t, err, "unable to update the admin network policy")
207207
// luna-lovegood-0 is our client pod in ravenclaw namespace
208208
// ensure egress to slytherin is PASSED from ravenclaw at port 9003; egressRule at index3 should take effect
209-
success := kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
209+
success := kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-0", "sctp",
210210
serverPod.Status.PodIP, int32(9003), s.TimeoutConfig.RequestTimeout, true)
211211
assert.Equal(t, true, success)
212212
// luna-lovegood-1 is our client pod in ravenclaw namespace
213213
// ensure egress to slytherin is ALLOWED from ravenclaw for rest of the traffic; matches no rules hence allowed
214-
success = kubernetes.PokeServer(t, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
214+
success = kubernetes.PokeServer(t, s.ClientSet, &s.KubeConfig, "network-policy-conformance-ravenclaw", "luna-lovegood-1", "sctp",
215215
serverPod.Status.PodIP, int32(9005), s.TimeoutConfig.RequestTimeout, true)
216216
assert.Equal(t, true, success)
217217
})

0 commit comments

Comments
 (0)