Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2021,30 +2021,6 @@ func (r *HostedControlPlaneReconciler) reconcileValidIDPConfigurationCondition(c
}

func (r *HostedControlPlaneReconciler) cleanupClusterNetworkOperatorResources(ctx context.Context, hcp *hyperv1.HostedControlPlane, hasRouteCap bool) error {
if restartAnnotation, ok := hcp.Annotations[hyperv1.RestartDateAnnotation]; ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has zero callers after your PR — the three call sites you removed were its only consumers. Worth deleting it here to avoid leaving dead exported code in the package. Same for MultusAdmissionControllerDeployment, NetworkNodeIdentityDeployment, OVNKubeControlPlaneDeployment and their constants in manifests/cno.go — all orphaned now.

Happy to help with a follow-up if you prefer to keep this PR minimal, but since it's all in the same ownership boundary it fits naturally here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it still called in

if err := r.cleanupClusterNetworkOperatorResources(ctx, hcp, r.ManagementClusterCapabilities.Has(capabilities.CapabilityRoute)); err != nil {
?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to comment the same - let's remove the function now because it's unused.

Isn't it still called in

The function SetRestartAnnotationAndPatch was only called in this cleanupClusterNetworkOperatorResources.
See:

ᐅ grep -Ri SetRestartAnnotationAndPatch                            
control-plane-operator/controllers/hostedcontrolplane/v2/cno/component.go:func SetRestartAnnotationAndPatch(ctx context.Context, crclient client.Client, dep *appsv1.Deployment, restartAnnotation string) error {
control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go:			if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, multusDeployment, restartAnnotation); err != nil {
control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go:		if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, networkNodeIdentityDeployment, restartAnnotation); err != nil {
control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go:		// CNO manages overall ovnkube-control-plane deployment. CPO manages restarts.  Note that cnov2.SetRestartAnnotationAndPatch just returns err == nil if the deployment isn't found (so if OVN isn't being used)
control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go:		if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, ovnKubeControlPlaneDeployment, restartAnnotation); err != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — removed SetRestartAnnotationAndPatch and the orphaned manifest helpers (MultusAdmissionControllerDeployment, NetworkNodeIdentityDeployment, OVNKubeControlPlaneDeployment) along with their unused constants and imports.

// CNO manages overall multus-admission-controller deployment. CPO manages restarts.
// TODO: why is this not done in CNO?
// Only restart multus deployment if Multus is not disabled
if !netutil.IsDisableMultiNetwork(hcp) {
multusDeployment := manifests.MultusAdmissionControllerDeployment(hcp.Namespace)
if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, multusDeployment, restartAnnotation); err != nil {
return fmt.Errorf("failed to restart multus admission controller: %w", err)
}
}

// CNO manages overall network-node-identity deployment. CPO manages restarts.
networkNodeIdentityDeployment := manifests.NetworkNodeIdentityDeployment(hcp.Namespace)
if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, networkNodeIdentityDeployment, restartAnnotation); err != nil {
return fmt.Errorf("failed to restart network node identity: %w", err)
}

// CNO manages overall ovnkube-control-plane deployment. CPO manages restarts. Note that cnov2.SetRestartAnnotationAndPatch just returns err == nil if the deployment isn't found (so if OVN isn't being used)
ovnKubeControlPlaneDeployment := manifests.OVNKubeControlPlaneDeployment(hcp.Namespace)
if err := cnov2.SetRestartAnnotationAndPatch(ctx, r.Client, ovnKubeControlPlaneDeployment, restartAnnotation); err != nil {
return fmt.Errorf("failed to restart ovnkube-control-plane: %w", err)
}
}

// Clean up ovnkube-sbdb Route if exists
if hasRouteCap {
if _, err := k8sutil.DeleteIfNeeded(ctx, r.Client, manifests.OVNKubeSBDBRoute(hcp.Namespace)); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
)

const clusterNetworkOperator = "cluster-network-operator"
const multusAdmissionController = "multus-admission-controller"
const networkNodeIdentity = "network-node-identity"
const ovnKubeControlPlane = "ovnkube-control-plane"

func ClusterNetworkOperatorDeployment(ns string) *appsv1.Deployment {
return &appsv1.Deployment{
Expand Down Expand Up @@ -50,33 +47,6 @@ func ClusterNetworkOperatorServiceAccount(namespace string) *corev1.ServiceAccou
}
}

func MultusAdmissionControllerDeployment(namespace string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: multusAdmissionController,
},
}
}

func NetworkNodeIdentityDeployment(namespace string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: networkNodeIdentity,
},
}
}

func OVNKubeControlPlaneDeployment(namespace string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: ovnKubeControlPlane,
},
}
}

func OVNKubeSBDBRoute(namespace string) *routev1.Route {
return &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cno

import (
"context"
"errors"
"fmt"

Expand All @@ -13,7 +12,6 @@ import (
"github.com/openshift/hypershift/support/podspec"

appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/ptr"

Expand Down Expand Up @@ -82,28 +80,6 @@ func isAroHCP(cpContext component.WorkloadContext) bool {
return azureutil.IsAroHCPByHCP(cpContext.HCP)
}

func SetRestartAnnotationAndPatch(ctx context.Context, crclient client.Client, dep *appsv1.Deployment, restartAnnotation string) error {
if err := crclient.Get(ctx, client.ObjectKeyFromObject(dep), dep); err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return fmt.Errorf("failed retrieve deployment: %w", err)
}

patch := dep.DeepCopy()
podMeta := patch.Spec.Template.ObjectMeta
if podMeta.Annotations == nil {
podMeta.Annotations = map[string]string{}
}
podMeta.Annotations[hyperv1.RestartDateAnnotation] = restartAnnotation

if err := crclient.Patch(ctx, patch, client.MergeFrom(dep)); err != nil {
return fmt.Errorf("failed to set restart annotation: %w", err)
}

return nil
}

type operand struct {
DeploymentName string
ContainerName string
Expand Down