-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2d0254
commit 7917761
Showing
2 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,88 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func receivePreflightResults(preflightJobNamespace string, preflightJobName string) error { | ||
// poll until there are no more "running" collectors | ||
troubleshootClient, err := createTroubleshootK8sClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bundlePath, err := ioutil.TempDir("", "troubleshoot") | ||
if err != nil { | ||
return err | ||
} | ||
defer os.RemoveAll(bundlePath) | ||
|
||
receivedPreflights := []string{} | ||
for { | ||
job, err := troubleshootClient.PreflightJobs(preflightJobNamespace).Get(preflightJobName, metav1.GetOptions{}) | ||
if err != nil && kuberneteserrors.IsNotFound(err) { | ||
// where did it go! | ||
return nil | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
// If the collectors are still running, hang tight. | ||
if !job.Status.IsCollectorsComplete { | ||
time.Sleep(time.Millisecond * 400) | ||
continue | ||
} | ||
|
||
for _, readyPreflight := range job.Status.AnalyzersSuccessful { | ||
alreadyReceived := false | ||
for _, receivedPreflight := range receivedPreflights { | ||
if receivedPreflight == readyPreflight { | ||
alreadyReceived = true | ||
} | ||
} | ||
|
||
if alreadyReceived { | ||
continue | ||
} | ||
|
||
preflightResp, err := http.Get(fmt.Sprintf("http://localhost:8000/preflight/%s", readyPreflight)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer preflightResp.Body.Close() | ||
body, err := ioutil.ReadAll(preflightResp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s\n", body) | ||
receivedPreflights = append(receivedPreflights, readyPreflight) | ||
} | ||
|
||
// if len(job.Status.Running) == 0 { | ||
// tarGz := archiver.TarGz{ | ||
// Tar: &archiver.Tar{ | ||
// ImplicitTopLevelFolder: false, | ||
// }, | ||
// } | ||
|
||
// paths := make([]string, 0, 0) | ||
// for _, id := range receivedCollectors { | ||
// paths = append(paths, filepath.Join(bundlePath, id)) | ||
// } | ||
|
||
// if err := tarGz.Archive(paths, "support-bundle.tar.gz"); err != nil { | ||
// return err | ||
// } | ||
// return nil | ||
// } | ||
} | ||
} |
This file contains 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