Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vaidikcode committed Oct 29, 2024
1 parent 59525f2 commit d0b2232
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public static Object loadAndSubmitResource(Reader content) throws Exception {
// Getting the strongly typed class from ModelMapper
Class<?> modelClass = ModelMapper.getApiTypeClass(group, version, kind);

// **Change**: Add check for the list type of the resource.
Class<?> modelListClass = ModelMapper.getApiTypeClass(group, version, kind + "List");

// Validate model class
if (modelClass == null) {
throw new IllegalArgumentException("Could not determine model class for group: "
Expand All @@ -142,7 +145,7 @@ public static Object loadAndSubmitResource(Reader content) throws Exception {
KubernetesObject typedObject = (KubernetesObject) Yaml.loadAs(content, modelClass);

// Submit the resource to Kubernetes API
return submitResourceToApi(typedObject, (Class<KubernetesObject>) modelClass, group, version, resourcePlural);
return submitResourceToApi(typedObject, (Class<KubernetesObject>) modelClass, group, version, resourcePlural, modelListClass);
} else {
throw new IllegalArgumentException("Invalid resource kind: " + kind);
}
Expand All @@ -156,6 +159,7 @@ public static Object loadAndSubmitResource(Reader content) throws Exception {
* @param group The API group of the resource
* @param version The API version of the resource
* @param resourcePlural The plural form of the resource
* @param apiListTypeClass The class type for the list of the resource
* @return The created resource object from the API response
* @throws Exception If there is an error in submitting the resource
*/
Expand All @@ -164,17 +168,15 @@ public static <ApiType extends KubernetesObject> Object submitResourceToApi(
Class<ApiType> apiTypeClass,
String group,
String version,
String resourcePlural) throws Exception {
String resourcePlural,
Class<?> apiListTypeClass) throws Exception { // **Change**: Added apiListTypeClass

// Creating an API client and configuring it
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);

// Using the apiTypeClass and apiListTypeClass for list of resources
Class<?> apiListTypeClass = ModelMapper.getApiTypeClass(group, version, resourcePlural);

// Configuring the GenericKubernetesApi handler
GenericKubernetesApi<ApiType, ?> genericApi = new GenericKubernetesApi<>(
// Configuring the GenericKubernetesApi handler with explicit list type
GenericKubernetesApi<ApiType, KubernetesListObject> genericApi = new GenericKubernetesApi<>(
apiTypeClass,
apiListTypeClass,
group,
Expand All @@ -194,4 +196,5 @@ public static <ApiType extends KubernetesObject> Object submitResourceToApi(
// Return the created resource
return apiResponse.getObject();
}

}

0 comments on commit d0b2232

Please sign in to comment.