-
Notifications
You must be signed in to change notification settings - Fork 173
OCPEDGE-2118: Record Kubernetes events for etcd transition lifecycle #1653
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
lucaconsalvi
wants to merge
5
commits into
openshift:main
Choose a base branch
from
lucaconsalvi:ocpedge-2118-etcd-transition-events
base: main
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.
+185
−48
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bd68bb
OCPEDGE-2118: Record Kubernetes events for etcd transition lifecycle
lucaconsalvi 4530ded
Lowercase event name to comply with RFC 1123 subdomain rules
lucaconsalvi d75bdc7
Fix gofmt alignment in const block
lucaconsalvi 76d363d
Move test-transition-events.sh to pkg/tnf/hack/
lucaconsalvi d31a9b2
Label mock events for safe cleanup in test script
lucaconsalvi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/bash | ||
| # Test script to validate transition event format on a live cluster. | ||
| # Creates mock events identical to what our code produces, then verifies | ||
| # they appear correctly in `oc get events`. | ||
| # | ||
| # Usage: ./hack/test-transition-events.sh | ||
| # Requires: oc/kubectl with cluster-admin access | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| NAMESPACE="openshift-etcd" | ||
| TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
|
|
||
| events=( | ||
| "EtcdTransitionAuthCompleted|PCS authentication completed on all nodes" | ||
| "EtcdTransitionClusterConfigured|Pacemaker cluster configured successfully" | ||
| "EtcdTransitionFencingConfigured|STONITH fencing configured successfully" | ||
| "EtcdTransitionEtcdResourceCreated|Pacemaker etcd resource agent (podman-etcd) configured" | ||
| "EtcdTransitionConstraintsConfigured|Pacemaker ordering and colocation constraints configured" | ||
| "EtcdTransitionStarted|Etcd transition from CEO-controlled to pacemaker-controlled has started" | ||
| "EtcdTransitionWaitingForRemoval|Waiting for CEO to remove static etcd container from all nodes" | ||
| "EtcdTransitionStaticContainerRemoved|Static etcd container removed from all nodes, revision is stable" | ||
| "EtcdTransitionCompleted|Etcd transition to pacemaker-controlled has completed" | ||
| ) | ||
|
|
||
| echo "Creating ${#events[@]} test transition events in ${NAMESPACE}..." | ||
|
|
||
| for entry in "${events[@]}"; do | ||
| reason="${entry%%|*}" | ||
| message="${entry#*|}" | ||
| name="test-${reason,,}-$(date +%s%N)" | ||
|
|
||
| oc apply -f - <<EOF | ||
| apiVersion: v1 | ||
| kind: Event | ||
| metadata: | ||
| name: ${name} | ||
| namespace: ${NAMESPACE} | ||
| labels: | ||
| tnf-test: "true" | ||
| involvedObject: | ||
| kind: Job | ||
| name: tnf-setup-job | ||
| namespace: ${NAMESPACE} | ||
| apiVersion: batch/v1 | ||
| reason: ${reason} | ||
| message: "${message}" | ||
| type: Normal | ||
| source: | ||
| component: tnf-setup-runner | ||
| firstTimestamp: "${TIMESTAMP}" | ||
| lastTimestamp: "${TIMESTAMP}" | ||
| count: 1 | ||
| EOF | ||
|
|
||
| echo " Created: ${reason}" | ||
| done | ||
|
|
||
| echo "" | ||
| echo "Verifying events..." | ||
| echo "" | ||
| oc get events -n "${NAMESPACE}" --field-selector reason!=="" --sort-by='.lastTimestamp' | grep -i "EtcdTransition" || echo "No EtcdTransition events found!" | ||
|
|
||
| echo "" | ||
| echo "Cleanup: oc delete events -n ${NAMESPACE} -l tnf-test=true" | ||
| echo " (events auto-expire after ~1 hour)" |
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
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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package tools | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| const ( | ||
| setupEventNamespace = "openshift-etcd" | ||
| setupJobName = "tnf-setup-job" | ||
| setupSourceComponent = "tnf-setup-runner" | ||
| ) | ||
|
|
||
| // RecordSetupEvent creates a Normal Kubernetes event in openshift-etcd for a | ||
| // TNF setup lifecycle milestone. Failures are logged but never returned — | ||
| // event recording must not block the setup. | ||
| func RecordSetupEvent(ctx context.Context, kubeClient kubernetes.Interface, reason, message string) { | ||
| event := &corev1.Event{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: fmt.Sprintf("tnf-%s-%d", strings.ToLower(reason), time.Now().UnixNano()), | ||
| Namespace: setupEventNamespace, | ||
| }, | ||
| InvolvedObject: corev1.ObjectReference{ | ||
| Kind: "Job", | ||
| Name: setupJobName, | ||
| Namespace: setupEventNamespace, | ||
| APIVersion: "batch/v1", | ||
| }, | ||
| Reason: reason, | ||
| Message: message, | ||
| Type: corev1.EventTypeNormal, | ||
| Source: corev1.EventSource{Component: setupSourceComponent}, | ||
| FirstTimestamp: metav1.Now(), | ||
| LastTimestamp: metav1.Now(), | ||
| Count: 1, | ||
| } | ||
|
|
||
| if _, err := kubeClient.CoreV1().Events(setupEventNamespace).Create(ctx, event, metav1.CreateOptions{}); err != nil { | ||
| klog.Warningf("Failed to record %s event: %v", reason, err) | ||
| } else { | ||
| klog.Infof("Recorded event: %s - %s", reason, message) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.