Skip to content

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

@JohnNiang

Description

@JohnNiang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions