-
Notifications
You must be signed in to change notification settings - Fork 443
RFE-5434: Add cluster ID and timestamp to must-gather directory name #2252
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
dda7aec
9a50bdb
6483683
2d3c35a
177b4d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ import ( | |
| "k8s.io/kubectl/pkg/util/templates" | ||
| admissionapi "k8s.io/pod-security-admission/api" | ||
| "k8s.io/utils/exec" | ||
| "k8s.io/utils/clock" | ||
| utilptr "k8s.io/utils/ptr" | ||
|
|
||
| configclient "github.com/openshift/client-go/config/clientset/versioned" | ||
|
|
@@ -73,7 +74,9 @@ var ( | |
| `) | ||
|
|
||
| mustGatherExample = templates.Examples(` | ||
| # Gather information using the default plug-in image and command, writing into ./must-gather.local.<rand> | ||
| # Gather information using the default plug-in image and command, writing into | ||
| # ./must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> | ||
| # or ./must-gather.local.<timestamp>.<rand> if the cluster ID is unavailable | ||
| oc adm must-gather | ||
|
|
||
| # Gather information with a specific local folder to copy to | ||
|
|
@@ -185,6 +188,7 @@ func NewMustGatherOptions(streams genericiooptions.IOStreams) *MustGatherOptions | |
| IOStreams: streams, | ||
| Timeout: 10 * time.Minute, | ||
| VolumePercentage: defaultVolumePercentage, | ||
| Clock: clock.RealClock{}, | ||
|
Contributor
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. Better to export as few fields as necessary. I would rename this to clock := o.clock
if clock == nil {
clock = clock.RealClock{}
}Or feel free to add a helper method on
Author
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. Good point, updated. Renamed to unexported |
||
| } | ||
| opts.LogOut = opts.newPrefixWriter(streams.Out, "[must-gather ] OUT", false, true) | ||
| opts.RawOut = opts.newPrefixWriter(streams.Out, "", false, false) | ||
|
|
@@ -230,7 +234,7 @@ func (o *MustGatherOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg | |
| } | ||
| } | ||
| if len(o.DestDir) == 0 { | ||
| o.DestDir = fmt.Sprintf("must-gather.local.%06d", rand.Int63()) | ||
| o.DestDir = o.generateDestDir(context.TODO()) | ||
| } | ||
| // TODO: this should be in Validate() method, but added here because of the call to o.completeImages() below | ||
| if o.AllImages { | ||
|
|
@@ -266,6 +270,39 @@ func (o *MustGatherOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg | |
| return nil | ||
| } | ||
|
|
||
| // generateDestDir builds the default destination directory name for must-gather output. | ||
| // The format includes a partial cluster ID (last 12 characters), a UTC timestamp, and a | ||
| // random ID to help distinguish must-gather archives from different clusters and collection | ||
| // times. If the cluster ID cannot be retrieved (e.g. cluster is unreachable), it falls back | ||
| // to the timestamp and random ID only. | ||
| // See: https://issues.redhat.com/browse/RFE-5434 | ||
| func (o *MustGatherOptions) generateDestDir(ctx context.Context) string { | ||
|
Contributor
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. Honestly would be nicer to pass a
Author
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. Good suggestion, done. Added a In production, it's initialized with The random suffix from
Author
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. @tchap just checking in on this. All your feedback has been addressed (reordering, clock.PassiveClock, klog.V(4) debug logging, fallback format in example text). Could you take a quick look when you get a chance? Also, would you be able to run /ok-to-test so CI can pick it up? Thanks! |
||
| clusterIDSuffix := "" | ||
| if o.ConfigClient != nil { | ||
| lookupCtx, cancel := context.WithTimeout(ctx, 5*time.Second) | ||
| defer cancel() | ||
| cv, err := o.ConfigClient.ConfigV1().ClusterVersions().Get(lookupCtx, "version", metav1.GetOptions{}) | ||
| if err == nil { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| id := string(cv.Spec.ClusterID) | ||
| if len(id) >= 12 { | ||
| clusterIDSuffix = id[len(id)-12:] | ||
| } else if len(id) > 0 { | ||
| clusterIDSuffix = id | ||
| } | ||
| } else { | ||
| klog.V(4).Infof("unable to retrieve cluster ID for directory name: %v", err) | ||
| } | ||
| } | ||
|
|
||
| timestamp := o.Clock.Now().UTC().Format("20060102T150405Z") | ||
| randID := rand.Int63() | ||
|
|
||
| if clusterIDSuffix != "" { | ||
| return fmt.Sprintf("must-gather.local.%s.%s.%06d", clusterIDSuffix, timestamp, randID) | ||
| } | ||
| return fmt.Sprintf("must-gather.local.%s.%06d", timestamp, randID) | ||
| } | ||
|
|
||
| func (o *MustGatherOptions) completeImages(ctx context.Context) error { | ||
| for _, imageStream := range o.ImageStreams { | ||
| if image, err := o.resolveImageStreamTagString(ctx, imageStream); err == nil { | ||
|
|
@@ -398,6 +435,7 @@ type MustGatherOptions struct { | |
| SinceTime string | ||
|
|
||
| RsyncRshCmd string | ||
| Clock clock.PassiveClock | ||
|
|
||
| PrinterCreated printers.ResourcePrinter | ||
| PrinterDeleted printers.ResourcePrinter | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.