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 commit and repository to status in buildless #1480

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,12 @@ type FunctionStatus struct {
FunctionResourceProfile string `json:"functionResourceProfile,omitempty"`
// Specifies an array of conditions describing the status of the parser.
Conditions []metav1.Condition `json:"conditions,omitempty"`

// TODO: add Commit field with github support
// Specifies the commit hash used to build the Function.
// Commit string `json:"commit,omitempty"`
// TODO: add Repository field with github support
Commit string `json:"commit,omitempty"`
// Specify the repository which was used to build the function.
// Repository `json:",inline,omitempty"`
Repository `json:",inline,omitempty"`

//TODO Should we add the GitRepository URL here?
}

type ConditionType string
Expand Down

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 @@ -357,6 +357,14 @@ spec:
status:
description: FunctionStatus defines the observed state of Function.
properties:
baseDir:
description: |-
Specifies the relative path to the Git directory that contains the source code
from which the Function is built.
type: string
commit:
description: Specifies the commit hash used to build the Function.
type: string
conditions:
description: Specifies an array of conditions describing the status
of the parser.
Expand Down Expand Up @@ -422,6 +430,11 @@ spec:
description: Specifies the Pod selector used to match Pods in the
Function's Deployment.
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
replicas:
description: Specifies the total number of non-terminated Pods targeted
by this Function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ func sFnAdjustStatus(_ context.Context, m *fsm.StateMachine) (fsm.StateFn, *ctrl
s.PodSelector = selector.String()

s.FunctionResourceProfile = getUsedResourceFunctionPreset(m.State.Function.Spec.ResourceConfiguration, m.FunctionConfig)

if m.State.Function.HasGitSources() {
s.Repository.BaseDir = m.State.Function.Spec.Source.GitRepository.BaseDir
s.Repository.Reference = m.State.Function.Spec.Source.GitRepository.Reference
s.Commit = m.State.Commit
} else {
s.Repository = serverlessv1alpha2.Repository{}
s.Commit = ""
}

//TODO: Add more status fields
return requeueAfter(m.FunctionConfig.FunctionReadyRequeueDuration)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func Test_sFnAdjustStatus(t *testing.T) {
t.Run("status is set and requeue after long time from config", func(t *testing.T) {
t.Run("status is set and requeue after long time from config for inline function", func(t *testing.T) {
// Arrange
// machine with our function and previously created/calculated deployment
f := serverlessv1alpha2.Function{
Expand Down Expand Up @@ -61,8 +61,73 @@ func Test_sFnAdjustStatus(t *testing.T) {
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/function-name=keen-meitner")
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/managed-by=function-controller")
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/resource=deployment")
// should be empty beacuse it is inline function
require.Contains(t, m.State.Function.Status.Repository.BaseDir, "")
require.Contains(t, m.State.Function.Status.Repository.Reference, "")
require.Contains(t, m.State.Function.Status.Commit, "")
// UUID is unset because it is fake object
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/uuid=")
require.Equal(t, "charming-dubinsky", m.State.Function.Status.FunctionResourceProfile)
})
t.Run("status is set and requeue after long time from config for git function", func(t *testing.T) {
// Arrange
// machine with our function and previously created/calculated deployment
f := serverlessv1alpha2.Function{
ObjectMeta: v1.ObjectMeta{
Name: "keen-meitner"},
Spec: serverlessv1alpha2.FunctionSpec{
Runtime: "practical-panini",
RuntimeImageOverride: "zen-wu",
Source: serverlessv1alpha2.Source{
GitRepository: &serverlessv1alpha2.GitRepositorySource{
URL: "test-url",
Repository: serverlessv1alpha2.Repository{
BaseDir: "test-base-dir",
Reference: "test-reference",
},
}}},
Status: serverlessv1alpha2.FunctionStatus{}}
fc := config.FunctionConfig{
FunctionReadyRequeueDuration: 3546,
ResourceConfig: config.ResourceConfig{
Function: config.FunctionResourceConfig{
Resources: config.Resources{
DefaultPreset: "charming-dubinsky"}}}}
m := fsm.StateMachine{
State: fsm.SystemState{
Function: f,
Commit: "test-commit",
BuiltDeployment: resources.NewDeployment(&f, &fc, "test-commit"),
ClusterDeployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
Replicas: int32(686)}}},
FunctionConfig: fc,
}

// Act
next, result, err := sFnAdjustStatus(context.Background(), &m)

// Assert
// no errors
require.Nil(t, err)
// we expect stop and requeue
require.NotNil(t, result)
require.Equal(t, ctrl.Result{RequeueAfter: 3546}, *result)
// no next state (we will stop)
require.Nil(t, next)
// function should have status image from deployment
require.Equal(t, serverlessv1alpha2.Runtime("practical-panini"), m.State.Function.Status.Runtime)
require.Equal(t, "zen-wu", m.State.Function.Status.RuntimeImage)
require.Equal(t, int32(686), m.State.Function.Status.Replicas)
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/function-name=keen-meitner")
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/managed-by=function-controller")
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/resource=deployment")
// UUID is unset because it is fake object
require.Contains(t, m.State.Function.Status.PodSelector, "serverless.kyma-project.io/uuid=")
// function should have commit from git, url and reference in status
require.Contains(t, m.State.Function.Status.Repository.BaseDir, "test-base-dir")
require.Contains(t, m.State.Function.Status.Repository.Reference, "test-reference")
require.Contains(t, m.State.Function.Status.Commit, "test-commit")
require.Equal(t, "charming-dubinsky", m.State.Function.Status.FunctionResourceProfile)
})
}
13 changes: 13 additions & 0 deletions config/buildless-serverless/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ spec:
status:
description: FunctionStatus defines the observed state of Function.
properties:
baseDir:
description: |-
Specifies the relative path to the Git directory that contains the source code
from which the Function is built.
type: string
commit:
description: Specifies the commit hash used to build the Function.
type: string
conditions:
description: Specifies an array of conditions describing the status
of the parser.
Expand Down Expand Up @@ -421,6 +429,11 @@ spec:
description: Specifies the Pod selector used to match Pods in the
Function's Deployment.
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
replicas:
description: Specifies the total number of non-terminated Pods targeted
by this Function.
Expand Down
Loading