github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/pkg/fn/eval.go (about)

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package fn
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"io"
    21  
    22  	v1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
    23  )
    24  
    25  // FunctionRunner knows how to run a function.
    26  type FunctionRunner interface {
    27  	// Run method accepts resourceList in wireformat and returns resourceList in wire format.
    28  	Run(r io.Reader, w io.Writer) error
    29  }
    30  
    31  // FunctionRuntime provides a way to obtain a function runner to be used for a given function configuration.
    32  // If the function is not found, this should return an error that includes a NotFoundError in the chain.
    33  type FunctionRuntime interface {
    34  	GetRunner(ctx context.Context, fn *v1.Function) (FunctionRunner, error)
    35  }
    36  
    37  type NotFoundError struct {
    38  	Function v1.Function
    39  }
    40  
    41  func (e *NotFoundError) Error() string {
    42  	return fmt.Sprintf("function %q not found", e.Function.Image)
    43  }