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

Request to carry more settings on S2iRun into S2i webhook #164

Open
JohnNiang opened this issue Nov 18, 2021 · 0 comments
Open

Request to carry more settings on S2iRun into S2i webhook #164

JohnNiang opened this issue Nov 18, 2021 · 0 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@JohnNiang
Copy link
Member

KubeSphere provides Source-to-Image (S2I) and Binary-to-Image (B2I) features to automate image building and pushing and application deployment. In KubeSphere v3.1, you can configure S2I and B2I webhooks so that your Image Builder can be automatically triggered when there is any relevant activity in your code repository.

References:

But it has a drawback, which we cannot trigger the webhook with payload. For example, someone want to automatically trigger the webhook but with different version every time. For example, we could pass the payload into the webhook:

curl -d '{ "builderName": "johnniang-halo-s2i-latest-ahs", "newTag": "v1.0.1" }' -H "Content-Type: application/json" -X POST http://xyz...

The type of payload could be:

type S2iRunSpec struct {
//BuilderName specify the name of s2ibuilder, required
BuilderName string `json:"builderName"`
//BackoffLimit limits the restart count of each s2irun. Default is 0
BackoffLimit int32 `json:"backoffLimit,omitempty"`
//SecondsAfterFinished if is set and greater than zero, and the job created by s2irun become successful or failed , the job will be auto deleted after SecondsAfterFinished
SecondsAfterFinished int32 `json:"secondsAfterFinished,omitempty"`
//NewTag override the default tag in its s2ibuilder, image name cannot be changed.
NewTag string `json:"newTag,omitempty"`
//NewRevisionId override the default NewRevisionId in its s2ibuilder.
NewRevisionId string `json:"newRevisionId,omitempty"`
//NewSourceURL is used to download new binary artifacts
NewSourceURL string `json:"newSourceURL,omitempty"`
}

And could obtain the payload at here:

func (g *Trigger) Serve(request *restful.Request, response *restful.Response) {
reqSecretCode := request.QueryParameter("secretCode")
g.S2iBuilderName = request.PathParameter("s2ibuilder")
g.Namespace = request.PathParameter("namespace")
// Authentication
res, err := g.Authentication(reqSecretCode)
if err != nil {
log.Error(err, "Failed to handle event")
response.WriteHeader(http.StatusInternalServerError)
return
}
if !res {
log.Error(err, "Unauthorized")
response.WriteHeader(http.StatusUnauthorized)
return
}
// create resource
err = g.Action()
if err != nil {
log.Error(err, "Failed to handle event")
response.WriteHeader(http.StatusInternalServerError)
return
}
response.WriteHeader(http.StatusCreated)
}

/kind feature
/cc @kubesphere/sig-devops

@ks-ci-bot ks-ci-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 18, 2021
@JohnNiang JohnNiang changed the title Request to carry more settings on S2iBuilder into S2i webhook Request to carry more settings on S2iRun into S2i webhook Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants