testing: Remove use of deprecated ComponentStatusList API

pull/9058/head
Thomas Stromberg 2020-08-21 16:07:39 -07:00
parent 02c7d0480c
commit 4e56db1874
1 changed files with 23 additions and 9 deletions

View File

@ -311,26 +311,40 @@ func validateMinikubeKubectl(ctx context.Context, t *testing.T, profile string)
func validateComponentHealth(ctx context.Context, t *testing.T, profile string) { func validateComponentHealth(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile) defer PostMortemLogs(t, profile)
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "cs", "-o=json")) // The ComponentStatus API is deprecated in v1.19, so do the next closest thing.
found := map[string]bool{
"etcd": false,
"kube-apiserver": false,
"kube-controller-manager": false,
"kube-scheduler": false,
}
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "po", "-l", "tier=control-plane", "-n", "kube-system", "-o=json"))
if err != nil { if err != nil {
t.Fatalf("failed to get components. args %q: %v", rr.Command(), err) t.Fatalf("failed to get components. args %q: %v", rr.Command(), err)
} }
cs := api.ComponentStatusList{} cs := api.PodList{}
d := json.NewDecoder(bytes.NewReader(rr.Stdout.Bytes())) d := json.NewDecoder(bytes.NewReader(rr.Stdout.Bytes()))
if err := d.Decode(&cs); err != nil { if err := d.Decode(&cs); err != nil {
t.Fatalf("failed to decode kubectl json output: args %q : %v", rr.Command(), err) t.Fatalf("failed to decode kubectl json output: args %q : %v", rr.Command(), err)
} }
for _, i := range cs.Items { for _, i := range cs.Items {
status := api.ConditionFalse for _, l := range i.Labels {
for _, c := range i.Conditions { t.Logf("%s phase: %s", l, i.Status.Phase)
if c.Type != api.ComponentHealthy { _, ok := found[l]
continue if ok {
found[l] = true
if i.Status.Phase != "Running" {
t.Errorf("%s is not Running: %+v", l, i.Status)
} }
status = c.Status
} }
if status != api.ConditionTrue { }
t.Errorf("unexpected status: %v - item: %+v", status, i) }
for k, v := range found {
if !v {
t.Errorf("expected component %q was not found", k)
} }
} }
} }