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

Rename the Input type to GoTemplate #15

Merged
merged 1 commit into from
Nov 3, 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
2 changes: 1 addition & 1 deletion fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ

rsp := response.To(req, response.DefaultTTL)

in := &v1beta1.Input{}
in := &v1beta1.GoTemplate{}
if err := request.GetInput(req, in); err != nil {
response.Fatal(rsp, errors.Wrapf(err, "cannot get Function input from %T", req))
return rsp, nil
Expand Down
54 changes: 27 additions & 27 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: "wrong",
}),
},
Expand Down Expand Up @@ -99,9 +99,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdMissingResourceName},
Inline: &v1beta1.TemplateSourceInline{Template: cdMissingResourceName},
}),
},
},
Expand All @@ -122,9 +122,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdMissingKind},
Inline: &v1beta1.TemplateSourceInline{Template: cdMissingKind},
}),
},
},
Expand All @@ -145,9 +145,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdWrongTmpl},
Inline: &v1beta1.TemplateSourceInline{Template: cdWrongTmpl},
},
),
Observed: &fnv1beta1.State{
Expand Down Expand Up @@ -185,9 +185,9 @@ func TestRunFunction(t *testing.T) {
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "nochange"},
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cd},
Inline: &v1beta1.TemplateSourceInline{Template: cd},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -228,9 +228,9 @@ func TestRunFunction(t *testing.T) {
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "templates"},
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdTmpl},
Inline: &v1beta1.TemplateSourceInline{Template: cdTmpl},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -266,9 +266,9 @@ func TestRunFunction(t *testing.T) {
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "status"},
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: xrWithStatus},
Inline: &v1beta1.TemplateSourceInline{Template: xrWithStatus},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -299,9 +299,9 @@ func TestRunFunction(t *testing.T) {
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "status"},
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: xrWithNestedStatusBaz},
Inline: &v1beta1.TemplateSourceInline{Template: xrWithNestedStatusBaz},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -332,9 +332,9 @@ func TestRunFunction(t *testing.T) {
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "templates"},
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.FileSystemSource,
FileSystem: &v1beta1.InputSourceFileSystem{DirPath: path},
FileSystem: &v1beta1.TemplateSourceFileSystem{DirPath: path},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -369,9 +369,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.FileSystemSource,
FileSystem: &v1beta1.InputSourceFileSystem{DirPath: wrongPath},
FileSystem: &v1beta1.TemplateSourceFileSystem{DirPath: wrongPath},
},
),
},
Expand All @@ -393,9 +393,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdWithReadyWrong},
Inline: &v1beta1.TemplateSourceInline{Template: cdWithReadyWrong},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -431,9 +431,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: cdWithReadyTrue},
Inline: &v1beta1.TemplateSourceInline{Template: cdWithReadyTrue},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -474,9 +474,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: metaResourceInvalid},
Inline: &v1beta1.TemplateSourceInline{Template: metaResourceInvalid},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down Expand Up @@ -512,9 +512,9 @@ func TestRunFunction(t *testing.T) {
args: args{
req: &fnv1beta1.RunFunctionRequest{
Input: resource.MustStructObject(
&v1beta1.Input{
&v1beta1.GoTemplate{
Source: v1beta1.InlineSource,
Inline: &v1beta1.InputSourceInline{Template: metaResourceConDet},
Inline: &v1beta1.TemplateSourceInline{Template: metaResourceConDet},
}),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Expand Down
20 changes: 10 additions & 10 deletions input/v1beta1/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ import (
// This isn't a custom resource, in the sense that we never install its CRD.
// It is a KRM-like object, so we generate a CRD to describe its schema.

// Input is used to provide templates to this Function.
// A GoTemplate is used to provide templates to this Function.
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:categories=crossplane
type Input struct {
type GoTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Source specifies the different types of input sources that can be used with this function
Source InputSource `json:"source"`
Source TemplateSource `json:"source"`
// Inline is the inline form input of the templates
Inline *InputSourceInline `json:"inline,omitempty"`
Inline *TemplateSourceInline `json:"inline,omitempty"`
// FileSystem is the folder path where the templates are located
FileSystem *InputSourceFileSystem `json:"fileSystem,omitempty"`
FileSystem *TemplateSourceFileSystem `json:"fileSystem,omitempty"`
}

type InputSource string
type TemplateSource string

const (
// InlineSource indicates that function will get its input as inline
InlineSource InputSource = "Inline"
InlineSource TemplateSource = "Inline"

// FileSystemSource indicates that function will get its input from a folder
FileSystemSource InputSource = "FileSystem"
FileSystemSource TemplateSource = "FileSystem"
)

type InputSourceInline struct {
type TemplateSourceInline struct {
Template string `json:"template,omitempty"`
}

type InputSourceFileSystem struct {
type TemplateSourceFileSystem struct {
DirPath string `json:"dirPath,omitempty"`
}
30 changes: 15 additions & 15 deletions input/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: inputs.gotemplating.fn.crossplane.io
name: gotemplates.gotemplating.fn.crossplane.io
spec:
group: gotemplating.fn.crossplane.io
names:
categories:
- crossplane
kind: Input
listKind: InputList
plural: inputs
singular: input
kind: GoTemplate
listKind: GoTemplateList
plural: gotemplates
singular: gotemplate
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: Input is used to provide templates to this Function.
description: A GoTemplate is used to provide templates to this Function.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down
6 changes: 3 additions & 3 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TemplateGetter interface {
}

// NewTemplateSourceGetter returns a TemplateGetter based on the cd source
func NewTemplateSourceGetter(in *v1beta1.Input) (TemplateGetter, error) {
func NewTemplateSourceGetter(in *v1beta1.GoTemplate) (TemplateGetter, error) {
switch in.Source {
case v1beta1.InlineSource:
return newInlineSource(in)
Expand Down Expand Up @@ -47,7 +47,7 @@ func (is *InlineSource) GetTemplates() string {
return is.Template
}

func newInlineSource(in *v1beta1.Input) (*InlineSource, error) {
func newInlineSource(in *v1beta1.GoTemplate) (*InlineSource, error) {
return &InlineSource{
Template: in.Inline.Template,
}, nil
Expand All @@ -58,7 +58,7 @@ func (fs *FileSource) GetTemplates() string {
return fs.Template
}

func newFileSource(in *v1beta1.Input) (*FileSource, error) {
func newFileSource(in *v1beta1.GoTemplate) (*FileSource, error) {
d := in.FileSystem.DirPath

tmpl, err := readTemplates(d)
Expand Down