Skip to content

Commit

Permalink
warning message added for go and rust builder
Browse files Browse the repository at this point in the history
  • Loading branch information
IPC3 committed Jul 20, 2023
1 parent 57a4b6a commit 63a2a55
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
8 changes: 7 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 Expand Up @@ -240,3 +245,4 @@ func (pp *PipelinesProvider) createRemotePACResources(ctx context.Context, f fn.

return nil
}

9 changes: 7 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 Expand Up @@ -533,3 +537,4 @@ func createPipelinePersistentVolumeClaim(ctx context.Context, f fn.Function, nam
}
return nil
}

30 changes: 21 additions & 9 deletions pkg/pipelines/tekton/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,44 @@ var (
)

type ErrRuntimeNotSupported struct {
Runtime string
Runtime string
CustomBuilder bool
}

func (e ErrRuntimeNotSupported) Error() string {
return fmt.Sprintf("runtime %q is not supported for on cluster build", e.Runtime)
if e.CustomBuilder {
return fmt.Sprintf("runtime %q is not supported for on cluster build with default builders, "+
"continuing with the custom builder provided", e.Runtime)
} else {
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}
if len(f.Build.BuilderImages) > 0 {
warningMsg = ErrRuntimeNotSupported{f.Runtime, true}.Error()
} else {
return "", ErrRuntimeNotSupported{f.Runtime, false}
}
}

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
}

3 changes: 2 additions & 1 deletion pkg/pipelines/tekton/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ 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
}
})
}
}

0 comments on commit 63a2a55

Please sign in to comment.