Skip to content

Commit

Permalink
Add missing image name and selector
Browse files Browse the repository at this point in the history
  • Loading branch information
tiopramayudi committed Mar 12, 2024
1 parent 63fc044 commit 9659271
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions api/pkg/observability/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,18 @@ func (c *deployer) createDeploymentSpec(ctx context.Context, data *models.Worker
},
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{},
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": data.Metadata.App,
},
},
Replicas: &c.consumerConfig.Replicas,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "worker",
Image: "",
Image: c.consumerConfig.ImageName,
Command: []string{
"python",
"-m",
Expand Down
22 changes: 13 additions & 9 deletions api/pkg/observability/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
timeoutError deploymentStatus = "timeout_error"
)

func createDeploymentSpec(data *models.WorkerData, resourceRequest corev1.ResourceList, resourceLimit corev1.ResourceList) *appsv1.Deployment {
func createDeploymentSpec(data *models.WorkerData, resourceRequest corev1.ResourceList, resourceLimit corev1.ResourceList, imageName string) *appsv1.Deployment {
labels := data.Metadata.ToLabel()
numReplicas := int32(2)
cfgVolName := "config-volume"
Expand All @@ -61,13 +61,17 @@ func createDeploymentSpec(data *models.WorkerData, resourceRequest corev1.Resour
},
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{},
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": data.Metadata.App,
},
},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "worker",
Image: "",
Image: imageName,
Command: []string{
"python",
"-m",
Expand Down Expand Up @@ -291,7 +295,7 @@ func Test_deployer_Deploy(t *testing.T) {
Stream: "stream",
Team: "team",
},
}, requestResource, limitResource)
}, requestResource, limitResource, consumerConfig.ImageName)
prependUpsertDeploymentReactor(t, deploymentAPI, depl, nil, false)

updatedDepl := changeDeploymentStatus(depl, ready, 1)
Expand Down Expand Up @@ -415,7 +419,7 @@ func Test_deployer_Deploy(t *testing.T) {
Stream: "stream",
Team: "team",
},
}, requestResource, limitResource)
}, requestResource, limitResource, consumerConfig.ImageName)
prependUpsertDeploymentReactor(t, deploymentAPI, depl, fmt.Errorf("control plane is down"), false)
prependDeleteSecretReactor(t, secretAPI, "model-1-config", nil)
prependDeleteDeploymentReactor(t, deploymentAPI, "model-1", nil)
Expand Down Expand Up @@ -500,7 +504,7 @@ func Test_deployer_Deploy(t *testing.T) {
Stream: "stream",
Team: "team",
},
}, requestResource, limitResource)
}, requestResource, limitResource, consumerConfig.ImageName)
preprendGetDeploymentReactor(t, deploymentAPI, depl, nil)
prependUpsertDeploymentReactor(t, deploymentAPI, depl, nil, true)

Expand Down Expand Up @@ -605,7 +609,7 @@ func Test_deployer_Deploy(t *testing.T) {
Stream: "stream",
Team: "team",
},
}, requestResource, limitResource)
}, requestResource, limitResource, consumerConfig.ImageName)
preprendGetDeploymentReactor(t, deploymentAPI, depl, nil)
prependUpsertDeploymentReactor(t, deploymentAPI, depl, nil, true)

Expand Down Expand Up @@ -780,7 +784,7 @@ func Test_deployer_GetDeployedManifest(t *testing.T) {
},
TopicSource: "caraml-project-1-model-1-1-prediction-log",
}
depl := createDeploymentSpec(workerData, requestResource, limitResource)
depl := createDeploymentSpec(workerData, requestResource, limitResource, "image:v0.1")
testCases := []struct {
name string
data *models.WorkerData
Expand Down Expand Up @@ -979,7 +983,7 @@ func prependUpsertDeploymentReactor(t *testing.T, deploymentAPI *fakeappsv1.Fake
}

if !reflect.DeepEqual(requestedDepl.ObjectMeta, actualReqDepl.ObjectMeta) || !reflect.DeepEqual(requestedDepl.Spec, actualReqDepl.Spec) {
t.Fatalf("actual and expected requested secret is different")
t.Fatalf("actual and expected requested deployment is different")
}

return true, requestedDepl, expectedErr
Expand Down

0 comments on commit 9659271

Please sign in to comment.