@@ -1045,6 +1045,115 @@ public JsonNode bindingResource(String pod, String namespace, String host) throw
10451045 return createResource (KubeUtil .toBinding (pod , namespace , host ));
10461046 }
10471047
1048+
1049+ /**
1050+ * {
1051+ "kind": "CustomResourceDefinition",
1052+ "apiVersion": "apiextensions.k8s.io/v1",
1053+ "metadata": {
1054+ "name": "virtualmachines.doslab.io",
1055+ "uid": "eac76c1c-254d-4895-b815-381755805da7",
1056+ "resourceVersion": "10577917",
1057+ "generation": 1,
1058+ "creationTimestamp": "2023-10-21T08:23:57Z",
1059+ "labels": {
1060+ "kubevirt.io": ""
1061+ },
1062+ "annotations": {
1063+ "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apiextensions.k8s.io/v1\",\"kind\":\"CustomResourceDefinition\",\"metadata\":{\"annotations\":{},\"labels\":{\"kubevirt.io\":\"\"},\"name\":\"virtualmachines.doslab.io\"},\"spec\":{\"group\":\"doslab.io\",\"names\":{\"kind\":\"VirtualMachine\",\"plural\":\"virtualmachines\",\"shortNames\":[\"vm\",\"vms\"],\"singular\":\"virtualmachine\"},\"scope\":\"Namespaced\",\"versions\":[{\"additionalPrinterColumns\":[{\"jsonPath\":\".spec.domain.uuid.text\",\"name\":\"UUID\",\"type\":\"string\"},{\"jsonPath\":\".spec.domain._type\",\"name\":\"TYPE\",\"type\":\"string\"},{\"jsonPath\":\".spec.domain.vcpu._current\",\"name\":\"CPU\",\"type\":\"string\"},{\"jsonPath\":\".spec.domain.currentMemory.text\",\"name\":\"RAM(KB)\",\"type\":\"string\"},{\"jsonPath\":\".spec.powerstate\",\"name\":\"STATUS\",\"type\":\"string\"},{\"jsonPath\":\".metadata.creationTimestamp\",\"name\":\"AGE\",\"type\":\"date\"},{\"jsonPath\":\".spec.nodeName\",\"name\":\"NODE\",\"type\":\"string\"},{\"jsonPath\":\".spec.status.conditions.state.waiting.reason\",\"name\":\"MESSAGE\",\"type\":\"string\"},{\"jsonPath\":\".spec.image\",\"name\":\"IMAGE\",\"type\":\"string\"}],\"name\":\"v1\",\"schema\":{\"openAPIV3Schema\":{\"properties\":{\"spec\":{\"type\":\"object\",\"x-kubernetes-preserve-unknown-fields\":true}},\"type\":\"object\"}},\"served\":true,\"storage\":true}]}}\n"
1064+ },
1065+ "spec": {
1066+ "group": "doslab.io",
1067+ "names": {
1068+ "plural": "virtualmachines",
1069+ "singular": "virtualmachine",
1070+ "shortNames": ["vm", "vms"],
1071+ "kind": "VirtualMachine",
1072+ "listKind": "VirtualMachineList"
1073+ },
1074+ "scope": "Namespaced",
1075+ "versions": [{
1076+ "name": "v1",
1077+ "served": true,
1078+ "storage": true,
1079+ "schema": {
1080+ "openAPIV3Schema": {
1081+ "type": "object",
1082+ "properties": {
1083+ "spec": {
1084+ "type": "object",
1085+ "x-kubernetes-preserve-unknown-fields": true
1086+ }
1087+ }
1088+ }
1089+ },
1090+ "additionalPrinterColumns": [{
1091+ "name": "UUID",
1092+ "type": "string",
1093+ "jsonPath": ".spec.domain.uuid.text"
1094+ }, {
1095+ "name": "TYPE",
1096+ "type": "string",
1097+ "jsonPath": ".spec.domain._type"
1098+ }, {
1099+ "name": "CPU",
1100+ "type": "string",
1101+ "jsonPath": ".spec.domain.vcpu._current"
1102+ }, {
1103+ "name": "RAM(KB)",
1104+ "type": "string",
1105+ "jsonPath": ".spec.domain.currentMemory.text"
1106+ }, {
1107+ "name": "STATUS",
1108+ "type": "string",
1109+ "jsonPath": ".spec.powerstate"
1110+ }, {
1111+ "name": "AGE",
1112+ "type": "date",
1113+ "jsonPath": ".metadata.creationTimestamp"
1114+ }, {
1115+ "name": "NODE",
1116+ "type": "string",
1117+ "jsonPath": ".spec.nodeName"
1118+ }, {
1119+ "name": "MESSAGE",
1120+ "type": "string",
1121+ "jsonPath": ".spec.status.conditions.state.waiting.reason"
1122+ }, {
1123+ "name": "IMAGE",
1124+ "type": "string",
1125+ "jsonPath": ".spec.image"
1126+ }]
1127+ }],
1128+ "conversion": {
1129+ "strategy": "None"
1130+ }
1131+ },
1132+ "status": {
1133+ "conditions": null,
1134+ "acceptedNames": {
1135+ "plural": "",
1136+ "kind": ""
1137+ },
1138+ "storedVersions": ["v1"]
1139+ }
1140+ }
1141+ *
1142+ * @param crd 上面就是一个CRD例子
1143+ * @return /apis/doslab.io/v1
1144+ * @throws Exception
1145+ */
1146+ public boolean registerResource (JsonNode crd ) throws Exception {
1147+ if (crd .has ("kind" ) && crd .get ("kind" ).asText ().equals ("CustomResourceDefinition" )) {
1148+ StringBuilder sb = new StringBuilder ();
1149+ sb .append ("/apis/" ).append (crd .get ("spec" ).get ("group" ).asText ()).append ("/" )
1150+ .append (crd .get ("spec" ).get ("versions" ).get (0 ).get ("name" ).asText ());
1151+ getAnalyzer ().getRegistry ().registerKinds (this , sb .toString ());
1152+ return true ;
1153+ }
1154+
1155+ throw new KubernetesInternalServerErrorException ("it is not a valid crd." );
1156+ }
10481157 /**********************************************************
10491158 *
10501159 *
0 commit comments