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
|
package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -70,8 +71,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) {
|
|||||||
// version of the service
|
// version of the service
|
||||||
version := kservice.Metadata.Labels["version"]
|
version := kservice.Metadata.Labels["version"]
|
||||||
|
|
||||||
// save as service
|
srv := &service{
|
||||||
svcMap[name+version] = &service{
|
|
||||||
Service: &runtime.Service{
|
Service: &runtime.Service{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
@ -80,10 +80,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) {
|
|||||||
kservice: &kservice,
|
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
|
// copy annotations metadata into service metadata
|
||||||
for k, v := range kservice.Metadata.Annotations {
|
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
|
// collect additional info from kubernetes deployment
|
||||||
|
@ -217,7 +217,7 @@ func NewService(name, version, typ string) *Service {
|
|||||||
Type: "ClusterIP",
|
Type: "ClusterIP",
|
||||||
Selector: Labels,
|
Selector: Labels,
|
||||||
Ports: []ServicePort{{
|
Ports: []ServicePort{{
|
||||||
"service-port", 9090, "",
|
"service-port", 8080, "",
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@ type ServicePort struct {
|
|||||||
|
|
||||||
// ServiceSpec provides service configuration
|
// ServiceSpec provides service configuration
|
||||||
type ServiceSpec struct {
|
type ServiceSpec struct {
|
||||||
|
ClusterIP string `json:"clusterIP"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Selector map[string]string `json:"selector,omitempty"`
|
Selector map[string]string `json:"selector,omitempty"`
|
||||||
Ports []ServicePort `json:"ports,omitempty"`
|
Ports []ServicePort `json:"ports,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user