Skip to content

Commit

Permalink
Add labels to buildless serverless (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKalke authored Jan 7, 2025
1 parent 2547c08 commit 3912fa1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,10 @@ func (f *Function) UpdateCondition(c ConditionType, s metav1.ConditionStatus, r
}

const (
FunctionNameLabel = "serverless.kyma-project.io/function-name"
FunctionNameLabel = "serverless.kyma-project.io/function-name"
FunctionManagedByLabel = "serverless.kyma-project.io/managed-by"
FunctionControllerValue = "buildless-function-controller"
FunctionUUIDLabel = "serverless.kyma-project.io/uuid"
FunctionResourceLabel = "serverless.kyma-project.io/resource"
FunctionResourceLabelDeploymentValue = "deployment"
)
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (fr *FunctionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
// SetupWithManager sets up the controller with the Manager.
func (fr *FunctionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Named("buildless-function-controller").
For(&serverlessv1alpha2.Function{}).
WithEventFilter(buildPredicates()).
Owns(&appsv1.Deployment{}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func NewDeployment(f *serverlessv1alpha2.Function, c *config.FunctionConfig) *De

func (d *Deployment) construct() *appsv1.Deployment {
labels := map[string]string{
"app": d.name(),
// TODO: do we need to add more labels here?
"app": d.name(),
serverlessv1alpha2.FunctionNameLabel: d.function.GetName(),
serverlessv1alpha2.FunctionManagedByLabel: serverlessv1alpha2.FunctionControllerValue,
serverlessv1alpha2.FunctionResourceLabel: serverlessv1alpha2.FunctionResourceLabelDeploymentValue,
serverlessv1alpha2.FunctionUUIDLabel: string(d.function.GetUID()),
}

deployment := &appsv1.Deployment{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func TestDeployment_construct(t *testing.T) {
expectedLabels := map[string]string{
"app": "test-function-name",
"serverless.kyma-project.io/function-name": "test-function-name",
"serverless.kyma-project.io/managed-by": "buildless-function-controller",
"serverless.kyma-project.io/resource": "deployment",
"serverless.kyma-project.io/uuid": "test-uid",
}

r := d.construct()
Expand Down Expand Up @@ -812,6 +815,7 @@ func minimalFunction() *serverlessv1alpha2.Function {
ObjectMeta: metav1.ObjectMeta{
Name: "test-function-name",
Namespace: "test-function-namespace",
UID: "test-uid",
},
Spec: serverlessv1alpha2.FunctionSpec{
Runtime: "python312",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func (s *Service) construct() *corev1.Service {
}},
Selector: map[string]string{
// TODO: do we need to add more labels here?
serverlessv1alpha2.FunctionNameLabel: s.function.GetName(),
serverlessv1alpha2.FunctionNameLabel: s.function.GetName(),
serverlessv1alpha2.FunctionManagedByLabel: serverlessv1alpha2.FunctionControllerValue,
serverlessv1alpha2.FunctionResourceLabel: serverlessv1alpha2.FunctionResourceLabelDeploymentValue,
serverlessv1alpha2.FunctionUUIDLabel: string(s.function.GetUID()),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestNewService(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-function-name",
Namespace: "test-function-namespace",
UID: "test-uid",
},
Spec: serverlessv1alpha2.FunctionSpec{},
Status: serverlessv1alpha2.FunctionStatus{},
Expand All @@ -34,6 +35,9 @@ func TestNewService(t *testing.T) {
}},
Selector: map[string]string{
"serverless.kyma-project.io/function-name": "test-function-name",
"serverless.kyma-project.io/managed-by": "buildless-function-controller",
"serverless.kyma-project.io/resource": "deployment",
"serverless.kyma-project.io/uuid": "test-uid",
},
},
}
Expand Down

0 comments on commit 3912fa1

Please sign in to comment.