MCPcopy
hub / github.com/kubernetes/test-infra / uploadLogfilesToGCS

Function uploadLogfilesToGCS

logexporter/cmd/main.go:196–216  ·  view source on GitHub ↗
(logDir string)

Source from the content-addressed store, hash-verified

194}
195
196func uploadLogfilesToGCS(logDir string) error {
197 cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("ls %v/*", logDir))
198 output, err := cmd.Output()
199 if err != nil {
200 return fmt.Errorf("Could not list any logfiles: %w", err)
201 }
202 klog.Infof("List of logfiles available: %v", string(output))
203
204 gcsLogPath := *gcsPath + "/" + *nodeName
205 klog.Infof("Uploading logfiles to GCS at path '%v'", gcsLogPath)
206 for uploadAttempt := 0; uploadAttempt < 3; uploadAttempt++ {
207 // Upload the files with compression (-z) and parallelism (-m) for speeding up.
208 if err = runCommand("gsutil", "-m", "-q", "cp", "-c",
209 "-z", "log,txt,xml", logDir+"/*", gcsLogPath); err != nil {
210 klog.Errorf("Attempt %v to upload to GCS failed: %v", uploadAttempt, err)
211 continue
212 }
213 return writeSuccessMarkerFile()
214 }
215 return fmt.Errorf("Multiple attempts of gsutil failed, the final one due to: %w", err)
216}
217
218// Write a marker file to GCS named after this node to indicate logexporter's success.
219// The directory to which we write this file can then be used as a registry to quickly

Callers 1

mainFunction · 0.85

Calls 3

runCommandFunction · 0.85
writeSuccessMarkerFileFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected