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

add support to git functions for buildless serverless #1452

Merged
merged 15 commits into from
Feb 20, 2025
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
49 changes: 47 additions & 2 deletions components/buildless-serverless/api/v1alpha2/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type FunctionSpec struct {
RuntimeImageOverride string `json:"runtimeImageOverride,omitempty"`

// Contains the Function's source code configuration.
/* // +kubebuilder:validation:XValidation:message="Use GitRepository or Inline source",rule="has(self.gitRepository) && !has(self.inline) || !has(self.gitRepository) && has(self.inline)" */
// +kubebuilder:validation:XValidation:message="Use GitRepository or Inline source",rule="has(self.gitRepository) && !has(self.inline) || !has(self.gitRepository) && has(self.inline)"
// +kubebuilder:validation:Required
Source Source `json:"source"`

Expand Down Expand Up @@ -78,7 +78,7 @@ type FunctionSpec struct {
type Source struct {
// Defines the Function as git-sourced. Can't be used together with **Inline**.
// +optional
// GitRepository *GitRepositorySource `json:"gitRepository,omitempty"`
GitRepository *GitRepositorySource `json:"gitRepository,omitempty"`

// Defines the Function as the inline Function. Can't be used together with **GitRepository**.
// +optional
Expand All @@ -96,6 +96,33 @@ type InlineSource struct {
Dependencies string `json:"dependencies,omitempty"`
}

type GitRepositorySource struct {
// +kubebuilder:validation:Required

// Specifies the URL of the Git repository with the Function's code and dependencies.
// Depending on whether the repository is public or private and what authentication method is used to access it,
// the URL must start with the `http(s)`, `git`, or `ssh` prefix.
URL string `json:"url"`

// // Specifies the authentication method. Required for SSH.
// // +optional
// Auth *RepositoryAuth `json:"auth,omitempty"`

// +kubebuilder:validation:XValidation:message="BaseDir is required and cannot be empty",rule="has(self.baseDir) && (self.baseDir.trim().size() != 0)"
// +kubebuilder:validation:XValidation:message="Reference is required and cannot be empty",rule="has(self.reference) && (self.reference.trim().size() != 0)"
Repository `json:",inline"`
}

type Repository struct {
// Specifies the relative path to the Git directory that contains the source code
// from which the Function is built.
BaseDir string `json:"baseDir,omitempty"`

// Specifies either the branch name, tag or commit revision from which the Function Controller
// automatically fetches the changes in the Function's code and dependencies.
Reference string `json:"reference,omitempty"`
}

type ResourceConfiguration struct {
// Specifies resources requested by the Function's Pod.
// +optional
Expand Down Expand Up @@ -256,3 +283,21 @@ func (f *Function) PodLabels() map[string]string {
}
return labels.Merge(result, map[string]string{PodAppNameLabel: f.GetName()})
}

func (f *Function) HasGitSources() bool {
return f.Spec.Source.GitRepository != nil
}

func (f *Function) HasInlineSources() bool {
return f.Spec.Source.Inline != nil
}

func (f *Function) HasPythonRuntime() bool {
runtime := f.Spec.Runtime
return runtime == Python312
}

func (f *Function) HasNodejsRuntime() bool {
runtime := f.Spec.Runtime
return runtime == NodeJs20 || runtime == NodeJs22
}

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 @@ -300,10 +300,37 @@ spec:
type: object
type: array
source:
description: |-
Contains the Function's source code configuration.
// +kubebuilder:validation:XValidation:message="Use GitRepository or Inline source",rule="has(self.gitRepository) && !has(self.inline) || !has(self.gitRepository) && has(self.inline)"
description: Contains the Function's source code configuration.
properties:
gitRepository:
description: Defines the Function as git-sourced. Can't be used
together with **Inline**.
properties:
baseDir:
description: |-
Specifies the relative path to the Git directory that contains the source code
from which the Function is built.
type: string
reference:
description: |-
Specifies either the branch name, tag or commit revision from which the Function Controller
automatically fetches the changes in the Function's code and dependencies.
type: string
url:
description: |-
Specifies the URL of the Git repository with the Function's code and dependencies.
Depending on whether the repository is public or private and what authentication method is used to access it,
the URL must start with the `http(s)`, `git`, or `ssh` prefix.
type: string
required:
- url
type: object
x-kubernetes-validations:
- message: BaseDir is required and cannot be empty
rule: has(self.baseDir) && (self.baseDir.trim().size() != 0)
- message: Reference is required and cannot be empty
rule: has(self.reference) && (self.reference.trim().size() !=
0)
inline:
description: Defines the Function as the inline Function. Can't
be used together with **GitRepository**.
Expand All @@ -319,6 +346,10 @@ spec:
- source
type: object
type: object
x-kubernetes-validations:
- message: Use GitRepository or Inline source
rule: has(self.gitRepository) && !has(self.inline) || !has(self.gitRepository)
&& has(self.inline)
required:
- runtime
- source
Expand Down
Loading
Loading