Unverified Commit 8af8c82f authored by julienmancuso's avatar julienmancuso Committed by GitHub
Browse files

fix: create k8s service for main component only (#953)

parent c4213899
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
package v1alpha1 package v1alpha1
import ( import (
"strings"
dynamoCommon "github.com/ai-dynamo/dynamo/deploy/cloud/operator/api/dynamo/common" dynamoCommon "github.com/ai-dynamo/dynamo/deploy/cloud/operator/api/dynamo/common"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
...@@ -160,3 +162,7 @@ func (s *DynamoComponentDeployment) GetSpec() any { ...@@ -160,3 +162,7 @@ func (s *DynamoComponentDeployment) GetSpec() any {
func (s *DynamoComponentDeployment) SetSpec(spec any) { func (s *DynamoComponentDeployment) SetSpec(spec any) {
s.Spec = spec.(DynamoComponentDeploymentSpec) s.Spec = spec.(DynamoComponentDeploymentSpec)
} }
func (s *DynamoComponentDeployment) IsMainComponent() bool {
return strings.HasSuffix(s.Spec.DynamoTag, s.Spec.ServiceName)
}
/*
* SPDX-FileCopyrightText: Copyright (c) 2022 Atalaya Tech. Inc
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES
*/
package v1alpha1
import (
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestDynamoComponentDeployment_IsMainComponent(t *testing.T) {
type fields struct {
TypeMeta metav1.TypeMeta
ObjectMeta metav1.ObjectMeta
Spec DynamoComponentDeploymentSpec
Status DynamoComponentDeploymentStatus
}
tests := []struct {
name string
fields fields
want bool
}{
{
name: "main component",
fields: fields{
Spec: DynamoComponentDeploymentSpec{
DynamoTag: "dynamo-component:main",
DynamoComponentDeploymentSharedSpec: DynamoComponentDeploymentSharedSpec{
ServiceName: "main",
},
},
},
want: true,
},
{
name: "not main component",
fields: fields{
Spec: DynamoComponentDeploymentSpec{
DynamoTag: "dynamo-component:main",
DynamoComponentDeploymentSharedSpec: DynamoComponentDeploymentSharedSpec{
ServiceName: "not-main",
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &DynamoComponentDeployment{
TypeMeta: tt.fields.TypeMeta,
ObjectMeta: tt.fields.ObjectMeta,
Spec: tt.fields.Spec,
Status: tt.fields.Status,
}
if got := s.IsMainComponent(); got != tt.want {
t.Errorf("DynamoComponentDeployment.IsMainComponent() = %v, want %v", got, tt.want)
}
})
}
}
...@@ -1522,8 +1522,8 @@ func (r *DynamoComponentDeploymentReconciler) generateService(ctx context.Contex ...@@ -1522,8 +1522,8 @@ func (r *DynamoComponentDeploymentReconciler) generateService(ctx context.Contex
}, },
} }
if !opt.isGenericService && !opt.containsStealingTrafficDebugModeEnabled { if !opt.dynamoComponentDeployment.IsMainComponent() || (!opt.isGenericService && !opt.containsStealingTrafficDebugModeEnabled) {
// if it's not a generic service and not contains stealing traffic debug mode enabled, we don't need to create the service // if it's not the main component or if it's not a generic service and not contains stealing traffic debug mode enabled, we don't need to create the service
return kubeService, true, nil return kubeService, true, nil
} }
......
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