Ian Howell 9f4f1a7849 Move from Godeps to go modules
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
2019-09-30 14:20:47 -05:00

83 lines
1.9 KiB
Go

package entrypoint
import (
"sync"
"time"
"k8s.io/client-go/rest"
cli "opendev.org/airship/kubernetes-entrypoint/client"
"opendev.org/airship/kubernetes-entrypoint/logger"
)
var dependencies []Resolver // List containing all dependencies to be resolved
const (
//DependencyPrefix is a prefix for env variables
DependencyPrefix = "DEPENDENCY_"
JsonSuffix = "_JSON"
resolverSleepInterval = 2
)
//Resolver is an interface which all dependencies should implement
type Resolver interface {
IsResolved(entrypoint EntrypointInterface) (bool, error)
}
type EntrypointInterface interface {
Resolve()
Client() cli.ClientInterface
}
// Entrypoint is a main struct which checks dependencies
type Entrypoint struct {
client cli.ClientInterface
namespace string
}
//Register is a function which registers new dependencies
func Register(res Resolver) {
if res == nil {
panic("Entrypoint: could not register nil Resolver")
}
dependencies = append(dependencies, res)
}
//New is a constructor for entrypoint
func New(config *rest.Config) (entry *Entrypoint, err error) {
entry = new(Entrypoint)
client, err := cli.New(config)
if err != nil {
return nil, err
}
entry.client = client
return entry, err
}
func (e Entrypoint) Client() (client cli.ClientInterface) {
return e.client
}
//Resolve is a main loop which iterates through all dependencies and resolves them
func (e Entrypoint) Resolve() {
var wg sync.WaitGroup
for _, dep := range dependencies {
wg.Add(1)
go func(dep Resolver) {
defer wg.Done()
logger.Info.Printf("Resolving %v", dep)
var err error
status := false
for !status {
if status, err = dep.IsResolved(e); err != nil {
logger.Warning.Printf("Resolving dependency %s failed: %v .", dep, err)
}
time.Sleep(resolverSleepInterval * time.Second)
}
logger.Info.Printf("Dependency %v is resolved.", dep)
}(dep)
}
wg.Wait()
}