Svc metadata (#972)

* Added service metadata

* Added metadata to runtime service

* Add Annotations metadata to service metadata

* Add micro/micro as default service owners

* Update runtime/kubernetes/client/kubernetes.go

Change comment

Co-Authored-By: Jake Sanders <i@am.so-aweso.me>
This commit is contained in:
Milos Gajdos
2019-11-22 17:10:00 +00:00
committed by Asim Aslam
parent 8dc3fb964e
commit 38e29c5101
10 changed files with 209 additions and 124 deletions

View File

@@ -152,10 +152,5 @@ func (c *client) List(r *Resource) error {
"micro": "service",
}
return api.NewRequest(c.opts).
Get().
Resource(r.Kind).
Params(&api.Params{LabelSelector: labels}).
Do().
Into(r.Value)
return c.Get(r, labels)
}

View File

@@ -50,7 +50,6 @@ func DefaultService(name, version string) *Service {
if len(version) > 0 {
// API service object name joins name and version over "-"
svcName = strings.Join([]string{name, version}, "-")
}
Metadata := &Metadata{
@@ -84,26 +83,32 @@ func DefaultDeployment(name, version, source string) *Deployment {
"micro": "service",
}
// API deployment object name joins name and version over "="
depName := strings.Join([]string{name, version}, "-")
depName := name
if len(version) > 0 {
// API deployment object name joins name and version over "-"
depName = strings.Join([]string{name, version}, "-")
}
Metadata := &Metadata{
Name: depName,
Namespace: "default",
Version: version,
Labels: Labels,
Annotations: map[string]string{
"source": source,
"owner": "micro",
"group": "micro",
},
}
// TODO: we need to figure out this version stuff
// might be worth adding Build to runtime.Service
// might have to add Build to runtime.Service
buildTime, err := strconv.ParseInt(version, 10, 64)
if err == nil {
buildUnixTimeUTC := time.Unix(buildTime, 0)
Metadata.Annotations = map[string]string{
"build": buildUnixTimeUTC.Format(time.RFC3339),
}
Metadata.Annotations["build"] = buildUnixTimeUTC.Format(time.RFC3339)
} else {
log.Debugf("Runtime could not parse build: %v", err)
log.Debugf("could not parse build: %v", err)
}
// enable go modules by default

View File

@@ -17,6 +17,12 @@ metadata:
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
annotations:
{{- with .Metadata.Annotations }}
{{- range $key, $value := . }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
spec:
replicas: {{ .Spec.Replicas }}
selector:

View File

@@ -103,13 +103,21 @@ type DeploymentSpec struct {
Template *Template `json:"template,omitempty"`
}
// DeploymentCondition describes the state of deployment
type DeploymentCondition struct {
Type string `json:"type"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
// DeploymentStatus is returned when querying deployment
type DeploymentStatus struct {
Replicas int `json:"replicas,omitempty"`
UpdatedReplicas int `json:"updatedReplicas,omitempty"`
ReadyReplicas int `json:"readyReplicas,omitempty"`
AvailableReplicas int `json:"availableReplicas,omitempty"`
UnavailableReplicas int `json:"unavailableReplicas,omitempty"`
Replicas int `json:"replicas,omitempty"`
UpdatedReplicas int `json:"updatedReplicas,omitempty"`
ReadyReplicas int `json:"readyReplicas,omitempty"`
AvailableReplicas int `json:"availableReplicas,omitempty"`
UnavailableReplicas int `json:"unavailableReplicas,omitempty"`
Conditions []DeploymentCondition `json:"conditions,omitempty"`
}
// Deployment is Kubernetes deployment