|
1 | 1 | package generator |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "fmt" |
5 | 6 | "encoding/json" |
6 | 7 |
|
@@ -587,52 +588,55 @@ func (pg *Generator) FromPodObjString(podObjString string) (string, error) { |
587 | 588 | return "", fmt.Errorf("Could not unmarshal json document: %v", err) |
588 | 589 | } |
589 | 590 |
|
| 591 | + decoder := json.NewDecoder(bytes.NewReader(podObjJson)) |
| 592 | + decoder.DisallowUnknownFields() |
| 593 | + |
590 | 594 | switch kind := anyJson["kind"]; kind { |
591 | 595 | case "DaemonSet": |
592 | 596 | var ds appsv1.DaemonSet |
593 | | - if err = json.Unmarshal(podObjJson, &ds); err != nil { |
| 597 | + if err = decoder.Decode(&ds); err != nil { |
594 | 598 | return "", fmt.Errorf("Could not unmarshal json document as DaemonSet: %v", err) |
595 | 599 | } |
596 | 600 | return pg.fromDaemonSet(&ds) |
597 | 601 | case "Deployment": |
598 | 602 | var dep appsv1.Deployment |
599 | | - if err = json.Unmarshal(podObjJson, &dep); err != nil { |
| 603 | + if err = decoder.Decode(&dep); err != nil { |
600 | 604 | return "", fmt.Errorf("Could not unmarshal json document as Deployment: %v", err) |
601 | 605 | } |
602 | 606 | return pg.fromDeployment(&dep) |
603 | 607 | case "ReplicaSet": |
604 | 608 | var rs appsv1.ReplicaSet |
605 | | - if err = json.Unmarshal(podObjJson, &rs); err != nil { |
| 609 | + if err = decoder.Decode(&rs); err != nil { |
606 | 610 | return "", fmt.Errorf("Could not unmarshal json document as ReplicaSet: %v", err) |
607 | 611 | } |
608 | 612 | return pg.fromReplicaSet(&rs) |
609 | 613 | case "StatefulSet": |
610 | 614 | var ss appsv1.StatefulSet |
611 | | - if err = json.Unmarshal(podObjJson, &ss); err != nil { |
| 615 | + if err = decoder.Decode(&ss); err != nil { |
612 | 616 | return "", fmt.Errorf("Could not unmarshal json document as StatefulSet: %v", err) |
613 | 617 | } |
614 | 618 | return pg.fromStatefulSet(&ss) |
615 | 619 | case "ReplicationController": |
616 | 620 | var rc v1.ReplicationController |
617 | | - if err = json.Unmarshal(podObjJson, &rc); err != nil { |
| 621 | + if err = decoder.Decode(&rc); err != nil { |
618 | 622 | return "", fmt.Errorf("Could not unmarshal json document as ReplicationController: %v", err) |
619 | 623 | } |
620 | 624 | return pg.fromReplicationController(&rc) |
621 | 625 | case "CronJob": |
622 | 626 | var cj batchv1beta1.CronJob |
623 | | - if err = json.Unmarshal(podObjJson, &cj); err != nil { |
| 627 | + if err = decoder.Decode(&cj); err != nil { |
624 | 628 | return "", fmt.Errorf("Could not unmarshal json document as CronJob: %v", err) |
625 | 629 | } |
626 | 630 | return pg.fromCronJob(&cj) |
627 | 631 | case "Job": |
628 | 632 | var job batch.Job |
629 | | - if err = json.Unmarshal(podObjJson, &job); err != nil { |
| 633 | + if err = decoder.Decode(&job); err != nil { |
630 | 634 | return "", fmt.Errorf("Could not unmarshal json document as Job: %v", err) |
631 | 635 | } |
632 | 636 | return pg.fromJob(&job) |
633 | 637 | case "Pod": |
634 | 638 | var pod v1.Pod |
635 | | - if err = json.Unmarshal(podObjJson, &pod); err != nil { |
| 639 | + if err = decoder.Decode(&pod); err != nil { |
636 | 640 | return "", fmt.Errorf("Could not unmarshal json document as Pod: %v", err) |
637 | 641 | } |
638 | 642 | return pg.fromPod(&pod) |
|
0 commit comments