Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Fix error with invalid text in label
Browse files Browse the repository at this point in the history
The affected code was clearly not tested with Kubernetes where
label values are tightly constrained. This fixes the error by
putting the URL of a Git repo into an annotation.

Signed-off-by: Alex Ellis (VMware) <[email protected]>
  • Loading branch information
alexellis committed Oct 30, 2018
1 parent 97059cd commit 4eae23b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions buildshiprun/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ func Handle(req []byte) string {
sdk.FunctionLabelPrefix + "git-sha": event.SHA,
sdk.FunctionLabelPrefix + "git-private": fmt.Sprintf("%d", private),
sdk.FunctionLabelPrefix + "git-scm": event.SCM,
sdk.FunctionLabelPrefix + "git-repo-url": event.RepoURL,
"faas_function": serviceValue,
"app": serviceValue,
"com.openfaas.scale.min": scalingMinLimit,
"com.openfaas.scale.max": scalingMaxLimit,
},
Annotations: map[string]string{
sdk.FunctionLabelPrefix + "git-repo-url": event.RepoURL,
},
Limits: Limits{
Memory: defaultMemoryLimit,
},
Expand All @@ -218,19 +220,22 @@ func Handle(req []byte) string {

deployResult, err := deployFunction(deploy, gatewayURL, c)

log.Println(deployResult)

if err != nil {
status.AddStatus(sdk.StatusFailure, err.Error(), sdk.BuildFunctionContext(event.Service))
reportStatus(status)
log.Fatal(err.Error())

auditEvent.Message = fmt.Sprintf("buildshiprun failure: %s", err.Error())
sdk.PostAudit(auditEvent)
log.Fatalf("buildshiprun failure: %s", err.Error())
} else {
auditEvent.Message = fmt.Sprintf("buildshiprun succeeded: deployed %s", imageName)
sdk.PostAudit(auditEvent)
}

log.Println(deployResult)
}

sdk.PostAudit(auditEvent)
status.AddStatus(sdk.StatusSuccess, fmt.Sprintf("deployed: %s", serviceValue), sdk.BuildFunctionContext(event.Service))
reportStatus(status)
return fmt.Sprintf("buildStatus %s %s", imageName, res.Status)
Expand Down Expand Up @@ -411,17 +416,19 @@ func deployFunction(deploy deployment, gatewayURL string, c *http.Client) (strin
res, err = c.Do(httpReq)

if err != nil {
fmt.Println(err)
log.Printf("error %s to system/functions %s", method, err)
return "", err
}

defer res.Body.Close()

fmt.Println("Deploy status: " + res.Status)
log.Printf("Deploy status [%s] - %d", method, res.StatusCode)

buildStatus, _ := ioutil.ReadAll(res.Body)

if res.StatusCode < 200 || res.StatusCode > 299 {
return "", fmt.Errorf("http status code %d", res.StatusCode)
return "", fmt.Errorf("http status code %d, error: %s", res.StatusCode, string(buildStatus))
}
buildStatus, _ := ioutil.ReadAll(res.Body)

return string(buildStatus), err
}
Expand Down Expand Up @@ -479,6 +486,7 @@ type deployment struct {
Secrets []string
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem"`
RegistryAuth string `json:"registryAuth"`
Annotations map[string]string
}

type Limits struct {
Expand Down

0 comments on commit 4eae23b

Please sign in to comment.