Unverified Commit 7a341f86 authored by julienmancuso's avatar julienmancuso Committed by GitHub
Browse files

feat: simplify k8s deployment (#1708)

parent 5505507b
......@@ -37,7 +37,6 @@ import (
func TestGenerateDynamoComponentsDeployments(t *testing.T) {
type args struct {
parentDynamoGraphDeployment *v1alpha1.DynamoGraphDeployment
config *DynamoGraphConfig
ingressSpec *v1alpha1.IngressSpec
}
tests := []struct {
......@@ -47,7 +46,7 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
wantErr bool
}{
{
name: "Test GenerateDynamoComponentsDeployments http dependency",
name: "Test GenerateDynamoComponentsDeployments",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
......@@ -55,40 +54,34 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service1",
},
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"default"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
Workers: &[]int32{3}[0],
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: false,
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"default"}[0],
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
......@@ -107,11 +100,10 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService1",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
DynamoNamespace: &[]string{"default"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
......@@ -120,160 +112,15 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
GPU: "0",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "name",
DeploymentSelectorValue: "service2",
},
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
Autoscaling: nil,
},
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService1",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service2",
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
},
},
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments dynamo dependency",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
HttpExposed: true,
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service2",
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "dynamo",
DeploymentSelectorValue: "service2/default",
},
},
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
......@@ -284,97 +131,14 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service2",
DynamoNamespace: &[]string{"default"}[0],
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
Replicas: &[]int32{3}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
},
},
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments dynamo dependency, default namespace",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
HttpExposed: true,
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Name: "service2",
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
......@@ -382,80 +146,8 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
GPU: "0",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "dynamo",
DeploymentSelectorValue: "service2/dynamo-test-dynamographdeployment",
},
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
"service2": {
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",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service2",
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
},
Autoscaling: nil,
},
},
},
......@@ -463,7 +155,7 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments dependency not found",
name: "Test GenerateDynamoComponentsDeployments with default dynamo namespace",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
......@@ -471,491 +163,40 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService3",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service1",
},
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
},
},
{
Name: "service3",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service3",
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{},
},
wantErr: true,
},
{
name: "Test GenerateDynamoComponentsDeployments planner",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService1",
Services: []ServiceConfig{
{
Name: "service1",
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service1",
ComponentType: ComponentTypePlanner,
},
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
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",
DynamoTag: "dynamocomponent:MyService1",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
DynamoNamespace: &[]string{"default"}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
ExtraPodSpec: &compounaiCommon.ExtraPodSpec{
ServiceAccountName: PlannerServiceAccountName,
},
Autoscaling: &v1alpha1.Autoscaling{},
},
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments dynamo dependency, different namespace",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "namespace1",
Name: "service1",
},
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "namespace2",
Name: "service2",
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{},
},
want: nil,
wantErr: true,
},
{
name: "Test GenerateDynamoComponentsDeployments ingress enabled by default",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyServiceIngressEnabled",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Config: Config{
HttpExposed: true,
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyServiceIngressEnabled",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Annotations: nil,
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
ServiceName: "service1",
DynamoNamespace: nil,
Resources: nil,
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
MinReplicas: 0,
MaxReplicas: 0,
Behavior: nil,
Metrics: nil,
},
Envs: nil,
EnvFromSecret: nil,
PVC: nil,
RunMode: nil,
ExternalServices: nil,
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
ExtraPodMetadata: nil,
ExtraPodSpec: nil,
LivenessProbe: nil,
ReadinessProbe: nil,
Replicas: nil,
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments ingress explicitly disabled",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyServiceIngressDisabled",
Services: []ServiceConfig{
{
Name: "service1",
Config: Config{},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: false,
},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyServiceIngressDisabled",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Annotations: nil,
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
ServiceName: "service1",
DynamoNamespace: nil,
Resources: nil,
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
MinReplicas: 0,
MaxReplicas: 0,
Behavior: nil,
Metrics: nil,
},
Envs: nil,
EnvFromSecret: nil,
PVC: nil,
RunMode: nil,
ExternalServices: nil,
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
},
ExtraPodMetadata: nil,
ExtraPodSpec: nil,
LivenessProbe: nil,
ReadinessProbe: nil,
Replicas: nil,
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments ingress custom host",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyServiceIngressCustomHost",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Config: Config{
HttpExposed: true,
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: true,
Host: "custom-host",
},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service1",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyServiceIngressCustomHost",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Annotations: nil,
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
ServiceName: "service1",
DynamoNamespace: nil,
Resources: nil,
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
MinReplicas: 0,
MaxReplicas: 0,
Behavior: nil,
Metrics: nil,
},
Envs: nil,
EnvFromSecret: nil,
PVC: nil,
RunMode: nil,
ExternalServices: nil,
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "custom-host",
},
ExtraPodMetadata: nil,
ExtraPodSpec: nil,
LivenessProbe: nil,
ReadinessProbe: nil,
Replicas: nil,
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
},
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments with config override from parent deployment",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "10",
Memory: "10Gi",
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
HttpExposed: true,
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service2",
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
ingressSpec: &v1alpha1.IngressSpec{},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
......@@ -964,51 +205,30 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
ServiceName: "service1",
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "10",
Memory: "10Gi",
GPU: "0",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "dynamo",
DeploymentSelectorValue: "service2/default",
},
},
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Autoscaling: nil,
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
......@@ -1016,34 +236,27 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service2",
DynamoNamespace: &[]string{"default"}[0],
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
Replicas: &[]int32{3}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: nil,
},
},
},
......@@ -1051,7 +264,7 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments generate config from DYN_DEPLOYMENT_CONFIG env var",
name: "Test GenerateDynamoComponentsDeployments with different namespaces",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
......@@ -1059,20 +272,32 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"default"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"another"}[0],
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "10",
Memory: "10Gi",
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
......@@ -1080,35 +305,48 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
},
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
HttpExposed: true,
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
ingressSpec: &v1alpha1.IngressSpec{},
},
want: nil,
wantErr: true,
},
{
name: "Test GenerateDynamoComponentsDeployments with ingress enabled",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment",
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service2",
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
......@@ -1126,58 +364,34 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
ServiceName: "service1",
Replicas: &[]int32{3}[0],
ServiceName: "service1",
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "2",
Memory: "2Gi",
GPU: "2",
Custom: map[string]string{},
},
Limits: &compounaiCommon.ResourceItem{
CPU: "2",
Memory: "2Gi",
GPU: "2",
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "dynamo",
DeploymentSelectorValue: "service2/default",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Autoscaling: nil,
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
},
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
......@@ -1185,40 +399,27 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
ServiceName: "service2",
DynamoNamespace: &[]string{"default"}[0],
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
Replicas: &[]int32{3}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: nil,
},
},
},
......@@ -1226,7 +427,7 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
wantErr: false,
},
{
name: "Test GenerateDynamoComponentsDeployments, number of replicas always set by the parent CR",
name: "Test GenerateDynamoComponentsDeployments with config from DYN_DEPLOYMENT_CONFIG env var",
args: args{
parentDynamoGraphDeployment: &v1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{
......@@ -1234,67 +435,45 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":2, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "10",
Memory: "10Gi",
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Replicas: &[]int32{10}[0],
},
},
},
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyService2",
EntryService: "service1",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{{"service": "service2"}},
Config: Config{
HttpExposed: true,
Resources: &Resources{
CPU: &[]string{"1"}[0],
Memory: &[]string{"1Gi"}[0],
GPU: &[]string{"0"}[0],
Custom: map[string]string{},
},
Autoscaling: &Autoscaling{
MinReplicas: 1,
MaxReplicas: 5,
},
Workers: &[]int32{2}[0],
},
},
{
Name: "service2",
Dependencies: []map[string]string{},
Config: Config{
Dynamo: &DynamoConfig{
Enabled: true,
Namespace: "default",
Name: "service2",
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: nil,
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
},
},
},
ingressSpec: &v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
},
want: map[string]*v1alpha1.DynamoComponentDeployment{
"service1": {
......@@ -1303,20 +482,15 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
ServiceName: "service1",
Replicas: &[]int32{10}[0],
ServiceName: "service1",
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "2",
......@@ -1328,33 +502,22 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
CPU: "2",
Memory: "2Gi",
GPU: "2",
Custom: map[string]string{},
},
},
Autoscaling: &v1alpha1.Autoscaling{
Enabled: true,
MinReplicas: 1,
MaxReplicas: 5,
},
ExternalServices: map[string]v1alpha1.ExternalService{
"service2": {
DeploymentSelectorKey: "dynamo",
DeploymentSelectorValue: "service2/default",
Custom: nil,
},
},
Ingress: v1alpha1.IngressSpec{
Enabled: true,
Host: "test-dynamographdeployment",
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Autoscaling: nil,
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"ServiceArgs":{"Resources":{"CPU":"2","GPU":"2","Memory":"2Gi"},"Workers":2},"port":3000}}`,
},
},
},
},
Status: v1alpha1.DynamoComponentDeploymentStatus{
Conditions: nil,
PodSelector: nil,
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
......@@ -1362,39 +525,32 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyService2",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":3, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
ServiceName: "service2",
DynamoNamespace: &[]string{"default"}[0],
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
},
DynamoNamespace: &[]string{"dynamo-test-dynamographdeployment"}[0],
Replicas: &[]int32{3}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
commonconsts.KubeLabelDynamoNamespace: "dynamo-test-dynamographdeployment",
},
Ingress: v1alpha1.IngressSpec{
Enabled: false,
Host: "",
UseVirtualService: false,
VirtualServiceGateway: nil,
HostPrefix: nil,
Annotations: nil,
Labels: nil,
TLS: nil,
HostSuffix: nil,
IngressControllerClassName: nil,
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: nil,
Envs: []corev1.EnvVar{
{
Name: "DYN_DEPLOYMENT_CONFIG",
Value: `{"service1":{"port":8080,"ServiceArgs":{"Workers":2, "Resources":{"CPU":"2", "Memory":"2Gi", "GPU":"2"}}}}`,
},
},
},
},
......@@ -1411,20 +567,39 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
},
Spec: v1alpha1.DynamoGraphDeploymentSpec{
DynamoGraph: "dynamocomponent:ac4e234",
},
},
config: &DynamoGraphConfig{
DynamoTag: "dynamocomponent:MyServiceWithOverrides",
Services: []ServiceConfig{
{
Name: "service1",
Dependencies: []map[string]string{},
Config: Config{
ExtraPodSpec: &compounaiCommon.ExtraPodSpec{
MainContainer: &corev1.Container{
Command: []string{"sh", "-c"},
Args: []string{"echo hello world", "sleep 99999"},
Services: map[string]*v1alpha1.DynamoComponentDeploymentOverridesSpec{
"service1": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"default"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
ExtraPodSpec: &compounaiCommon.ExtraPodSpec{
MainContainer: &corev1.Container{
Command: []string{"sh", "-c"},
Args: []string{"echo hello world", "sleep 99999"},
},
},
},
},
"service2": {
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
DynamoNamespace: &[]string{"default"}[0],
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
},
},
......@@ -1440,19 +615,28 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponent: "dynamocomponent:ac4e234",
DynamoTag: "dynamocomponent:MyServiceWithOverrides",
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service1",
Autoscaling: &v1alpha1.Autoscaling{
Enabled: false,
ServiceName: "service1",
DynamoNamespace: &[]string{"default"}[0],
ComponentType: "main",
Replicas: &[]int32{3}[0],
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service1",
commonconsts.KubeLabelDynamoNamespace: "default",
},
Autoscaling: nil,
ExtraPodSpec: &compounaiCommon.ExtraPodSpec{
MainContainer: &corev1.Container{
Command: []string{"sh", "-c"},
......@@ -1462,13 +646,43 @@ func TestGenerateDynamoComponentsDeployments(t *testing.T) {
},
},
},
"service2": {
ObjectMeta: metav1.ObjectMeta{
Name: "test-dynamographdeployment-service2",
Namespace: "default",
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
},
},
Spec: v1alpha1.DynamoComponentDeploymentSpec{
DynamoComponentDeploymentSharedSpec: v1alpha1.DynamoComponentDeploymentSharedSpec{
ServiceName: "service2",
DynamoNamespace: &[]string{"default"}[0],
Replicas: &[]int32{3}[0],
Labels: map[string]string{
commonconsts.KubeLabelDynamoComponent: "service2",
commonconsts.KubeLabelDynamoNamespace: "default",
},
Resources: &compounaiCommon.Resources{
Requests: &compounaiCommon.ResourceItem{
CPU: "1",
Memory: "1Gi",
GPU: "0",
Custom: map[string]string{},
},
},
Autoscaling: nil,
},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GenerateDynamoComponentsDeployments(context.Background(), tt.args.parentDynamoGraphDeployment, tt.args.config, tt.args.ingressSpec)
got, err := GenerateDynamoComponentsDeployments(context.Background(), tt.args.parentDynamoGraphDeployment, tt.args.ingressSpec)
if (err != nil) != tt.wantErr {
t.Errorf("GenerateDynamoComponentsDeployments() error = %v, wantErr %v", err, tt.wantErr)
return
......
package secrets
import (
"context"
"encoding/json"
"fmt"
"sync"
"github.com/ai-dynamo/dynamo/deploy/cloud/operator/internal/common"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type DockerSecretIndexer struct {
// maps for a namespace, a docker registry server to a list of secret names
secrets map[string]map[string][]string
client client.Client
mu sync.RWMutex
}
func NewDockerSecretIndexer(client client.Client) *DockerSecretIndexer {
return &DockerSecretIndexer{
secrets: make(map[string]map[string][]string),
client: client,
}
}
func (i *DockerSecretIndexer) RefreshIndex(ctx context.Context) error {
// scan for all secrets in the namespace
secrets := &corev1.SecretList{}
if err := i.client.List(ctx, secrets); err != nil {
return fmt.Errorf("unable to list secrets: %w", err)
}
tmpSecrets := make(map[string]map[string][]string)
for _, secret := range secrets.Items {
if secret.Type == corev1.SecretTypeDockerConfigJson {
// unmarshal the secret data
dockerConfig := &struct {
Auths map[string]any `json:"auths"`
}{}
if err := json.Unmarshal(secret.Data[corev1.DockerConfigJsonKey], dockerConfig); err != nil {
return fmt.Errorf("unable to unmarshal docker config json for secret %s: %w", secret.Name, err)
}
namespace := secret.Namespace
if _, ok := tmpSecrets[namespace]; !ok {
tmpSecrets[namespace] = make(map[string][]string)
}
for auth := range dockerConfig.Auths {
// retrieve the registry host
registry, err := common.GetHost(auth)
if err != nil {
return fmt.Errorf("unable to get host for registry %s for secret %s: %w", auth, secret.Name, err)
}
tmpSecrets[namespace][registry] = append(tmpSecrets[namespace][registry], secret.Name)
}
}
}
i.mu.Lock()
defer i.mu.Unlock()
i.secrets = tmpSecrets
return nil
}
func (i *DockerSecretIndexer) GetSecrets(namespace, registry string) ([]string, error) {
registry, err := common.GetHost(registry)
if err != nil {
return nil, err
}
i.mu.RLock()
defer i.mu.RUnlock()
return i.secrets[namespace][registry], nil
}
package secrets
import (
"context"
"testing"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
func TestDockerSecretIndexer_RefreshIndex(t *testing.T) {
// Create mock secrets
mockSecrets := []corev1.Secret{
{
ObjectMeta: metav1.ObjectMeta{
Name: "secret1",
Namespace: "default",
},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{
".dockerconfigjson": []byte(`{"auths":{"docker.io":{}, "my-registry.com:5005/registry1":{}}}`),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "secret2",
Namespace: "default",
},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{
".dockerconfigjson": []byte(`{"auths":{"my-registry.com:5005/registry2":{}}}`),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "secret3",
Namespace: "another-namespace",
},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{
".dockerconfigjson": []byte(`{"auths":{"my-registry.com:5005/registry2":{}}}`),
},
},
}
// Create fake client with mock secrets
fakeClient := fake.NewClientBuilder().
WithScheme(scheme.Scheme).
WithObjects(&mockSecrets[0], &mockSecrets[1], &mockSecrets[2]).
Build()
i := NewDockerSecretIndexer(fakeClient)
if err := i.RefreshIndex(context.Background()); err != nil {
t.Errorf("DockerSecretIndexer.RefreshIndex() error = %v, wantErr %v", err, nil)
}
secrets, err := i.GetSecrets("default", "docker.io")
if err != nil {
t.Errorf("DockerSecretIndexer.GetSecrets() error = %v, wantErr %v", err, nil)
}
if len(secrets) != 1 {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", len(secrets), 1)
}
if secrets[0] != "secret1" {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", secrets[0], "secret1")
}
secrets, err = i.GetSecrets("default", "my-registry.com:5005")
if err != nil {
t.Errorf("DockerSecretIndexer.GetSecrets() error = %v, wantErr %v", err, nil)
}
if len(secrets) != 2 {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", len(secrets), 2)
}
if secrets[0] != "secret1" {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", secrets[0], "secret1")
}
if secrets[1] != "secret2" {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", secrets[1], "secret2")
}
secrets, err = i.GetSecrets("another-namespace", "my-registry.com:5005")
if err != nil {
t.Errorf("DockerSecretIndexer.GetSecrets() error = %v, wantErr %v", err, nil)
}
if len(secrets) != 1 {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", len(secrets), 1)
}
if secrets[0] != "secret3" {
t.Errorf("DockerSecretIndexer.GetSecrets() = %v, want %v", secrets[0], "secret3")
}
}
......@@ -138,7 +138,6 @@ addopts = [
"--mypy",
"--ignore-glob=*model.py",
"--ignore-glob=*_inc.py",
"--ignore-glob=deploy/cloud/api-store/*",
"--ignore-glob=*/llm/tensorrtllm*",
"--ignore-glob=docs/*",
# FIXME: Get relative/generic blob paths to work here
......
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