
This commit removes the configuration files for Godeps as well as the vendored dependencies, replacing them with go modules, Go's built-in dependency management system. This dramatically slims down the size of the repo (from 25M to 324K, discounting the .git directory) and greatly speeds up cloning times. This will also provide mechanisms for managing versions of any auxiliary tools (e.g. linters), creating a reproducible environment for developers and CI/CD efforts. This also modifies the Makefile to take into account that the repo no longer needs to be cloned into the GOPATH. Change-Id: I2213792cc3ce81831d5b835f2252ca6f137e0086
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
entry "opendev.org/airship/kubernetes-entrypoint/entrypoint"
|
|
"opendev.org/airship/kubernetes-entrypoint/util/env"
|
|
)
|
|
|
|
const FailingStatusFormat = "Service %v has no endpoints"
|
|
|
|
type Service struct {
|
|
name string
|
|
namespace string
|
|
}
|
|
|
|
func init() {
|
|
serviceEnv := fmt.Sprintf("%sSERVICE", entry.DependencyPrefix)
|
|
if serviceDeps := env.SplitEnvToDeps(serviceEnv); serviceDeps != nil {
|
|
if len(serviceDeps) > 0 {
|
|
for _, dep := range serviceDeps {
|
|
entry.Register(NewService(dep.Name, dep.Namespace))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func NewService(name string, namespace string) Service {
|
|
return Service{
|
|
name: name,
|
|
namespace: namespace,
|
|
}
|
|
|
|
}
|
|
|
|
func (s Service) IsResolved(entrypoint entry.EntrypointInterface) (bool, error) {
|
|
e, err := entrypoint.Client().Endpoints(s.namespace).Get(s.name, metav1.GetOptions{})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
for _, subset := range e.Subsets {
|
|
if len(subset.Addresses) > 0 {
|
|
return true, nil
|
|
}
|
|
}
|
|
return false, fmt.Errorf(FailingStatusFormat, s.name)
|
|
}
|
|
|
|
func (s Service) String() string {
|
|
return fmt.Sprintf("Service %s in namespace %s", s.name, s.namespace)
|
|
}
|