Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/public-api-server/networkpolicy_test.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.package public_api_server
4
package public_api_server
5
6
import (
7
"testing"
8
9
"github.com/gitpod-io/gitpod/installer/pkg/common"
10
"github.com/stretchr/testify/require"
11
networkingv1 "k8s.io/api/networking/v1"
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
"k8s.io/apimachinery/pkg/util/intstr"
14
)
15
16
func TestNetworkPolicy(t *testing.T) {
17
objects, err := networkpolicy(renderContextWithPublicAPI(t))
18
require.NoError(t, err)
19
require.Len(t, objects, 1)
20
21
policy, ok := objects[0].(*networkingv1.NetworkPolicy)
22
require.Truef(t, ok, "must cast object to network policy")
23
24
ingress := policy.Spec.Ingress
25
require.Len(t, ingress, 1, "must have only one ingress rule")
26
27
require.Equal(t, networkingv1.NetworkPolicyIngressRule{
28
Ports: []networkingv1.NetworkPolicyPort{
29
{
30
Protocol: common.TCPProtocol,
31
Port: &intstr.IntOrString{IntVal: GRPCContainerPort},
32
},
33
{
34
Protocol: common.TCPProtocol,
35
Port: &intstr.IntOrString{IntVal: HTTPContainerPort},
36
},
37
},
38
From: []networkingv1.NetworkPolicyPeer{
39
{
40
PodSelector: &metav1.LabelSelector{
41
MatchLabels: map[string]string{
42
"component": common.ProxyComponent,
43
},
44
},
45
},
46
},
47
}, ingress[0])
48
}
49
50