-
Notifications
You must be signed in to change notification settings - Fork 61
Description
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:
- https://v3-1.docs.kubesphere.io/docs/project-user-guide/image-builder/s2i-and-b2i-webhooks/
- ✨Webhook support #6 (comment)
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:
s2ioperator/pkg/apis/devops/v1alpha1/s2irun_types.go
Lines 33 to 46 in 56f9327
| 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:
s2ioperator/pkg/handler/general/general_webhook.go
Lines 30 to 58 in 56f9327
| 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