-
Notifications
You must be signed in to change notification settings - Fork 294
OCPBUGS-88531: Propagate restart-date annotation to CNO operand pod templates #3030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bryan-cox
wants to merge
1
commit into
openshift:master
Choose a base branch
from
bryan-cox:OCPBUGS-88531
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ const ( | |
| ClusterIDLabel = "_id" | ||
| // HyperShiftConditionTypePrefix is a cluster network operator condition type prefix in hostedControlPlane status | ||
| HyperShiftConditionTypePrefix = "network.operator.openshift.io/" | ||
| // RestartDateAnnotation is used to trigger rolling restarts of control plane operands | ||
| RestartDateAnnotation = "hypershift.openshift.io/restart-date" | ||
| ) | ||
|
|
||
| type RelatedObject struct { | ||
|
|
@@ -55,6 +57,7 @@ type RelatedObject struct { | |
|
|
||
| // HostedControlPlane represents a subset of HyperShift API definition for HostedControlPlane | ||
| type HostedControlPlane struct { | ||
| Namespace string | ||
| ClusterID string | ||
| ControllerAvailabilityPolicy AvailabilityPolicy | ||
| NodeSelector map[string]string | ||
|
|
@@ -63,6 +66,7 @@ type HostedControlPlane struct { | |
| AdvertiseAddress string | ||
| AdvertisePort int | ||
| PriorityClass string | ||
| RestartDate string | ||
| } | ||
|
|
||
| // AvailabilityPolicy specifies a high level availability policy for components. | ||
|
|
@@ -151,6 +155,11 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan | |
| return nil, fmt.Errorf("failed to extract control plane priority class annotation: %v", err) | ||
| } | ||
|
|
||
| restartDate, _, err := unstructured.NestedString(hcp.UnstructuredContent(), "metadata", "annotations", RestartDateAnnotation) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to extract restart date annotation: %v", err) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: It would be better to use |
||
| } | ||
|
|
||
| nodeSelector, _, err := unstructured.NestedStringMap(hcp.UnstructuredContent(), "spec", "nodeSelector") | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed extract nodeSelector: %v", err) | ||
|
|
@@ -256,6 +265,7 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan | |
| } | ||
|
|
||
| return &HostedControlPlane{ | ||
| Namespace: hcp.GetNamespace(), | ||
| ControllerAvailabilityPolicy: AvailabilityPolicy(controllerAvailabilityPolicy), | ||
| ClusterID: clusterID, | ||
| NodeSelector: nodeSelector, | ||
|
|
@@ -264,9 +274,42 @@ func ParseHostedControlPlane(hcp *unstructured.Unstructured) (*HostedControlPlan | |
| AdvertiseAddress: advertiseAddress, | ||
| AdvertisePort: int(advertisePort), | ||
| PriorityClass: controlPlanePriorityClassAnnotation, | ||
| RestartDate: restartDate, | ||
| }, nil | ||
| } | ||
|
|
||
| // SetRestartDateAnnotation sets the restart-date annotation on pod templates of | ||
| // Deployment, DaemonSet, and StatefulSet objects in the HCP namespace to trigger | ||
| // a rolling restart. Objects outside the HCP namespace (e.g. guest-cluster | ||
| // DaemonSets) are not modified. | ||
| func SetRestartDateAnnotation(objs []*unstructured.Unstructured, hcpNamespace, restartDate string) error { | ||
| for _, obj := range objs { | ||
| if obj.GetNamespace() != hcpNamespace { | ||
| continue | ||
| } | ||
| if obj.GetAPIVersion() != "apps/v1" { | ||
| continue | ||
| } | ||
| kind := obj.GetKind() | ||
| if kind != "Deployment" && kind != "DaemonSet" && kind != "StatefulSet" { | ||
| continue | ||
| } | ||
|
|
||
| anno, _, err := unstructured.NestedStringMap(obj.Object, "spec", "template", "metadata", "annotations") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get pod template annotations from %s/%s: %v", kind, obj.GetName(), err) | ||
| } | ||
| if anno == nil { | ||
| anno = map[string]string{} | ||
| } | ||
| anno[RestartDateAnnotation] = restartDate | ||
| if err := unstructured.SetNestedStringMap(obj.Object, anno, "spec", "template", "metadata", "annotations"); err != nil { | ||
| return fmt.Errorf("failed to set restart-date annotation on %s/%s: %v", kind, obj.GetName(), err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // SetHostedControlPlaneConditions updates the hcp status.conditions based on the provided operStatus | ||
| // Returns an updated list of conditions and an error. If there are no changes, the returned list is empty. | ||
| func SetHostedControlPlaneConditions(hcp *unstructured.Unstructured, operStatus *operv1.NetworkStatus) ([]metav1.Condition, error) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the annotation is removed there will be another rollout, is this the expected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removing the annotation would cause another rollout since the pod template spec changes (annotation removed). This is the expected behavior — removing the annotation is an explicit operator action, and the resulting rollout restores the clean state. I'll document this in the PR description.