Unverified Commit 0756702a authored by julienmancuso's avatar julienmancuso Committed by GitHub
Browse files

feat: label component CR for planner (#901)

parent d2635a7e
......@@ -42,6 +42,7 @@ const (
KubeLabelDynamoSelector = "nvidia.com/selector"
KubeLabelDynamoComponent = "nvidia.com/dynamo-component"
KubeLabelDynamoNamespace = "nvidia.com/dynamo-namespace"
KubeLabelDynamoDeploymentTargetType = "nvidia.com/dynamo-deployment-target-type"
KubeLabelDynamoComponentType = "nvidia.com/dynamo-component-type"
......
......@@ -31,6 +31,7 @@ import (
"github.com/ai-dynamo/dynamo/deploy/dynamo/operator/api/dynamo/schemas"
"github.com/ai-dynamo/dynamo/deploy/dynamo/operator/api/v1alpha1"
commonconfig "github.com/ai-dynamo/dynamo/deploy/dynamo/operator/internal/config"
commonconsts "github.com/ai-dynamo/dynamo/deploy/dynamo/operator/internal/consts"
"github.com/huandu/xstrings"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
......@@ -234,6 +235,12 @@ func GenerateDynamoComponentsDeployments(ctx context.Context, parentDynamoGraphD
deployment.Spec.DynamoTag = config.DynamoTag
deployment.Spec.DynamoComponent = parentDynamoGraphDeployment.Spec.DynamoGraph
deployment.Spec.ServiceName = service.Name
labels := make(map[string]string)
// add the labels in the spec in order to label all sub-resources
deployment.Spec.Labels = labels
// and add the labels to the deployment itself
deployment.Labels = labels
labels[commonconsts.KubeLabelDynamoComponent] = service.Name
if service.Config.Dynamo != nil && service.Config.Dynamo.Enabled {
dynamoNamespace := service.Config.Dynamo.Namespace
if dynamoNamespace == "" {
......@@ -242,6 +249,7 @@ func GenerateDynamoComponentsDeployments(ctx context.Context, parentDynamoGraphD
}
deployment.Spec.DynamoNamespace = &dynamoNamespace
dynamoServices[service.Name] = fmt.Sprintf("%s/%s", service.Config.Dynamo.Name, dynamoNamespace)
labels[commonconsts.KubeLabelDynamoNamespace] = dynamoNamespace
} else {
// dynamo is not enabled
if config.EntryService == service.Name {
......
......@@ -23,6 +23,7 @@ import (
compounaiCommon "github.com/ai-dynamo/dynamo/deploy/dynamo/operator/api/dynamo/common"
"github.com/ai-dynamo/dynamo/deploy/dynamo/operator/api/v1alpha1"
commonconsts "github.com/ai-dynamo/dynamo/deploy/dynamo/operator/internal/consts"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
......@@ -93,6 +94,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -125,6 +130,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
DeploymentSelectorValue: "service2",
},
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
},
},
......@@ -132,6 +141,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -141,6 +153,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
},
},
},
},
......@@ -202,6 +217,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -237,6 +255,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Enabled: true,
Host: "test-dynamographdeployment",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
},
},
......@@ -244,6 +265,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -254,6 +279,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
},
},
......@@ -311,6 +340,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -343,6 +375,9 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
},
},
Ingress: v1alpha1.IngressSpec{},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
},
},
......@@ -350,6 +385,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
......@@ -360,6 +399,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Enabled: false,
},
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
},
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment