Skip to content

Commit

Permalink
Change labels to function-controller in buildless (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKalke authored Jan 24, 2025
1 parent e7a1328 commit 6509321
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (f *Function) UpdateCondition(c ConditionType, s metav1.ConditionStatus, r
const (
FunctionNameLabel = "serverless.kyma-project.io/function-name"
FunctionManagedByLabel = "serverless.kyma-project.io/managed-by"
FunctionControllerValue = "buildless-function-controller"
FunctionControllerValue = "function-controller"
FunctionUUIDLabel = "serverless.kyma-project.io/uuid"
FunctionResourceLabel = "serverless.kyma-project.io/resource"
FunctionResourceLabelDeploymentValue = "deployment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +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").
Named("function-controller").
For(&serverlessv1alpha2.Function{}).
WithEventFilter(buildPredicates()).
Owns(&appsv1.Deployment{}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ 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/managed-by": "function-controller",
"serverless.kyma-project.io/resource": "deployment",
"serverless.kyma-project.io/uuid": "test-uid",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ func NewService(f *serverlessv1alpha2.Function) *Service {
return s
}

func (s *Service) functionLabels() map[string]string {
return map[string]string{
serverlessv1alpha2.FunctionNameLabel: s.function.GetName(),
serverlessv1alpha2.FunctionManagedByLabel: serverlessv1alpha2.FunctionControllerValue,
serverlessv1alpha2.FunctionUUIDLabel: string(s.function.GetUID()),
}
}

func (s *Service) construct() *corev1.Service {
selectorLabes := s.functionLabels()
selectorLabes[serverlessv1alpha2.FunctionResourceLabel] = serverlessv1alpha2.FunctionResourceLabelDeploymentValue

service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: s.function.Name,
Namespace: s.function.Namespace,
//TODO: do we need to add labels or annotations here?
//Labels: s.functionLabels(),
Labels: s.functionLabels(),
//Annotations: s.functionAnnotations(),
},
Spec: corev1.ServiceSpec{
Expand All @@ -40,13 +51,7 @@ func (s *Service) construct() *corev1.Service {
Port: 80,
Protocol: corev1.ProtocolTCP,
}},
Selector: map[string]string{
// TODO: do we need to add more labels here?
serverlessv1alpha2.FunctionNameLabel: s.function.GetName(),
serverlessv1alpha2.FunctionManagedByLabel: serverlessv1alpha2.FunctionControllerValue,
serverlessv1alpha2.FunctionResourceLabel: serverlessv1alpha2.FunctionResourceLabelDeploymentValue,
serverlessv1alpha2.FunctionUUIDLabel: string(s.function.GetUID()),
},
Selector: selectorLabes,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func TestNewService(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-function-name",
Namespace: "test-function-namespace",
Labels: map[string]string{
"serverless.kyma-project.io/function-name": "test-function-name",
"serverless.kyma-project.io/managed-by": "function-controller",
"serverless.kyma-project.io/uuid": "test-uid",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Expand All @@ -35,7 +40,7 @@ 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/managed-by": "function-controller",
"serverless.kyma-project.io/resource": "deployment",
"serverless.kyma-project.io/uuid": "test-uid",
},
Expand Down

0 comments on commit 6509321

Please sign in to comment.