Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/interlink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func main() {
mutex := http.NewServeMux()
mutex.HandleFunc("/status", interLinkAPIs.StatusHandler)
mutex.HandleFunc("/create", interLinkAPIs.CreateHandler)
mutex.HandleFunc("/createPodGroup", interLinkAPIs.CreatePodGroupHandler)
mutex.HandleFunc("/delete", interLinkAPIs.DeleteHandler)
mutex.HandleFunc("/pinglink", interLinkAPIs.Ping)
mutex.HandleFunc("/getLogs", interLinkAPIs.GetLogsHandler)
Expand Down
14 changes: 14 additions & 0 deletions cmd/openapi-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ func main() {
panic(err)
}

// CREATE POD GROUP
createPodGroupOp, err := reflector.NewOperationContext(http.MethodPost, "/createPodGroup")
if err != nil {
panic(err)
}

createPodGroupOp.AddReqStructure(new(interlink.PodGroupCreateRequests))
createPodGroupOp.AddRespStructure(new([]interlink.CreateStruct), func(cu *openapi.ContentUnit) { cu.HTTPStatus = http.StatusOK })

err = reflector.AddOperation(createPodGroupOp)
if err != nil {
panic(err)
}

// DELETE
deleteOp, err := reflector.NewOperationContext(http.MethodPost, "/delete")
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions docs/docs/guides/02-develop-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ Retrieves logs from a specific container.
**Query Parameters**: Pod UID, container name, log options **Response**:
Container logs (plain text)

### POST /createPodGroup (optional)

Creates the pods of one pod group as a single job. A plugin that implements it
lists `pod-group-create` in the `capabilities` of its ping answer, and it is
used only then; status, logs and delete stay per pod.

**Request Body**: `RetrievedPodGroupData` **Response**: `List[CreateStruct]`,
one per pod in the order of the request, all with the job ID of the group

```json
{
"groupUID": "workload-uid",
"pods": [...] // each pod as sent to /create, in rank order
}
```

The order of the pods gives their ranks; rank 0 is the head. Answer 400 with a
text body for a bad request or a permanent refusal, and 503 when the group
cannot be taken now.

## Developing with the Python SDK

### Basic Plugin Structure
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi/interlink-openapi.json

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions docs/openapi/plugin-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,48 @@
}
}
},
"/createPodGroup": {
"post": {
"summary": "Create Pod Group",
"operationId": "create_pod_group_createPodGroup_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RetrievedPodGroupData"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"items": {
"$ref": "#/components/schemas/CreateStruct"
},
"type": "array",
"title": "Response Create Pod Group Createpodgroup Post"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/delete": {
"post": {
"summary": "Delete Pod",
Expand Down Expand Up @@ -984,6 +1026,27 @@
],
"title": "PodVolume"
},
"RetrievedPodGroupData": {
"properties": {
"groupUID": {
"type": "string",
"title": "Group Uid"
},
"pods": {
"items": {
"$ref": "#/components/schemas/Pod"
},
"type": "array",
"title": "Pods"
}
},
"type": "object",
"required": [
"groupUID",
"pods"
],
"title": "RetrievedPodGroupData"
},
"Secret": {
"properties": {
"metadata": {
Expand Down
29 changes: 15 additions & 14 deletions pkg/interlink/api/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,14 @@
log.G(h.Ctx).Infof("Updated JobScript successfully (len=%d)", len(data.JobScript))

case h.Config.JobScriptTemplate != "":

tmp, err := template.ParseFiles(h.Config.JobScriptTemplate)
if err != nil {
statusCode = http.StatusInternalServerError
log.G(h.Ctx).Error(err)
w.WriteHeader(statusCode)
types.SetSpanError(span, statusCode, err)
return
}

var tpl bytes.Buffer
err = tmp.Execute(&tpl, data)
data.JobScript, err = renderJobScript(h.Config.JobScriptTemplate, data)
if err != nil {
statusCode = http.StatusInternalServerError
log.G(h.Ctx).Error(err)
w.WriteHeader(statusCode)
types.SetSpanError(span, statusCode, err)
return
}

data.JobScript = tpl.String()
}

// updated to handle single data
Expand Down Expand Up @@ -199,17 +186,31 @@
return
}

log.G(h.Ctx).Info("InterLink: forwarding Create call to sidecar")

ForwardAccessToken(r, req)
_, err = ReqWithError(ctx, req, w, start, span, true, false, sessionContext, h.ClientHTTP)
if err != nil {
// ReqWithError has already marked the span as failed.
log.L.Error(err)
return
}

// The return code was already recorded by ReqWithError, so only the outcome
// is set here.
types.SetSpanOK(span, 0)
}

// renderJobScript fills the job script template at path with the data of one pod.

Check notice on line 204 in pkg/interlink/api/create.go

View workflow job for this annotation

GitHub Actions / Check duplicated code

Copy/pasted code

see pkg/interlink/api/delete.go (90-131)
func renderJobScript(path string, data types.RetrievedPodData) (string, error) {
tmp, err := template.ParseFiles(path)
if err != nil {
return "", err
}

var tpl bytes.Buffer
if err := tmp.Execute(&tpl, data); err != nil {
return "", err
}
return tpl.String(), nil
}
Loading
Loading