Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PodExecOptions (as object of AdmissionReview#request) not supported? #2332

Closed
duco-lw opened this issue Jul 6, 2020 · 3 comments · Fixed by #2335
Closed

PodExecOptions (as object of AdmissionReview#request) not supported? #2332

duco-lw opened this issue Jul 6, 2020 · 3 comments · Fixed by #2335
Assignees

Comments

@duco-lw
Copy link
Contributor

duco-lw commented Jul 6, 2020

When reading JSON representing an AdmissionReview for a pod/exec request (PodExecOptions), no resource type is found.

With this code (which can be cut down to a simple test if needed):

...
// imports included for completeness
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.api.model.admission.AdmissionRequest;
import io.fabric8.kubernetes.api.model.admission.AdmissionResponseBuilder;
import io.fabric8.kubernetes.api.model.admission.AdmissionReview;
...
	@POST
	public AdmissionReview validate(String admissionReviewJSON) {
		ObjectMapper objectMapper = new ObjectMapper();
		final AdmissionReview admissionReview;
		try {
			// have to use this approach as passing parameter of type AdmissionReview doesn't work
			admissionReview = objectMapper.readValue(admissionReviewJSON, AdmissionReview.class);
		} catch (JsonProcessingException e) {
			logger.error("Failed to parse AdmissionReview", e);
			return null;
		}

		admissionReview.setResponse(new AdmissionResponseBuilder()
				.withUid(admissionRequest.getUid())
				.withAllowed(true) // TODO: check
				.build());
		return admissionReview;
	}

The JSON passed in is:

{
   "kind":"AdmissionReview",
   "apiVersion":"admission.k8s.io/v1",
   "request":{
      "uid":"b7a46c3d-a6c8-4f57-b616-27d839f4e210",
      "kind":{
         "group":"",
         "version":"v1",
         "kind":"PodExecOptions"
      },
      "resource":{
         "group":"",
         "version":"v1",
         "resource":"pods"
      },
      "subResource":"exec",
      "requestKind":{
         "group":"",
         "version":"v1",
         "kind":"PodExecOptions"
      },
      "requestResource":{
         "group":"",
         "version":"v1",
         "resource":"pods"
      },
      "requestSubResource":"exec",
      "name":"dummy-599f7fdbdc-22gmf",
      "namespace":"test123",
      "operation":"CONNECT",
      "userInfo":{
         "username":"admin",
         "uid":"admin",
         "groups":[
            "system:masters",
            "system:authenticated"
         ]
      },
      "object":{
         "kind":"PodExecOptions",
         "apiVersion":"v1",
         "stdin":true,
         "stdout":true,
         "tty":true,
         "container":"dummy",
         "command":[
            "sh",
            "-c",
            "command -v bash \u003e/dev/null \u0026\u0026 exec bash || exec sh"
         ]
      },
      "oldObject":null,
      "dryRun":false,
      "options":null
   }
}

I get the following error:
Failed to parse AdmissionReview: com.fasterxml.jackson.databind.JsonMappingException: No resource type found for:v1#PodExecOptions

What is the expected approach here?
Is it simply that the model is missing and might ship with a new release in future?
Or am I missing something? (If so, what?)

@rohanKanojia
Copy link
Member

ah, looks like Fabric8 Kubernetes Model doesn't contain PodExecOptions object. We should add it.

@rohanKanojia
Copy link
Member

@duco-lw: Would it be possible for you to submit a Pull Request for this one? Implementing it should not be that hard. Just need to add an entry here:

ListOptions metav1.ListOptions
DeleteOptions metav1.DeleteOptions
CreateOptions metav1.CreateOptions
UpdateOptions metav1.UpdateOptions
GetOptions metav1.GetOptions
PatchOptions metav1.PatchOptions
Time metav1.Time
MicroTime metav1.MicroTime
RootPaths metav1.RootPaths
GroupVersionKind metav1.GroupVersionKind
GroupVersionResource metav1.GroupVersionResource
Quantity resource.Quantity
PodList kapi.PodList
PodTemplateList kapi.PodTemplateList
ReplicationControllerList kapi.ReplicationControllerList

I think PodExecOptions is in core/v1 . So you would just need to add one additional kapi.PodExecOptions there. Then you can simply issue make on top of kubernetes-model-generator/kubernetes-model-core which would modify schema.

@duco-lw
Copy link
Contributor Author

duco-lw commented Jul 7, 2020

PR #2335

@duco-lw duco-lw mentioned this issue Jul 8, 2020
11 tasks
rohanKanojia pushed a commit that referenced this issue Jul 13, 2020
Co-authored-by: Lewis Wolf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants