Update the k8s deployment to use metadata labels & custom source (#1271)
This commit is contained in:
parent
962567ef42
commit
afe6861e2f
@ -3,7 +3,6 @@ package kubernetes
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
log "github.com/micro/go-micro/v2/logger"
|
log "github.com/micro/go-micro/v2/logger"
|
||||||
"github.com/micro/go-micro/v2/runtime"
|
"github.com/micro/go-micro/v2/runtime"
|
||||||
@ -34,12 +33,15 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
|||||||
kservice := client.NewService(name, version, c.Type)
|
kservice := client.NewService(name, version, c.Type)
|
||||||
kdeploy := client.NewDeployment(name, version, c.Type)
|
kdeploy := client.NewDeployment(name, version, c.Type)
|
||||||
|
|
||||||
if len(c.Source) > 0 {
|
// ensure the metadata is set
|
||||||
for i := range kdeploy.Spec.Template.PodSpec.Containers {
|
if kdeploy.Spec.Template.Metadata.Annotations == nil {
|
||||||
kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source
|
kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string)
|
||||||
kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{}
|
}
|
||||||
kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name}
|
|
||||||
}
|
// add the service metadata to the k8s labels, do this first so we
|
||||||
|
// don't override any labels used by the runtime, e.g. name
|
||||||
|
for k, v := range s.Metadata {
|
||||||
|
kdeploy.Metadata.Annotations[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// attach our values to the deployment; name, version, source
|
// attach our values to the deployment; name, version, source
|
||||||
@ -51,11 +53,16 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
|||||||
kdeploy.Metadata.Annotations["owner"] = "micro"
|
kdeploy.Metadata.Annotations["owner"] = "micro"
|
||||||
kdeploy.Metadata.Annotations["group"] = "micro"
|
kdeploy.Metadata.Annotations["group"] = "micro"
|
||||||
|
|
||||||
// set a build timestamp to the current time
|
// update the deployment is a custom source is provided
|
||||||
if kdeploy.Spec.Template.Metadata.Annotations == nil {
|
if len(c.Source) > 0 {
|
||||||
kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string)
|
for i := range kdeploy.Spec.Template.PodSpec.Containers {
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{}
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name}
|
||||||
|
}
|
||||||
|
|
||||||
|
kdeploy.Metadata.Annotations["source"] = c.Source
|
||||||
}
|
}
|
||||||
kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339)
|
|
||||||
|
|
||||||
// define the environment values used by the container
|
// define the environment values used by the container
|
||||||
env := make([]client.EnvVar, 0, len(c.Env))
|
env := make([]client.EnvVar, 0, len(c.Env))
|
||||||
|
Loading…
Reference in New Issue
Block a user