Skip to content

Commit 2463202

Browse files
allowing on cluster build for go runtime (#1445)
* allowing on cluster build for go runtime * warning message added for go and rust builder * gofmt * fixups Signed-off-by: Matej Vasek <mvasek@redhat.com> --------- Signed-off-by: Matej Vasek <mvasek@redhat.com> Co-authored-by: Matej Vasek <mvasek@redhat.com>
1 parent 24fe6d3 commit 2463202

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

docs/building-functions/on_cluster_build.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ git remote add origin git@github.com:my-repo/my-function.git
3434
```
3535
4. Update the Function configuration in `func.yaml` to enable on cluster builds for the Git repository:
3636
```yaml
37-
build: git # required, specify `git` build type
38-
git:
39-
url: https://github.com/my-repo/my-function.git # required, git repository with the function source code
40-
revision: main # optional, git revision to be used (branch, tag, commit)
41-
# contextDir: myfunction # optional, needed only if the function is not located
42-
# in the repository root folder
37+
build:
38+
git:
39+
url: https://github.com/my-repo/my-function.git # required, git repository with the function source code
40+
revision: main # optional, git revision to be used (branch, tag, commit)
41+
# contextDir: myfunction # optional, needed only if the function is not located in the repository root folder
42+
# builderImages: # optional, needed only if the runtime is golang
43+
# pack: ghcr.io/boson-project/go-function-builder:tip
44+
buildpacks: []
45+
builder: ""
46+
buildEnvs: []
4347
```
4448
5. Implement the business logic of your Function, then commit and push changes
4549
```bash

pkg/pipelines/tekton/pipelines_pac_provider.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ func (pp *PipelinesProvider) ConfigurePAC(ctx context.Context, f fn.Function, me
3030
return fmt.Errorf("incorrect type of pipelines metadata: %T", metadata)
3131
}
3232

33-
if err := validatePipeline(f); err != nil {
33+
var warningMsg string
34+
var err error
35+
if warningMsg, err = validatePipeline(f); err != nil {
3436
return err
3537
}
38+
if warningMsg != "" {
39+
pp.progressListener.Increment(warningMsg)
40+
}
3641

3742
if data.ConfigureLocalResources {
3843
if err := pp.createLocalPACResources(ctx, f); err != nil {

pkg/pipelines/tekton/pipelines_provider.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ func NewPipelinesProvider(opts ...Opt) *PipelinesProvider {
118118
// After the PipelineRun is being initialized, the progress of the PipelineRun is being watched and printed to the output.
119119
func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) error {
120120
pp.progressListener.Increment("Creating Pipeline resources")
121-
122-
if err := validatePipeline(f); err != nil {
121+
var warningMsg string
122+
var err error
123+
if warningMsg, err = validatePipeline(f); err != nil {
123124
return err
124125
}
126+
if warningMsg != "" {
127+
pp.progressListener.Increment(warningMsg)
128+
}
125129

126130
client, namespace, err := NewTektonClientAndResolvedNamespace(pp.namespace)
127131
if err != nil {

pkg/pipelines/tekton/validate.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"knative.dev/func/pkg/builders"
8+
"knative.dev/func/pkg/builders/buildpacks"
89
"knative.dev/func/pkg/builders/s2i"
910
fn "knative.dev/func/pkg/functions"
1011
)
@@ -21,28 +22,36 @@ type ErrRuntimeNotSupported struct {
2122
}
2223

2324
func (e ErrRuntimeNotSupported) Error() string {
24-
return fmt.Sprintf("runtime %q is not supported for on cluster build", e.Runtime)
25+
return fmt.Sprintf("runtime %q is not supported for on cluster build with default builders", e.Runtime)
2526
}
2627

27-
func validatePipeline(f fn.Function) error {
28+
func validatePipeline(f fn.Function) (string, error) {
29+
var warningMsg string
2830
if f.Build.Builder == builders.Pack {
2931
if f.Runtime == "" {
30-
return ErrRuntimeRequired
32+
return "", ErrRuntimeRequired
3133
}
3234

3335
if f.Runtime == "go" || f.Runtime == "rust" {
34-
return ErrRuntimeNotSupported{f.Runtime}
36+
builder := f.Build.BuilderImages[builders.Pack]
37+
defaultBuilder := buildpacks.DefaultBuilderImages[f.Runtime]
38+
if builder != "" && builder != defaultBuilder {
39+
warningMsg = fmt.Sprintf("runtime %q is not supported for on cluster build with default builders, "+
40+
"continuing with the custom builder provided", f.Runtime)
41+
} else {
42+
return "", ErrRuntimeNotSupported{f.Runtime}
43+
}
3544
}
3645

3746
if len(f.Build.Buildpacks) > 0 {
38-
return ErrBuilpacksNotSupported
47+
return "", ErrBuilpacksNotSupported
3948
}
4049
} else if f.Build.Builder == builders.S2I {
4150
_, err := s2i.BuilderImage(f, builders.S2I)
42-
return err
51+
return "", err
4352
} else {
44-
return builders.ErrUnknownBuilder{Name: f.Build.Builder}
53+
return "", builders.ErrUnknownBuilder{Name: f.Build.Builder}
4554
}
4655

47-
return nil
56+
return warningMsg, nil
4857
}

pkg/pipelines/tekton/validate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Test_validatePipeline(t *testing.T) {
108108

109109
for _, tt := range tests {
110110
t.Run(tt.name, func(t *testing.T) {
111-
err := validatePipeline(tt.function)
111+
_, err := validatePipeline(tt.function)
112112
if (err != nil) != tt.wantErr {
113113
t.Errorf("validatePipeline() error = %v, wantErr %v", err, tt.wantErr)
114114
return

0 commit comments

Comments
 (0)