add k8s service ip to metadata (#1367)
* add k8s service ip to metadata * go fmt * use same port as container
This commit is contained in:
parent
c91bf7e9e7
commit
1bd340701b
@ -2,6 +2,7 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -70,8 +71,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) {
|
||||
// version of the service
|
||||
version := kservice.Metadata.Labels["version"]
|
||||
|
||||
// save as service
|
||||
svcMap[name+version] = &service{
|
||||
srv := &service{
|
||||
Service: &runtime.Service{
|
||||
Name: name,
|
||||
Version: version,
|
||||
@ -80,10 +80,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) {
|
||||
kservice: &kservice,
|
||||
}
|
||||
|
||||
// set the address
|
||||
address := kservice.Spec.ClusterIP
|
||||
port := kservice.Spec.Ports[0]
|
||||
srv.Service.Metadata["address"] = fmt.Sprintf("%s:%d", address, port.Port)
|
||||
|
||||
// copy annotations metadata into service metadata
|
||||
for k, v := range kservice.Metadata.Annotations {
|
||||
svcMap[name+version].Service.Metadata[k] = v
|
||||
srv.Service.Metadata[k] = v
|
||||
}
|
||||
|
||||
// save as service
|
||||
svcMap[name+version] = srv
|
||||
}
|
||||
|
||||
// collect additional info from kubernetes deployment
|
||||
|
@ -217,7 +217,7 @@ func NewService(name, version, typ string) *Service {
|
||||
Type: "ClusterIP",
|
||||
Selector: Labels,
|
||||
Ports: []ServicePort{{
|
||||
"service-port", 9090, "",
|
||||
"service-port", 8080, "",
|
||||
}},
|
||||
}
|
||||
|
||||
|
@ -132,9 +132,10 @@ type ServicePort struct {
|
||||
|
||||
// ServiceSpec provides service configuration
|
||||
type ServiceSpec struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
Ports []ServicePort `json:"ports,omitempty"`
|
||||
ClusterIP string `json:"clusterIP"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
Ports []ServicePort `json:"ports,omitempty"`
|
||||
}
|
||||
|
||||
// ServiceStatus
|
||||
|
Loading…
x
Reference in New Issue
Block a user