Skip to content

Commit

Permalink
provision/kubernetes: add version label to deployments and app to svcs
Browse files Browse the repository at this point in the history
The version label can be used by istio or other components.
  • Loading branch information
cezarsa committed Nov 14, 2018
1 parent 02a88fd commit 82022c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 11 additions & 3 deletions provision/kubernetes/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ func createAppDeployment(client *ClusterClient, oldDeployment *v1beta2.Deploymen
rawAppLabel := appLabelForApp(a, process)
expandedLabels["app"] = rawAppLabel
expandedLabelsNoReplicas["app"] = rawAppLabel
_, tag := image.SplitImageName(imageName)
expandedLabels["version"] = tag
expandedLabelsNoReplicas["version"] = tag
deployment := v1beta2.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: depName,
Expand Down Expand Up @@ -950,13 +953,19 @@ func (m *serviceManager) DeployService(ctx context.Context, a provision.App, pro
}
return provision.ErrUnitStartup{Err: err}
}
expandedLabels := labels.ToLabels()
labels.SetIsHeadlessService()
expandedLabelsHeadless := labels.ToLabels()
rawAppLabel := appLabelForApp(a, process)
expandedLabels["app"] = rawAppLabel
expandedLabelsHeadless["app"] = rawAppLabel
targetPort := getTargetPortForImage(img)
port, _ := strconv.Atoi(provision.WebProcessDefaultPort())
svc := &apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: depName,
Namespace: ns,
Labels: labels.ToLabels(),
Labels: expandedLabels,
Annotations: annotations.ToLabels(),
},
Spec: apiv1.ServiceSpec{
Expand Down Expand Up @@ -984,13 +993,12 @@ func (m *serviceManager) DeployService(ctx context.Context, a provision.App, pro
if err != nil {
return errors.WithStack(err)
}
labels.SetIsHeadlessService()
kubeConf := getKubeConfig()
headlessSvc := &apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: headlessServiceNameForApp(a, process),
Namespace: ns,
Labels: labels.ToLabels(),
Labels: expandedLabelsHeadless,
Annotations: annotations.ToLabels(),
},
Spec: apiv1.ServiceSpec{
Expand Down
11 changes: 8 additions & 3 deletions provision/kubernetes/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func (s *S) TestServiceManagerDeployService(c *check.C) {
a := &app.App{Name: "myapp", TeamOwner: s.team.Name}
err := app.CreateApp(a, s.user)
c.Assert(err, check.IsNil)
err = image.SaveImageCustomData("myimg", map[string]interface{}{
err = image.SaveImageCustomData("myimg:v2", map[string]interface{}{
"processes": map[string]interface{}{
"p1": "cm1",
"p2": "cmd2",
},
})
c.Assert(err, check.IsNil)
err = servicecommon.RunServicePipeline(&m, a, "myimg", servicecommon.ProcessSpec{
err = servicecommon.RunServicePipeline(&m, a, "myimg:v2", servicecommon.ProcessSpec{
"p1": servicecommon.ProcessState{Start: true},
}, nil)
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -98,6 +98,7 @@ func (s *S) TestServiceManagerDeployService(c *check.C) {
"tsuru.io/provisioner": "kubernetes",
"tsuru.io/builder": "",
"app": "myapp-p1",
"version": "v2",
}
podLabels := make(map[string]string)
for k, v := range depLabels {
Expand Down Expand Up @@ -159,7 +160,7 @@ func (s *S) TestServiceManagerDeployService(c *check.C) {
Containers: []apiv1.Container{
{
Name: "myapp-p1",
Image: "myimg",
Image: "myimg:v2",
Command: []string{
"/bin/sh",
"-lc",
Expand Down Expand Up @@ -192,6 +193,7 @@ func (s *S) TestServiceManagerDeployService(c *check.C) {
Name: "myapp-p1",
Namespace: nsName,
Labels: map[string]string{
"app": "myapp-p1",
"tsuru.io/is-tsuru": "true",
"tsuru.io/is-service": "true",
"tsuru.io/is-build": "false",
Expand Down Expand Up @@ -236,6 +238,7 @@ func (s *S) TestServiceManagerDeployService(c *check.C) {
Name: "myapp-p1-units",
Namespace: nsName,
Labels: map[string]string{
"app": "myapp-p1",
"tsuru.io/is-tsuru": "true",
"tsuru.io/is-service": "true",
"tsuru.io/is-build": "false",
Expand Down Expand Up @@ -356,6 +359,7 @@ func (s *S) TestServiceManagerDeployServiceCustomPort(c *check.C) {
Name: "myapp-p1",
Namespace: nsName,
Labels: map[string]string{
"app": "myapp-p1",
"tsuru.io/is-tsuru": "true",
"tsuru.io/is-service": "true",
"tsuru.io/is-build": "false",
Expand Down Expand Up @@ -424,6 +428,7 @@ func (s *S) TestServiceManagerDeployServiceCustomHeadlessPort(c *check.C) {
Name: "myapp-p1-units",
Namespace: nsName,
Labels: map[string]string{
"app": "myapp-p1",
"tsuru.io/is-tsuru": "true",
"tsuru.io/is-service": "true",
"tsuru.io/is-build": "false",
Expand Down

0 comments on commit 82022c8

Please sign in to comment.