@@ -38,7 +38,7 @@ public static JsonNode toBinding(String podName, String podNamespace, String hos
3838
3939 ObjectNode binding = new ObjectMapper ().createObjectNode ();
4040 binding .put (KubernetesConstants .KUBE_APIVERSION , KubernetesConstants .DEFAULT_APIVERSION );
41- binding .put (KubernetesConstants .KUBE_KIND , KubernetesConstants .BINDING_KIND );
41+ binding .put (KubernetesConstants .KUBE_KIND , KubernetesConstants .KUBD_KIND_BINDING );
4242
4343 ObjectNode metadata = new ObjectMapper ().createObjectNode ();
4444 metadata .put (KubernetesConstants .KUBE_METADATA_NAME , podName );
@@ -54,6 +54,68 @@ public static JsonNode toBinding(String podName, String podNamespace, String hos
5454 return binding ;
5555 }
5656
57+ /**
58+ * json必须符合Kubernetes的CRD规范,这里不考虑异常情况
59+ * https://kubernetes.io/docs/concepts/overview/working-with-objects/
60+ *
61+ * @param crd Kubernetes的CRD
62+ * @return 其中一个APIVERSION
63+ */
64+ public static String getCrdApiversion (JsonNode crd ) {
65+ String group = crd .get (KubernetesConstants .KUBE_SPEC )
66+ .get (KubernetesConstants .KUBE_SPEC_GROUP )
67+ .asText ();
68+ String version = crd .get (KubernetesConstants .KUBE_SPEC )
69+ .get (KubernetesConstants .KUBE_SPEC_VERSIONS )
70+ .get (0 )
71+ .get (KubernetesConstants .KUBE_SPEC_VERSIONS_NAME )
72+ .asText ();
73+
74+ return group + KubernetesConstants .KUBE_VALUE_SPLIT + version ;
75+ }
76+
77+ /**
78+ * json必须符合Kubernetes的CRD规范,这里不考虑异常情况
79+ * https://kubernetes.io/docs/concepts/overview/working-with-objects/
80+ *
81+ * @param crd Kubernetes的CRD
82+ * @return kind
83+ */
84+ public static String getCrdKind (JsonNode crd ) {
85+ return crd .get (KubernetesConstants .KUBE_SPEC )
86+ .get (KubernetesConstants .KUBE_SPEC_NAMES )
87+ .get (KubernetesConstants .KUBE_SPEC_NAMES_KIND )
88+ .asText ();
89+ }
90+
91+ /**
92+ * json必须符合Kubernetes的CRD规范,这里不考虑异常情况
93+ * https://kubernetes.io/docs/concepts/overview/working-with-objects/
94+ *
95+ * @param crd Kubernetes的CRD
96+ * @return kind
97+ */
98+ public static String getCrdPlural (JsonNode crd ) {
99+ return crd .get (KubernetesConstants .KUBE_SPEC )
100+ .get (KubernetesConstants .KUBE_SPEC_NAMES )
101+ .get (KubernetesConstants .KUBE_SPEC_NAMES_PLURAL )
102+ .asText ();
103+ }
104+
105+ /**
106+ * json必须符合Kubernetes规范,这里不考虑异常情况
107+ * https://kubernetes.io/docs/concepts/overview/working-with-objects/
108+ *
109+ * @param json Kubernetes对应kind的apiVersion
110+ * @return fullkind
111+ */
112+ public static String getFullkind (JsonNode json ) {
113+ String group = getGroup (json );
114+ String kind = getKind (json );
115+ return group .length () == 0 ? kind : group +
116+ KubernetesConstants .KUBE_VALUE_SPLIT + kind ;
117+ }
118+
57119 /**
58120 * 不考虑apiVersion为空或者不符合Kuberneres资源定义的的情况
59121 * 否则抛出异常
@@ -80,6 +142,19 @@ public static String getName(JsonNode json) {
80142 return json .get (KubernetesConstants .KUBE_METADATA ).get (KubernetesConstants .KUBE_METADATA_NAME ).asText ();
81143 }
82144
145+
146+ /**
147+ * 不考虑json为空或者不符合Kuberneres资源定义的的情况
148+ * 否则抛出异常
149+ * https://kubernetes.io/docs/concepts/overview/working-with-objects/
150+ *
151+ * @param json json
152+ * @return 获得kubernetes的kind
153+ */
154+ public static String getKind (JsonNode json ) {
155+ return json .get (KubernetesConstants .KUBE_KIND ).asText ();
156+ }
157+
83158 /**
84159 * 不考虑json为空或者不符合Kuberneres资源定义的的情况
85160 * 否则抛出异常
0 commit comments