Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
gorename flux.ServiceID -> flux.ResourceID
Browse files Browse the repository at this point in the history
  • Loading branch information
awh committed Sep 6, 2017
1 parent c45b65d commit 6f81af7
Show file tree
Hide file tree
Showing 47 changed files with 187 additions and 187 deletions.
4 changes: 2 additions & 2 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
type Cluster interface {
// Get all of the services (optionally, from a specific namespace), excluding those
AllServices(maybeNamespace string) ([]Service, error)
SomeServices([]flux.ServiceID) ([]Service, error)
SomeServices([]flux.ResourceID) ([]Service, error)
Ping() error
Export() ([]byte, error)
Sync(SyncDef) error
Expand All @@ -31,7 +31,7 @@ type Cluster interface {
// all supported platforms, but right now it looks a lot like a Kubernetes
// service.
type Service struct {
ID flux.ServiceID
ID flux.ResourceID
IP string
Metadata map[string]string // a grab bag of goodies, likely platform-specific
Status string // A status summary for display
Expand Down
4 changes: 2 additions & 2 deletions cluster/kubernetes/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// directory given, and returns a map of service IDs (from its
// specified namespace and name) to the paths of resource definition
// files.
func (c *Manifests) FindDefinedServices(path string) (map[flux.ServiceID][]string, error) {
func (c *Manifests) FindDefinedServices(path string) (map[flux.ResourceID][]string, error) {
objects, err := resource.Load(path)
if err != nil {
return nil, errors.Wrap(err, "loading resources")
Expand All @@ -25,7 +25,7 @@ func (c *Manifests) FindDefinedServices(path string) (map[flux.ServiceID][]strin
}

var (
result = map[flux.ServiceID][]string{}
result = map[flux.ResourceID][]string{}
services []*resource.Service
templates []template
)
Expand Down
4 changes: 2 additions & 2 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *Cluster) loop() {
// SomeServices returns the services named, missing out any that don't
// exist in the cluster. They do not necessarily have to be returned
// in the order requested.
func (c *Cluster) SomeServices(ids []flux.ServiceID) (res []cluster.Service, err error) {
func (c *Cluster) SomeServices(ids []flux.ResourceID) (res []cluster.Service, err error) {
namespacedServices := map[string][]string{}
for _, id := range ids {
ns, name := id.Components()
Expand Down Expand Up @@ -207,7 +207,7 @@ func (c *Cluster) AllServices(namespace string) (res []cluster.Service, err erro
}

func (c *Cluster) makeService(ns string, service *v1.Service, controllers []podController) cluster.Service {
id := flux.MakeServiceID(ns, service.Name)
id := flux.MakeResourceID(ns, service.Name)
svc := cluster.Service{
ID: id,
IP: service.Spec.ClusterIP,
Expand Down
6 changes: 3 additions & 3 deletions cluster/kubernetes/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func (m *Manifests) ServicesWithPolicies(root string) (policy.ServiceMap, error)
return nil, err
}

result := map[flux.ServiceID]policy.Set{}
err = iterateManifests(all, func(s flux.ServiceID, m Manifest) error {
result := map[flux.ResourceID]policy.Set{}
err = iterateManifests(all, func(s flux.ResourceID, m Manifest) error {
ps, err := policiesFrom(m)
if err != nil {
return err
Expand All @@ -160,7 +160,7 @@ func (m *Manifests) ServicesWithPolicies(root string) (policy.ServiceMap, error)
return result, nil
}

func iterateManifests(services map[flux.ServiceID][]string, f func(flux.ServiceID, Manifest) error) error {
func iterateManifests(services map[flux.ResourceID][]string, f func(flux.ResourceID, Manifest) error) error {
for serviceID, paths := range services {
if len(paths) != 1 {
continue
Expand Down
2 changes: 1 addition & 1 deletion cluster/kubernetes/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Deployment struct {
Spec DeploymentSpec
}

func (o Deployment) ServiceIDs(all map[string]resource.Resource) []flux.ServiceID {
func (o Deployment) ServiceIDs(all map[string]resource.Resource) []flux.ResourceID {
found := flux.ServiceIDSet{}
// Look through all for any matching services
for _, r := range all {
Expand Down
2 changes: 1 addition & 1 deletion cluster/kubernetes/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (o *baseObject) debyte() {
}

// ServiceIDs reports the services that depend on this resource.
func (o baseObject) ServiceIDs(all map[string]resource.Resource) []flux.ServiceID {
func (o baseObject) ServiceIDs(all map[string]resource.Resource) []flux.ResourceID {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions cluster/kubernetes/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type Service struct {
Spec ServiceSpec `yaml:"spec"`
}

func (o Service) ServiceIDs(all map[string]resource.Resource) []flux.ServiceID {
func (o Service) ServiceIDs(all map[string]resource.Resource) []flux.ResourceID {
// A service is part of its own service id
ns := o.Meta.Namespace
if ns == "" {
ns = "default"
}
return []flux.ServiceID{flux.MustParseServiceID(fmt.Sprintf("%s/%s", ns, o.Meta.Name))}
return []flux.ResourceID{flux.MustParseResourceID(fmt.Sprintf("%s/%s", ns, o.Meta.Name))}
}

// Matches checks if this service's label selectors match the labels fo some
Expand Down Expand Up @@ -51,10 +51,10 @@ type ServicePort struct {
}

// This is handy when we want to talk about flux.Services
func (s Service) ServiceID() flux.ServiceID {
func (s Service) ServiceID() flux.ResourceID {
ns := s.Meta.Namespace
if ns == "" {
ns = "default"
}
return flux.MakeServiceID(ns, s.Meta.Name)
return flux.MakeResourceID(ns, s.Meta.Name)
}
10 changes: 5 additions & 5 deletions cluster/kubernetes/testfiles/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func WriteTestFiles(dir string) error {

// ServiceMap ... given a base path, construct the map representing the services
// given in the test data.
func ServiceMap(dir string) map[flux.ServiceID][]string {
return map[flux.ServiceID][]string{
flux.MustParseServiceID("default/helloworld"): []string{filepath.Join(dir, "helloworld-deploy.yaml")},
flux.MustParseServiceID("default/locked-service"): []string{filepath.Join(dir, "locked-service-deploy.yaml")},
flux.MustParseServiceID("default/test-service"): []string{filepath.Join(dir, "test-service-deploy.yaml")},
func ServiceMap(dir string) map[flux.ResourceID][]string {
return map[flux.ResourceID][]string{
flux.MustParseResourceID("default/helloworld"): []string{filepath.Join(dir, "helloworld-deploy.yaml")},
flux.MustParseResourceID("default/locked-service"): []string{filepath.Join(dir, "locked-service-deploy.yaml")},
flux.MustParseResourceID("default/test-service"): []string{filepath.Join(dir, "test-service-deploy.yaml")},
}
}

Expand Down
4 changes: 2 additions & 2 deletions cluster/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Manifests interface {
// Given a directory with manifest files, find which files define
// which services.
FindDefinedServices(path string) (map[flux.ServiceID][]string, error)
FindDefinedServices(path string) (map[flux.ResourceID][]string, error)
// Update the definitions in a manifests bytes according to the
// spec given.
UpdateDefinition(def []byte, container string, newImageID flux.ImageID) ([]byte, error)
Expand All @@ -32,7 +32,7 @@ type Manifests interface {
// UpdateManifest looks for the manifest for a given service, reads
// its contents, applies f(contents), and writes the results back to
// the file.
func UpdateManifest(m Manifests, root string, serviceID flux.ServiceID, f func(manifest []byte) ([]byte, error)) error {
func UpdateManifest(m Manifests, root string, serviceID flux.ResourceID, f func(manifest []byte) ([]byte, error)) error {
services, err := m.FindDefinedServices(root)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cluster/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
// Doubles as a cluster.Cluster and cluster.Manifests implementation
type Mock struct {
AllServicesFunc func(maybeNamespace string) ([]Service, error)
SomeServicesFunc func([]flux.ServiceID) ([]Service, error)
SomeServicesFunc func([]flux.ResourceID) ([]Service, error)
PingFunc func() error
ExportFunc func() ([]byte, error)
SyncFunc func(SyncDef) error
PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
FindDefinedServicesFunc func(path string) (map[flux.ServiceID][]string, error)
FindDefinedServicesFunc func(path string) (map[flux.ResourceID][]string, error)
UpdateDefinitionFunc func(def []byte, container string, newImageID flux.ImageID) ([]byte, error)
LoadManifestsFunc func(paths ...string) (map[string]resource.Resource, error)
ParseManifestsFunc func([]byte) (map[string]resource.Resource, error)
Expand All @@ -28,7 +28,7 @@ func (m *Mock) AllServices(maybeNamespace string) ([]Service, error) {
return m.AllServicesFunc(maybeNamespace)
}

func (m *Mock) SomeServices(s []flux.ServiceID) ([]Service, error) {
func (m *Mock) SomeServices(s []flux.ResourceID) ([]Service, error) {
return m.SomeServicesFunc(s)
}

Expand All @@ -48,7 +48,7 @@ func (m *Mock) PublicSSHKey(regenerate bool) (ssh.PublicKey, error) {
return m.PublicSSHKeyFunc(regenerate)
}

func (m *Mock) FindDefinedServices(path string) (map[flux.ServiceID][]string, error) {
func (m *Mock) FindDefinedServices(path string) (map[flux.ResourceID][]string, error) {
return m.FindDefinedServicesFunc(path)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/automate_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (opts *serviceAutomateOpts) RunE(cmd *cobra.Command, args []string) error {
return newUsageError("-s, --service is required")
}

serviceID, err := flux.ParseServiceID(opts.service)
serviceID, err := flux.ParseResourceID(opts.service)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/deautomate_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (opts *serviceDeautomateOpts) RunE(cmd *cobra.Command, args []string) error
return newUsageError("-s, --service is required")
}

serviceID, err := flux.ParseServiceID(opts.service)
serviceID, err := flux.ParseResourceID(opts.service)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/lock_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (opts *serviceLockOpts) RunE(cmd *cobra.Command, args []string) error {
return newUsageError("-s, --service is required")
}

serviceID, err := flux.ParseServiceID(opts.service)
serviceID, err := flux.ParseResourceID(opts.service)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (opts *servicePolicyOpts) RunE(cmd *cobra.Command, args []string) error {
return newUsageError("lock and unlock both specified")
}

serviceID, err := flux.ParseServiceID(opts.service)
serviceID, err := flux.ParseResourceID(opts.service)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/fluxctl/release_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (opts *serviceReleaseOpts) RunE(cmd *cobra.Command, args []string) error {
services = []update.ServiceSpec{update.ServiceSpecAll}
} else {
for _, service := range opts.services {
if _, err := flux.ParseServiceID(service); err != nil {
if _, err := flux.ParseResourceID(service); err != nil {
return err
}
services = append(services, update.ServiceSpec(service))
Expand All @@ -92,9 +92,9 @@ func (opts *serviceReleaseOpts) RunE(cmd *cobra.Command, args []string) error {
kind = update.ReleaseKindPlan
}

var excludes []flux.ServiceID
var excludes []flux.ResourceID
for _, exclude := range opts.exclude {
s, err := flux.ParseServiceID(exclude)
s, err := flux.ParseResourceID(exclude)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/unlock_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (opts *serviceUnlockOpts) RunE(cmd *cobra.Command, args []string) error {
return newUsageError("-s, --service is required")
}

serviceID, err := flux.ParseServiceID(opts.service)
serviceID, err := flux.ParseResourceID(opts.service)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/fluxsvc/fluxsvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func setup(t *testing.T) {
mockPlatform = &remote.MockPlatform{
ListServicesAnswer: []flux.ServiceStatus{
flux.ServiceStatus{
ID: flux.MustParseServiceID(helloWorldSvc),
ID: flux.MustParseResourceID(helloWorldSvc),
Status: "ok",
Containers: []flux.Container{
flux.Container{
Expand All @@ -90,7 +90,7 @@ func setup(t *testing.T) {
},
ListImagesAnswer: []flux.ImageStatus{
flux.ImageStatus{
ID: flux.MustParseServiceID(helloWorldSvc),
ID: flux.MustParseResourceID(helloWorldSvc),
Containers: []flux.Container{
flux.Container{
Name: "helloworld",
Expand All @@ -101,7 +101,7 @@ func setup(t *testing.T) {
},
},
flux.ImageStatus{
ID: flux.MustParseServiceID("a/another"),
ID: flux.MustParseResourceID("a/another"),
Containers: []flux.Container{
flux.Container{
Name: "helloworld",
Expand Down Expand Up @@ -276,8 +276,8 @@ func TestFluxsvc_History(t *testing.T) {
}
err := eventLogger.LogEvent("", history.Event{
Type: history.EventLock,
ServiceIDs: []flux.ServiceID{
flux.MustParseServiceID(helloWorldSvc),
ServiceIDs: []flux.ResourceID{
flux.MustParseResourceID(helloWorldSvc),
},
Message: "default/helloworld locked.",
})
Expand Down
8 changes: 4 additions & 4 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *Daemon) ListImages(spec update.ServiceSpec) ([]flux.ImageStatus, error)
if err != nil {
return nil, errors.Wrap(err, "treating service spec as ID")
}
services, err = d.Cluster.SomeServices([]flux.ServiceID{id})
services, err = d.Cluster.SomeServices([]flux.ResourceID{id})
}

images, err := update.CollectAvailableImages(d.Registry, services, d.Logger)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (d *Daemon) queueJob(do DaemonJobFunc) job.ID {
d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusSucceeded, Result: *metadata})
logger.Log("revision", metadata.Revision)
if metadata.Revision != "" {
var serviceIDs []flux.ServiceID
var serviceIDs []flux.ResourceID
for id, result := range metadata.Result {
if result.Status == update.ReleaseStatusSuccess {
serviceIDs = append(serviceIDs, id)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (d *Daemon) UpdateManifests(spec update.Spec) (job.ID, error) {
func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJobFunc {
return func(ctx context.Context, jobID job.ID, working *git.Checkout, logger log.Logger) (*history.CommitEventMetadata, error) {
// For each update
var serviceIDs []flux.ServiceID
var serviceIDs []flux.ResourceID
metadata := &history.CommitEventMetadata{
Spec: &spec,
Result: update.Result{},
Expand Down Expand Up @@ -466,7 +466,7 @@ func policyEvents(us policy.Updates, now time.Time) map[string]history.Event {
e, ok := eventsByType[eventType]
if !ok {
e = history.Event{
ServiceIDs: []flux.ServiceID{},
ServiceIDs: []flux.ResourceID{},
Type: eventType,
StartedAt: now,
EndedAt: now,
Expand Down
8 changes: 4 additions & 4 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func mockDaemon(t *testing.T) (*Daemon, func(), *cluster.Mock, history.EventRead
logger := log.NewNopLogger()

singleService := cluster.Service{
ID: flux.MustParseServiceID(svc),
ID: flux.MustParseResourceID(svc),
Containers: cluster.ContainersOrExcuse{
Containers: []cluster.Container{
{
Expand All @@ -321,7 +321,7 @@ func mockDaemon(t *testing.T) (*Daemon, func(), *cluster.Mock, history.EventRead
multiService := []cluster.Service{
singleService,
cluster.Service{
ID: flux.MakeServiceID("another", "service"),
ID: flux.MakeResourceID("another", "service"),
Containers: cluster.ContainersOrExcuse{
Containers: []cluster.Container{
{
Expand Down Expand Up @@ -366,7 +366,7 @@ func mockDaemon(t *testing.T) (*Daemon, func(), *cluster.Mock, history.EventRead
}
k8s.PingFunc = func() error { return nil }
k8s.ServicesWithPoliciesFunc = (&kubernetes.Manifests{}).ServicesWithPolicies
k8s.SomeServicesFunc = func([]flux.ServiceID) ([]cluster.Service, error) {
k8s.SomeServicesFunc = func([]flux.ResourceID) ([]cluster.Service, error) {
return []cluster.Service{
singleService,
}, nil
Expand Down Expand Up @@ -493,7 +493,7 @@ func updatePolicy(t *testing.T, d *Daemon) job.ID {
return updateManifest(t, d, update.Spec{
Type: update.Policy,
Spec: policy.Updates{
flux.MustParseServiceID("default/helloworld"): {
flux.MustParseResourceID("default/helloworld"): {
Add: policy.Set{
policy.Locked: "true",
},
Expand Down
2 changes: 1 addition & 1 deletion daemon/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (d *Daemon) pollForNewImages(logger log.Logger) {
}
}

func getTagPattern(services policy.ServiceMap, service flux.ServiceID, container string) string {
func getTagPattern(services policy.ServiceMap, service flux.ResourceID, container string) string {
policies := services[service]
if pattern, ok := policies.Get(policy.TagPrefix(container)); ok {
return strings.TrimPrefix(pattern, "glob:")
Expand Down
Loading

0 comments on commit 6f81af7

Please sign in to comment.