squakez commented on code in PR #6866:
URL: https://github.com/apache/camel-k/pull/6866#discussion_r4227442491


##########
script/Makefile:
##########
@@ -277,6 +277,12 @@ test-common: gotestfmt-install
        go test -p $(TEST_COMMON_PARALLEL_COUNT) -timeout 90m -v 
./e2e/common/... --parallel 1 -tags=integration $(GOTESTFMT) || ((FAILED++)); \
        exit $${FAILED}
 
+#
+# NetworkPolicy test that requires a Calico-backed Minikube cluster
+#
+test-network-policy: gotestfmt-install
+       go test -p 1 -timeout 45m -v ./e2e/common/traits --parallel 1 
-tags=integration -run '^TestServiceNetworkPolicy$$' $(GOTESTFMT)

Review Comment:
   Probably better a shorter timeout (20 min?)



##########
.github/workflows/network-policy.yml:
##########
@@ -33,7 +33,7 @@ on:
       - 'e2e/common/traits/files/NetworkPolicyConsumer.java'
       - '.github/actions/infra-setting/action.yml'
       - '.github/workflows/network-policy.yml'
-      - 'script/Makefile'
+      - 'Makefile'

Review Comment:
   I think the previous was fine, as the Makefile is a symbolic link to the one 
in script



##########
script/Makefile:
##########
@@ -277,6 +277,12 @@ test-common: gotestfmt-install
        go test -p $(TEST_COMMON_PARALLEL_COUNT) -timeout 90m -v 
./e2e/common/... --parallel 1 -tags=integration $(GOTESTFMT) || ((FAILED++)); \
        exit $${FAILED}
 
+#
+# NetworkPolicy test that requires a Calico-backed Minikube cluster
+#
+test-network-policy: gotestfmt-install
+       go test -p 1 -timeout 45m -v ./e2e/common/traits --parallel 1 
-tags=integration -run '^TestServiceNetworkPolicy$$' $(GOTESTFMT)

Review Comment:
   Also, I think it would be better to isolate the tests, otherwise they will 
also run in the common workflow. You can create an e2e/networkpolicy directory



##########
e2e/common/traits/network_policy_test.go:
##########
@@ -0,0 +1,110 @@
+//go:build integration
+// +build integration
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package common
+
+import (
+       "context"
+       "testing"
+
+       . "github.com/onsi/gomega"
+
+       corev1 "k8s.io/api/core/v1"
+       networkingv1 "k8s.io/api/networking/v1"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       k8serrors "k8s.io/apimachinery/pkg/api/errors"
+       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+       . "github.com/apache/camel-k/v2/e2e/support"
+       v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+)
+
+func TestServiceNetworkPolicy(t *testing.T) {
+       WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+               namespace, err := TestClient(t).CoreV1().Namespaces().Get(ctx, 
ns, metav1.GetOptions{})
+               g.Expect(err).ToNot(HaveOccurred())
+
+               labels := namespace.Labels
+               if labels == nil {
+                       labels = map[string]string{}
+               }
+               labels["network-policy-test"] = "enabled"
+               namespace.Labels = labels
+               _, err = TestClient(t).CoreV1().Namespaces().Update(ctx, 
namespace, metav1.UpdateOptions{})
+               g.Expect(err).ToNot(HaveOccurred())
+
+               serverName := RandomizedSuffixName("network-policy-server")
+               g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java",
+                       "-t", "service.enabled=true",
+                       "-t", "service.network-policy-enabled=true",
+                       "-t", 
"service.network-policy-namespace-selector.'network-policy-test'=enabled",
+                       "-t", "service.network-policy-pod-selector.app=allowed",
+                       "--name", serverName,
+               ).Execute()).To(Succeed())
+
+               g.Eventually(IntegrationConditionStatus(t, ctx, ns, serverName, 
v1.IntegrationConditionReady), TestTimeoutMedium).
+                       Should(Equal(corev1.ConditionTrue))
+               g.Eventually(NetworkPolicyByName(t, ctx, ns, serverName), 
TestTimeoutShort).ShouldNot(BeNil())
+
+               allowedName := RandomizedSuffixName("network-policy-allowed")
+               deniedName := RandomizedSuffixName("network-policy-denied")
+
+               g.Expect(KamelRun(t, ctx, ns, 
"files/NetworkPolicyConsumer.java",
+                       "-p", "serviceName="+serverName,
+                       "--label", "app=allowed",
+                       "-t", "owner.target-labels=*",
+                       "--name", allowedName,
+               ).Execute()).To(Succeed())
+
+               g.Expect(KamelRun(t, ctx, ns, 
"files/NetworkPolicyConsumer.java",
+                       "-p", "serviceName="+serverName,
+                       "--label", "app=denied",
+                       "-t", "owner.target-labels=*",
+                       "--name", deniedName,
+               ).Execute()).To(Succeed())
+
+               g.Eventually(IntegrationPodPhase(t, ctx, ns, allowedName), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))

Review Comment:
   Better wait for Integration Condition Ready



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to