Skip to content

Commit c0e5e53

Browse files
committed
chore: reset release-please
1 parent b206684 commit c0e5e53

3 files changed

Lines changed: 174 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{".":"1.0.0"}
1+
{}

.github/workflows/release-please.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
outputs:
1818
release_created: ${{ steps.release.outputs.release_created }}
1919
tag_name: ${{ steps.release.outputs.tag_name }}
20+
sha: ${{ steps.release.outputs.sha }}
2021
upload_url: ${{ steps.release.outputs.upload_url }}
2122
steps:
2223
- uses: googleapis/release-please-action@v4
@@ -39,7 +40,7 @@ jobs:
3940
steps:
4041
- uses: actions/checkout@v5
4142
with:
42-
ref: ${{ needs.release-please.outputs.tag_name }}
43+
ref: ${{ needs.release-please.outputs.sha }}
4344

4445
- uses: arduino/setup-task@v2
4546
with:

pkg/util/networkpolicy/target.go

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package networkpolicy
2+
3+
import (
4+
"github.com/teutonet/cluster-api-provider-hosted-control-plane/api/v1alpha1"
5+
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/operator/util/names"
6+
corev1 "k8s.io/api/core/v1"
7+
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
8+
networkingv1ac "k8s.io/client-go/applyconfigurations/networking/v1"
9+
capiv2 "sigs.k8s.io/cluster-api/api/core/v1beta2"
10+
)
11+
12+
type NetworkPolicyTarget interface {
13+
ApplyToVanillaNetworkPolicy(
14+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
15+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration
16+
}
17+
18+
type DNSNetworkPolicyTarget struct {
19+
Hostname string
20+
}
21+
22+
func NewDNSNetworkPolicyTarget(hostname string) DNSNetworkPolicyTarget {
23+
return DNSNetworkPolicyTarget{
24+
Hostname: hostname,
25+
}
26+
}
27+
28+
var _ NetworkPolicyTarget = DNSNetworkPolicyTarget{}
29+
30+
func (d DNSNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
31+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
32+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
33+
// DNS filtering is not supported in NetworkPolicy, so we allow traffic from/to anywhere.
34+
return NewCIDRNetworkPolicyTarget("0.0.0.0/0").
35+
ApplyToVanillaNetworkPolicy(networkPolicyPeerApplyConfiguration)
36+
}
37+
38+
type CIDRNetworkPolicyTarget struct {
39+
CIDR string
40+
}
41+
42+
func NewCIDRNetworkPolicyTarget(cidr string) CIDRNetworkPolicyTarget {
43+
return CIDRNetworkPolicyTarget{
44+
CIDR: cidr,
45+
}
46+
}
47+
48+
func NewIPNetworkPolicyTarget(ip string) CIDRNetworkPolicyTarget {
49+
return CIDRNetworkPolicyTarget{
50+
CIDR: ip + "/32",
51+
}
52+
}
53+
54+
var _ NetworkPolicyTarget = CIDRNetworkPolicyTarget{}
55+
56+
func (c CIDRNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
57+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
58+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
59+
return networkPolicyPeerApplyConfiguration.
60+
WithIPBlock(
61+
networkingv1ac.IPBlock().
62+
WithCIDR(c.CIDR),
63+
)
64+
}
65+
66+
type APIServerNetworkPolicyTarget struct {
67+
HostedControlPlane *v1alpha1.HostedControlPlane
68+
}
69+
70+
func NewAPIServerNetworkPolicyTarget(hostedControlPlane *v1alpha1.HostedControlPlane) APIServerNetworkPolicyTarget {
71+
return APIServerNetworkPolicyTarget{
72+
HostedControlPlane: hostedControlPlane,
73+
}
74+
}
75+
76+
var _ NetworkPolicyTarget = APIServerNetworkPolicyTarget{}
77+
78+
func (a APIServerNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
79+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
80+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
81+
return NewIPNetworkPolicyTarget(a.HostedControlPlane.Status.LegacyIP).
82+
ApplyToVanillaNetworkPolicy(networkPolicyPeerApplyConfiguration)
83+
}
84+
85+
type ComponentNetworkPolicyTarget struct {
86+
Cluster *capiv2.Cluster
87+
Component string
88+
}
89+
90+
func NewComponentNetworkPolicyTarget(cluster *capiv2.Cluster, component string) ComponentNetworkPolicyTarget {
91+
return ComponentNetworkPolicyTarget{
92+
Cluster: cluster,
93+
Component: component,
94+
}
95+
}
96+
97+
var _ NetworkPolicyTarget = ComponentNetworkPolicyTarget{}
98+
99+
func (c ComponentNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
100+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
101+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
102+
return NewLabelNetworkPolicyTarget(
103+
names.GetControlPlaneLabels(c.Cluster, c.Component),
104+
map[string]string{
105+
corev1.LabelMetadataName: c.Cluster.Namespace,
106+
},
107+
).ApplyToVanillaNetworkPolicy(networkPolicyPeerApplyConfiguration)
108+
}
109+
110+
type LabelNetworkPolicyTarget struct {
111+
PodLabels map[string]string
112+
NamespaceLabels map[string]string
113+
}
114+
115+
func NewLabelNetworkPolicyTarget(podLabels, namespaceLabels map[string]string) LabelNetworkPolicyTarget {
116+
return LabelNetworkPolicyTarget{
117+
PodLabels: podLabels,
118+
NamespaceLabels: namespaceLabels,
119+
}
120+
}
121+
122+
func NewPodLabelNetworkPolicyTarget(podLabels map[string]string) LabelNetworkPolicyTarget {
123+
return LabelNetworkPolicyTarget{
124+
PodLabels: podLabels,
125+
}
126+
}
127+
128+
func NewNamespaceLabelNetworkPolicyTarget(namespaceLabels map[string]string) LabelNetworkPolicyTarget {
129+
return LabelNetworkPolicyTarget{
130+
NamespaceLabels: namespaceLabels,
131+
}
132+
}
133+
134+
var _ NetworkPolicyTarget = LabelNetworkPolicyTarget{}
135+
136+
func (l LabelNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
137+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
138+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
139+
policyPeerApplyConfiguration := networkPolicyPeerApplyConfiguration
140+
if l.PodLabels == nil {
141+
policyPeerApplyConfiguration = policyPeerApplyConfiguration.
142+
WithPodSelector(metav1ac.LabelSelector().WithMatchLabels(l.PodLabels))
143+
}
144+
if l.NamespaceLabels != nil {
145+
policyPeerApplyConfiguration = policyPeerApplyConfiguration.
146+
WithNamespaceSelector(metav1ac.LabelSelector().WithMatchLabels(l.NamespaceLabels))
147+
}
148+
return policyPeerApplyConfiguration
149+
}
150+
151+
type HCPControllerNetworkPolicyTarget struct {
152+
ControllerNamespace string
153+
}
154+
155+
func NewHCPControllerNetworkPolicyTarget(controllerNamespace string) HCPControllerNetworkPolicyTarget {
156+
return HCPControllerNetworkPolicyTarget{
157+
ControllerNamespace: controllerNamespace,
158+
}
159+
}
160+
161+
var _ NetworkPolicyTarget = HCPControllerNetworkPolicyTarget{}
162+
163+
func (h HCPControllerNetworkPolicyTarget) ApplyToVanillaNetworkPolicy(
164+
networkPolicyPeerApplyConfiguration *networkingv1ac.NetworkPolicyPeerApplyConfiguration,
165+
) *networkingv1ac.NetworkPolicyPeerApplyConfiguration {
166+
return NewNamespaceLabelNetworkPolicyTarget(
167+
map[string]string{
168+
corev1.LabelMetadataName: h.ControllerNamespace,
169+
},
170+
).ApplyToVanillaNetworkPolicy(networkPolicyPeerApplyConfiguration)
171+
}

0 commit comments

Comments
 (0)