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

call time middleware support #2275

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

davidgamero
Copy link
Contributor

@davidgamero davidgamero commented Feb 26, 2025

regenerate to support call-time middleware from upstream work in OpenAPITools/openapi-generator#20430

this will enable the use of the middleware property of the options argument to append additional middleware to calls

in particular, we can support something like a WithHeader middleware that allows setting content type for json merge patch or even a wrapper that returns a full options type that can be passed

after unblocking the bugfix, I'll add the WithHeader middleware as an exported function returning a Middleware for ease of use

ex:

// Options type
coreApi.putPod(
  { ... },
  WithHeader('Content-Type','application/json-patch+json'), // would require some chaining/ edits to WithHeader proposed implementation
)

// Middleware array type
coreApi.putPod(
  { ... },
  {
    middleware: WithHeaderMiddleware('Content-Type','application/json-patch+json'),
    middlewareMergeStrategy: 'append'
  }
)

//WithHeaderMiddleware implements Middleware[] Interface
function WithHeaderMiddleware(key: string, value: string): Middleware[]{
	return [{
		pre: (c: RequestContext)=> {
			return new Promise<RequestContext>((resolve)=>{
				c.headers[key] = value
				resolve(c)
			}
		)},
		post: (c: ResponseContext)=> {return new Promise<ResponseContext>((resolve)=>{ resolve(c) })},
	}]
}

// Returns RequestOptions that set a header
func WithHeader(key: string, value: string opt?: RequestOptions): RequestOptions{
  return {
    ...opt,
    middleware: WithHeaderMiddleware(key, value).concat(opt.middleware),
    middlewareMergeStrategy: 'append' // preserve chained middleware from opt
  }
}

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: davidgamero

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 26, 2025
@davidgamero
Copy link
Contributor Author

waiting on OpenAPITools/openapi-generator#20745 to fix

@brendandburns
Copy link
Contributor

Looks like CI/CD is failing, seems like some error about node 16 or some such, do we need to update our Github action?

@davidgamero
Copy link
Contributor Author

The ci errors are related to file extensions in the generated files.

I have a PR open upstream to fix it and can re generate once it merges

I'll try updating node on the actions if that fix doesn't resolve it

Copy link

linux-foundation-easycla bot commented Feb 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 27, 2025
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is a problem in the CI, and the bot does not recognize the most recent commit. Also, is it possible to add any unit tests?

@davidgamero
Copy link
Contributor Author

It looks like there is a problem in the CI, and the bot does not recognize the most recent commit. Also, is it possible to add any unit tests?

yes i think the CI issue is this medyagh/setup-minikube#565

how do we feel about adding something like minikube tests? i was trying to add an integration test that runs the patch example against a minikube cluster

i can add unit tests too, but they'd be mostly just testing the generated codes' features

@cjihrig
Copy link
Contributor

cjihrig commented Feb 27, 2025

how do we feel about adding something like minikube tests?

Seems like a good idea to me.

@davidgamero
Copy link
Contributor Author

it appears the CLA doesn't respect force pushes, so i will have to open a new PR redoing this with all signed commits?

@cjihrig
Copy link
Contributor

cjihrig commented Feb 27, 2025

What if you squash locally and force push this branch?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 27, 2025
@davidgamero
Copy link
Contributor Author

you are right. that worked

@brendandburns
Copy link
Contributor

fwiw, we have KIND based e2e in the Java repo here:

https://github.com/kubernetes-client/java/blob/master/.github/workflows/maven.yml#L66

If you want to add equivalent e2e for this client that would be awesome.

@cjihrig
Copy link
Contributor

cjihrig commented Feb 28, 2025

Maybe we should move the E2E tests to a separate PR and get this merged.

@davidgamero
Copy link
Contributor Author

fwiw, we have KIND based e2e in the Java repo here:

https://github.com/kubernetes-client/java/blob/master/.github/workflows/maven.yml#L66

If you want to add equivalent e2e for this client that would be awesome.

i'll use kind then to keep it similar.

Maybe we should move the E2E tests to a separate PR and get this merged.

agreed i'll remove the gh action changes

@davidgamero
Copy link
Contributor Author

i've added unit tests covering the two header-setting middleware utility functions for now, and will focus on e2e in a separate PR later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants