Skip to content

Commit

Permalink
Merge pull request openshift#4840 from davidvossel/np-fix-v1
Browse files Browse the repository at this point in the history
OCPBUGS-42579: Add network policies for konnectivity server and ignition server proxy
  • Loading branch information
openshift-merge-bot[bot] authored Oct 7, 2024
2 parents 83e7746 + 0d97fdd commit 605ee5a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
62 changes: 62 additions & 0 deletions hypershift-operator/controllers/hostedcluster/network_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ func (r *HostedClusterReconciler) reconcileNetworkPolicies(ctx context.Context,
}); err != nil {
return fmt.Errorf("failed to reconcile ignition nodeport network policy: %w", err)
}
// Reconcile nodeport-ignition-proxy Network Policy
policy = networkpolicy.NodePortIgnitionProxyNetworkPolicy(controlPlaneNamespaceName)
if _, err := createOrUpdate(ctx, r.Client, policy, func() error {
return reconcileNodePortIgnitionProxyNetworkPolicy(policy, hcluster)
}); err != nil {
return fmt.Errorf("failed to reconcile ignition proxy nodeport network policy: %w", err)
}
}
case hyperv1.Konnectivity:
if svc.ServicePublishingStrategy.Type == hyperv1.NodePort {
Expand All @@ -161,6 +168,15 @@ func (r *HostedClusterReconciler) reconcileNetworkPolicies(ctx context.Context,
}); err != nil {
return fmt.Errorf("failed to reconcile konnectivity nodeport network policy: %w", err)
}

// Reconcile nodeport-konnectivity Network Policy when konnectivity is hosted in the kas pod
policy = networkpolicy.NodePortKonnectivityKASNetworkPolicy(controlPlaneNamespaceName)
if _, err := createOrUpdate(ctx, r.Client, policy, func() error {
return reconcileNodePortKonnectivityKASNetworkPolicy(policy, hcluster)
}); err != nil {
return fmt.Errorf("failed to reconcile konnectivity nodeport network policy: %w", err)
}

}
}
}
Expand Down Expand Up @@ -357,6 +373,29 @@ func reconcileNodePortOauthNetworkPolicy(policy *networkingv1.NetworkPolicy, hcl
return nil
}

func reconcileNodePortIgnitionProxyNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8443)
protocol := corev1.ProtocolTCP
policy.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{
{
From: []networkingv1.NetworkPolicyPeer{},
Ports: []networkingv1.NetworkPolicyPort{
{
Port: &port,
Protocol: &protocol,
},
},
},
}
policy.Spec.PodSelector = metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "ignition-server-proxy",
},
}
policy.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeIngress}
return nil
}

func reconcileNodePortIgnitionNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(9090)
protocol := corev1.ProtocolTCP
Expand All @@ -380,6 +419,29 @@ func reconcileNodePortIgnitionNetworkPolicy(policy *networkingv1.NetworkPolicy,
return nil
}

func reconcileNodePortKonnectivityKASNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8091)
protocol := corev1.ProtocolTCP
policy.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{
{
From: []networkingv1.NetworkPolicyPeer{},
Ports: []networkingv1.NetworkPolicyPort{
{
Port: &port,
Protocol: &protocol,
},
},
},
}
policy.Spec.PodSelector = metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "kube-apiserver",
},
}
policy.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeIngress}
return nil
}

func reconcileNodePortKonnectivityNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8091)
protocol := corev1.ProtocolTCP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func NodePortIgnitionNetworkPolicy(namespace string) *networkingv1.NetworkPolicy
}
}

func NodePortIgnitionProxyNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "nodeport-ignition-proxy",
},
}
}

func NodePortKonnectivityNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -104,6 +113,15 @@ func NodePortKonnectivityNetworkPolicy(namespace string) *networkingv1.NetworkPo
}
}

func NodePortKonnectivityKASNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "nodeport-konnectivity-kas",
},
}
}

func VirtLauncherNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 605ee5a

Please sign in to comment.