...
1
16
17 package apps
18
19 import (
20 "fmt"
21
22 "k8s.io/apimachinery/pkg/runtime/schema"
23 )
24
25
26
27 type KindVisitor interface {
28 VisitDaemonSet(kind GroupKindElement)
29 VisitDeployment(kind GroupKindElement)
30 VisitJob(kind GroupKindElement)
31 VisitPod(kind GroupKindElement)
32 VisitReplicaSet(kind GroupKindElement)
33 VisitReplicationController(kind GroupKindElement)
34 VisitStatefulSet(kind GroupKindElement)
35 VisitCronJob(kind GroupKindElement)
36 }
37
38
39 type GroupKindElement schema.GroupKind
40
41
42 func (elem GroupKindElement) Accept(visitor KindVisitor) error {
43 switch {
44 case elem.GroupMatch("apps", "extensions") && elem.Kind == "DaemonSet":
45 visitor.VisitDaemonSet(elem)
46 case elem.GroupMatch("apps", "extensions") && elem.Kind == "Deployment":
47 visitor.VisitDeployment(elem)
48 case elem.GroupMatch("batch") && elem.Kind == "Job":
49 visitor.VisitJob(elem)
50 case elem.GroupMatch("", "core") && elem.Kind == "Pod":
51 visitor.VisitPod(elem)
52 case elem.GroupMatch("apps", "extensions") && elem.Kind == "ReplicaSet":
53 visitor.VisitReplicaSet(elem)
54 case elem.GroupMatch("", "core") && elem.Kind == "ReplicationController":
55 visitor.VisitReplicationController(elem)
56 case elem.GroupMatch("apps") && elem.Kind == "StatefulSet":
57 visitor.VisitStatefulSet(elem)
58 case elem.GroupMatch("batch") && elem.Kind == "CronJob":
59 visitor.VisitCronJob(elem)
60 default:
61 return fmt.Errorf("no visitor method exists for %v", elem)
62 }
63 return nil
64 }
65
66
67
68 func (elem GroupKindElement) GroupMatch(groups ...string) bool {
69 for _, g := range groups {
70 if elem.Group == g {
71 return true
72 }
73 }
74 return false
75 }
76
View as plain text