Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowing on cluster build for go runtime #1445

Merged
merged 5 commits into from
Jul 28, 2023
Merged
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
16 changes: 10 additions & 6 deletions docs/building-functions/on_cluster_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ git remote add origin git@github.com:my-repo/my-function.git
```
4. Update the Function configuration in `func.yaml` to enable on cluster builds for the Git repository:
```yaml
build: git # required, specify `git` build type
git:
url: https://github.com/my-repo/my-function.git # required, git repository with the function source code
revision: main # optional, git revision to be used (branch, tag, commit)
# contextDir: myfunction # optional, needed only if the function is not located
# in the repository root folder
build:
git:
url: https://github.com/my-repo/my-function.git # required, git repository with the function source code
revision: main # optional, git revision to be used (branch, tag, commit)
# contextDir: myfunction # optional, needed only if the function is not located in the repository root folder
# builderImages: # optional, needed only if the runtime is golang
# pack: ghcr.io/boson-project/go-function-builder:tip
buildpacks: []
builder: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builder should be "pack".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but empty string probably would work too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these two items are intended as hints, commenting them would probably be best.

The idea here is that the code has static defaults. Anything placed in the config file is specifically requesting that exact value, so while the first value, []buildpacks is innocuous, the second, builder="" is, if literally translated, requesting the system to build without a builder. In this case we do set the default if the value comes in empty like this, because building without a builder is nonsensical, but I presume this exists to give a hint to the user how to choose a builder and buildpacks, so a commented entry is the right tool for the job.

buildEnvs: []
```
5. Implement the business logic of your Function, then commit and push changes
```bash
Expand Down
7 changes: 6 additions & 1 deletion pkg/pipelines/tekton/pipelines_pac_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ func (pp *PipelinesProvider) ConfigurePAC(ctx context.Context, f fn.Function, me
return fmt.Errorf("incorrect type of pipelines metadata: %T", metadata)
}

if err := validatePipeline(f); err != nil {
var warningMsg string
var err error
if warningMsg, err = validatePipeline(f); err != nil {
return err
}
if warningMsg != "" {
pp.progressListener.Increment(warningMsg)
}

if data.ConfigureLocalResources {
if err := pp.createLocalPACResources(ctx, f); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/pipelines/tekton/pipelines_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ func NewPipelinesProvider(opts ...Opt) *PipelinesProvider {
// After the PipelineRun is being initialized, the progress of the PipelineRun is being watched and printed to the output.
func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) error {
pp.progressListener.Increment("Creating Pipeline resources")

if err := validatePipeline(f); err != nil {
var warningMsg string
var err error
if warningMsg, err = validatePipeline(f); err != nil {
return err
}
if warningMsg != "" {
pp.progressListener.Increment(warningMsg)
}

client, namespace, err := NewTektonClientAndResolvedNamespace(pp.namespace)
if err != nil {
Expand Down
25 changes: 17 additions & 8 deletions pkg/pipelines/tekton/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"knative.dev/func/pkg/builders"
"knative.dev/func/pkg/builders/buildpacks"
"knative.dev/func/pkg/builders/s2i"
fn "knative.dev/func/pkg/functions"
)
Expand All @@ -21,28 +22,36 @@ type ErrRuntimeNotSupported struct {
}

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

func validatePipeline(f fn.Function) error {
func validatePipeline(f fn.Function) (string, error) {
var warningMsg string
if f.Build.Builder == builders.Pack {
if f.Runtime == "" {
return ErrRuntimeRequired
return "", ErrRuntimeRequired
}

if f.Runtime == "go" || f.Runtime == "rust" {
return ErrRuntimeNotSupported{f.Runtime}
builder := f.Build.BuilderImages[builders.Pack]
defaultBuilder := buildpacks.DefaultBuilderImages[f.Runtime]
if builder != "" && builder != defaultBuilder {
warningMsg = fmt.Sprintf("runtime %q is not supported for on cluster build with default builders, "+
"continuing with the custom builder provided", f.Runtime)
} else {
return "", ErrRuntimeNotSupported{f.Runtime}
}
}

if len(f.Build.Buildpacks) > 0 {
return ErrBuilpacksNotSupported
return "", ErrBuilpacksNotSupported
}
} else if f.Build.Builder == builders.S2I {
_, err := s2i.BuilderImage(f, builders.S2I)
return err
return "", err
} else {
return builders.ErrUnknownBuilder{Name: f.Build.Builder}
return "", builders.ErrUnknownBuilder{Name: f.Build.Builder}
}

return nil
return warningMsg, nil
}
2 changes: 1 addition & 1 deletion pkg/pipelines/tekton/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Test_validatePipeline(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validatePipeline(tt.function)
_, err := validatePipeline(tt.function)
if (err != nil) != tt.wantErr {
t.Errorf("validatePipeline() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
Loading