From 6f81af7a920ba119e0da41b9c900c916d6fcb62e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 6 Sep 2017 10:00:37 +0100 Subject: [PATCH] gorename flux.ServiceID -> flux.ResourceID --- cluster/cluster.go | 4 +- cluster/kubernetes/files.go | 4 +- cluster/kubernetes/kubernetes.go | 4 +- cluster/kubernetes/policies.go | 6 +- cluster/kubernetes/resource/deployment.go | 2 +- cluster/kubernetes/resource/resource.go | 2 +- cluster/kubernetes/resource/service.go | 8 +-- cluster/kubernetes/testfiles/data.go | 10 +-- cluster/manifests.go | 4 +- cluster/mock.go | 8 +-- cmd/fluxctl/automate_cmd.go | 2 +- cmd/fluxctl/deautomate_cmd.go | 2 +- cmd/fluxctl/lock_cmd.go | 2 +- cmd/fluxctl/policy.go | 2 +- cmd/fluxctl/release_cmd.go | 6 +- cmd/fluxctl/unlock_cmd.go | 2 +- cmd/fluxsvc/fluxsvc_test.go | 10 +-- daemon/daemon.go | 8 +-- daemon/daemon_test.go | 8 +-- daemon/images.go | 2 +- daemon/loop_test.go | 26 ++++---- flux.go | 46 +++++++------- git/gittest/repo_test.go | 2 +- history/event.go | 2 +- history/history.go | 4 +- history/metrics.go | 2 +- history/mock.go | 2 +- history/sql/pg.go | 4 +- history/sql/ql.go | 4 +- history/sql/sql_test.go | 8 +-- http/daemon/server.go | 4 +- http/server/server.go | 4 +- notifications/notifications_test.go | 2 +- policy/policy.go | 10 +-- release/context.go | 6 +- release/releaser_test.go | 76 +++++++++++------------ remote/mock.go | 8 +-- resource/resource.go | 10 +-- server/server.go | 2 +- service/instance/events.go | 2 +- update/automated.go | 14 ++--- update/filter.go | 6 +- update/print.go | 2 +- update/print_test.go | 12 ++-- update/release.go | 14 ++--- update/result.go | 4 +- update/service.go | 2 +- 47 files changed, 187 insertions(+), 187 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index e83049762..923912534 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -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 @@ -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 diff --git a/cluster/kubernetes/files.go b/cluster/kubernetes/files.go index 62df84774..e5f71dafe 100644 --- a/cluster/kubernetes/files.go +++ b/cluster/kubernetes/files.go @@ -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") @@ -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 ) diff --git a/cluster/kubernetes/kubernetes.go b/cluster/kubernetes/kubernetes.go index b5921b426..8831f2fd6 100644 --- a/cluster/kubernetes/kubernetes.go +++ b/cluster/kubernetes/kubernetes.go @@ -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() @@ -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, diff --git a/cluster/kubernetes/policies.go b/cluster/kubernetes/policies.go index f9a99b05b..7e6e40fbe 100644 --- a/cluster/kubernetes/policies.go +++ b/cluster/kubernetes/policies.go @@ -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 @@ -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 diff --git a/cluster/kubernetes/resource/deployment.go b/cluster/kubernetes/resource/deployment.go index cb2cd0523..d5d7533ea 100644 --- a/cluster/kubernetes/resource/deployment.go +++ b/cluster/kubernetes/resource/deployment.go @@ -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 { diff --git a/cluster/kubernetes/resource/resource.go b/cluster/kubernetes/resource/resource.go index d0203b548..9e2d273f0 100644 --- a/cluster/kubernetes/resource/resource.go +++ b/cluster/kubernetes/resource/resource.go @@ -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 } diff --git a/cluster/kubernetes/resource/service.go b/cluster/kubernetes/resource/service.go index c56c8de79..a1f08b921 100644 --- a/cluster/kubernetes/resource/service.go +++ b/cluster/kubernetes/resource/service.go @@ -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 @@ -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) } diff --git a/cluster/kubernetes/testfiles/data.go b/cluster/kubernetes/testfiles/data.go index 08e206d11..76e72e087 100644 --- a/cluster/kubernetes/testfiles/data.go +++ b/cluster/kubernetes/testfiles/data.go @@ -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")}, } } diff --git a/cluster/manifests.go b/cluster/manifests.go index ff969f7e1..ace8c745a 100644 --- a/cluster/manifests.go +++ b/cluster/manifests.go @@ -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) @@ -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 diff --git a/cluster/mock.go b/cluster/mock.go index f28347fd3..e70f5afbc 100644 --- a/cluster/mock.go +++ b/cluster/mock.go @@ -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) @@ -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) } @@ -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) } diff --git a/cmd/fluxctl/automate_cmd.go b/cmd/fluxctl/automate_cmd.go index 16abec300..c40100dac 100644 --- a/cmd/fluxctl/automate_cmd.go +++ b/cmd/fluxctl/automate_cmd.go @@ -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 } diff --git a/cmd/fluxctl/deautomate_cmd.go b/cmd/fluxctl/deautomate_cmd.go index eea88d12f..478b93106 100644 --- a/cmd/fluxctl/deautomate_cmd.go +++ b/cmd/fluxctl/deautomate_cmd.go @@ -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 } diff --git a/cmd/fluxctl/lock_cmd.go b/cmd/fluxctl/lock_cmd.go index 694a41b19..37b8febc3 100644 --- a/cmd/fluxctl/lock_cmd.go +++ b/cmd/fluxctl/lock_cmd.go @@ -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 } diff --git a/cmd/fluxctl/policy.go b/cmd/fluxctl/policy.go index 9ba22c8a5..46b162435 100644 --- a/cmd/fluxctl/policy.go +++ b/cmd/fluxctl/policy.go @@ -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 } diff --git a/cmd/fluxctl/release_cmd.go b/cmd/fluxctl/release_cmd.go index 013e2291a..6464733b8 100644 --- a/cmd/fluxctl/release_cmd.go +++ b/cmd/fluxctl/release_cmd.go @@ -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)) @@ -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 } diff --git a/cmd/fluxctl/unlock_cmd.go b/cmd/fluxctl/unlock_cmd.go index 859a1ef8d..c3ed2e6b4 100644 --- a/cmd/fluxctl/unlock_cmd.go +++ b/cmd/fluxctl/unlock_cmd.go @@ -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 } diff --git a/cmd/fluxsvc/fluxsvc_test.go b/cmd/fluxsvc/fluxsvc_test.go index e2ddfdec8..5ceef4140 100644 --- a/cmd/fluxsvc/fluxsvc_test.go +++ b/cmd/fluxsvc/fluxsvc_test.go @@ -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{ @@ -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", @@ -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", @@ -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.", }) diff --git a/daemon/daemon.go b/daemon/daemon.go index 6fb49d809..2738b82be 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -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) @@ -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) @@ -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{}, @@ -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, diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index 0e0171f0a..e80f7f0b6 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -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{ { @@ -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{ { @@ -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 @@ -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", }, diff --git a/daemon/images.go b/daemon/images.go index d9a6c9b0d..8383d4bc7 100644 --- a/daemon/images.go +++ b/daemon/images.go @@ -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:") diff --git a/daemon/loop_test.go b/daemon/loop_test.go index 23f22b31f..6cc6257f9 100644 --- a/daemon/loop_test.go +++ b/daemon/loop_test.go @@ -91,9 +91,9 @@ func TestPullAndSync_InitialSync(t *testing.T) { syncCalled := 0 var syncDef *cluster.SyncDef expectedServiceIDs := flux.ServiceIDs{ - flux.MustParseServiceID("default/locked-service"), - flux.MustParseServiceID("default/test-service"), - flux.MustParseServiceID("default/helloworld")} + flux.MustParseResourceID("default/locked-service"), + flux.MustParseResourceID("default/test-service"), + flux.MustParseResourceID("default/helloworld")} expectedServiceIDs.Sort() k8s.SyncFunc = func(def cluster.SyncDef) error { syncCalled++ @@ -124,7 +124,7 @@ func TestPullAndSync_InitialSync(t *testing.T) { } else { gotServiceIDs := es[0].ServiceIDs flux.ServiceIDs(gotServiceIDs).Sort() - if !reflect.DeepEqual(gotServiceIDs, []flux.ServiceID(expectedServiceIDs)) { + if !reflect.DeepEqual(gotServiceIDs, []flux.ResourceID(expectedServiceIDs)) { t.Errorf("Unexpected event service ids: %#v, expected: %#v", gotServiceIDs, expectedServiceIDs) } } @@ -149,9 +149,9 @@ func TestDoSync_NoNewCommits(t *testing.T) { syncCalled := 0 var syncDef *cluster.SyncDef expectedServiceIDs := flux.ServiceIDs{ - flux.MustParseServiceID("default/locked-service"), - flux.MustParseServiceID("default/test-service"), - flux.MustParseServiceID("default/helloworld")} + flux.MustParseResourceID("default/locked-service"), + flux.MustParseResourceID("default/test-service"), + flux.MustParseResourceID("default/helloworld")} expectedServiceIDs.Sort() k8s.SyncFunc = func(def cluster.SyncDef) error { syncCalled++ @@ -206,7 +206,7 @@ func TestDoSync_WithNewCommit(t *testing.T) { t.Fatal(err) } // Push some new changes - if err := cluster.UpdateManifest(k8s, d.Checkout.ManifestDir(), flux.MustParseServiceID("default/helloworld"), func(def []byte) ([]byte, error) { + if err := cluster.UpdateManifest(k8s, d.Checkout.ManifestDir(), flux.MustParseResourceID("default/helloworld"), func(def []byte) ([]byte, error) { // A simple modification so we have changes to push return []byte(strings.Replace(string(def), "replicas: 5", "replicas: 4", -1)), nil }); err != nil { @@ -223,9 +223,9 @@ func TestDoSync_WithNewCommit(t *testing.T) { syncCalled := 0 var syncDef *cluster.SyncDef expectedServiceIDs := flux.ServiceIDs{ - flux.MustParseServiceID("default/locked-service"), - flux.MustParseServiceID("default/test-service"), - flux.MustParseServiceID("default/helloworld")} + flux.MustParseResourceID("default/locked-service"), + flux.MustParseResourceID("default/test-service"), + flux.MustParseResourceID("default/helloworld")} expectedServiceIDs.Sort() k8s.SyncFunc = func(def cluster.SyncDef) error { syncCalled++ @@ -257,8 +257,8 @@ func TestDoSync_WithNewCommit(t *testing.T) { gotServiceIDs := es[0].ServiceIDs flux.ServiceIDs(gotServiceIDs).Sort() // Event should only have changed service ids - if !reflect.DeepEqual(gotServiceIDs, []flux.ServiceID{flux.MustParseServiceID("default/helloworld")}) { - t.Errorf("Unexpected event service ids: %#v, expected: %#v", gotServiceIDs, []flux.ServiceID{flux.MustParseServiceID("default/helloworld")}) + if !reflect.DeepEqual(gotServiceIDs, []flux.ResourceID{flux.MustParseResourceID("default/helloworld")}) { + t.Errorf("Unexpected event service ids: %#v, expected: %#v", gotServiceIDs, []flux.ResourceID{flux.MustParseResourceID("default/helloworld")}) } } // It moves the tag diff --git a/flux.go b/flux.go index 723f25e5c..9cefe7e7f 100644 --- a/flux.go +++ b/flux.go @@ -26,58 +26,58 @@ func (t Token) Set(req *http.Request) { // (User) Service identifiers -type ServiceID struct { +type ResourceID struct { namespace string service string } -func (id ServiceID) String() string { +func (id ResourceID) String() string { return fmt.Sprintf("%s/%s", id.namespace, id.service) } -func ParseServiceID(s string) (ServiceID, error) { +func ParseResourceID(s string) (ResourceID, error) { toks := strings.SplitN(s, "/", 2) if len(toks) != 2 { - return ServiceID{}, errors.Wrap(ErrInvalidServiceID, "parsing "+s) + return ResourceID{}, errors.Wrap(ErrInvalidServiceID, "parsing "+s) } - return ServiceID{toks[0], toks[1]}, nil + return ResourceID{toks[0], toks[1]}, nil } -func MustParseServiceID(s string) ServiceID { - id, err := ParseServiceID(s) +func MustParseResourceID(s string) ResourceID { + id, err := ParseResourceID(s) if err != nil { panic(err) } return id } -func MakeServiceID(namespace, service string) ServiceID { - return ServiceID{namespace, service} +func MakeResourceID(namespace, service string) ResourceID { + return ResourceID{namespace, service} } -func (id ServiceID) Components() (namespace, service string) { +func (id ResourceID) Components() (namespace, service string) { return id.namespace, id.service } -func (id ServiceID) MarshalJSON() ([]byte, error) { +func (id ResourceID) MarshalJSON() ([]byte, error) { return json.Marshal(id.String()) } -func (id *ServiceID) UnmarshalJSON(data []byte) (err error) { +func (id *ResourceID) UnmarshalJSON(data []byte) (err error) { var str string if err := json.Unmarshal(data, &str); err != nil { return err } - *id, err = ParseServiceID(string(str)) + *id, err = ParseResourceID(string(str)) return err } -func (id ServiceID) MarshalText() (text []byte, err error) { +func (id ResourceID) MarshalText() (text []byte, err error) { return []byte(id.String()), nil } -func (id *ServiceID) UnmarshalText(text []byte) error { - result, err := ParseServiceID(string(text)) +func (id *ResourceID) UnmarshalText(text []byte) error { + result, err := ParseResourceID(string(text)) if err != nil { return err } @@ -85,7 +85,7 @@ func (id *ServiceID) UnmarshalText(text []byte) error { return nil } -type ServiceIDSet map[ServiceID]struct{} +type ServiceIDSet map[ResourceID]struct{} func (s ServiceIDSet) String() string { var ids []string @@ -95,7 +95,7 @@ func (s ServiceIDSet) String() string { return "{" + strings.Join(ids, ", ") + "}" } -func (s ServiceIDSet) Add(ids []ServiceID) { +func (s ServiceIDSet) Add(ids []ResourceID) { for _, id := range ids { s[id] = struct{}{} } @@ -114,7 +114,7 @@ func (s ServiceIDSet) Without(others ServiceIDSet) ServiceIDSet { return res } -func (s ServiceIDSet) Contains(id ServiceID) bool { +func (s ServiceIDSet) Contains(id ResourceID) bool { if s == nil { return false } @@ -148,7 +148,7 @@ func (s ServiceIDSet) ToSlice() ServiceIDs { return keys } -type ServiceIDs []ServiceID +type ServiceIDs []ResourceID func (p ServiceIDs) Len() int { return len(p) } func (p ServiceIDs) Less(i, j int) bool { return p[i].String() < p[j].String() } @@ -164,7 +164,7 @@ func (ids ServiceIDs) Without(others ServiceIDSet) (res ServiceIDs) { return res } -func (ids ServiceIDs) Contains(id ServiceID) bool { +func (ids ServiceIDs) Contains(id ResourceID) bool { set := ServiceIDSet{} set.Add(ids) return set.Contains(id) @@ -179,12 +179,12 @@ func (ids ServiceIDs) Intersection(others ServiceIDSet) ServiceIDSet { // -- types used in API type ImageStatus struct { - ID ServiceID + ID ResourceID Containers []Container } type ServiceStatus struct { - ID ServiceID + ID ResourceID Containers []Container Status string Automated bool diff --git a/git/gittest/repo_test.go b/git/gittest/repo_test.go index 63a4c4e91..6fb80f128 100644 --- a/git/gittest/repo_test.go +++ b/git/gittest/repo_test.go @@ -80,7 +80,7 @@ func TestCheckout(t *testing.T) { Spec: update.ReleaseSpec{}, }, Result: update.Result{ - flux.MustParseServiceID("default/service1"): update.ServiceResult{ + flux.MustParseResourceID("default/service1"): update.ServiceResult{ Status: update.ReleaseStatusFailed, Error: "failed the frobulator", }, diff --git a/history/event.go b/history/event.go index d1cb9ec51..577c42373 100644 --- a/history/event.go +++ b/history/event.go @@ -41,7 +41,7 @@ type Event struct { ID EventID `json:"id"` // ServiceIDs affected by this event. - ServiceIDs []flux.ServiceID `json:"serviceIDs"` + ServiceIDs []flux.ResourceID `json:"serviceIDs"` // Type is the type of event, usually "release" for now, but could be other // things later diff --git a/history/history.go b/history/history.go index 08c1f2bf7..038cf3927 100644 --- a/history/history.go +++ b/history/history.go @@ -25,7 +25,7 @@ type EventReader interface { // EventsForService returns the history for a particular // service. Events must be returned in descending timestamp order. - EventsForService(flux.ServiceID, time.Time, int64, time.Time) ([]Event, error) + EventsForService(flux.ResourceID, time.Time, int64, time.Time) ([]Event, error) // GetEvent finds a single event, by ID. GetEvent(EventID) (Event, error) @@ -34,7 +34,7 @@ type EventReader interface { type DB interface { LogEvent(service.InstanceID, Event) error AllEvents(service.InstanceID, time.Time, int64, time.Time) ([]Event, error) - EventsForService(service.InstanceID, flux.ServiceID, time.Time, int64, time.Time) ([]Event, error) + EventsForService(service.InstanceID, flux.ResourceID, time.Time, int64, time.Time) ([]Event, error) GetEvent(EventID) (Event, error) io.Closer } diff --git a/history/metrics.go b/history/metrics.go index da0863501..8c16d4517 100644 --- a/history/metrics.go +++ b/history/metrics.go @@ -54,7 +54,7 @@ func (i *instrumentedDB) AllEvents(inst service.InstanceID, before time.Time, li return i.db.AllEvents(inst, before, limit, after) } -func (i *instrumentedDB) EventsForService(inst service.InstanceID, s flux.ServiceID, before time.Time, limit int64, after time.Time) (e []Event, err error) { +func (i *instrumentedDB) EventsForService(inst service.InstanceID, s flux.ResourceID, before time.Time, limit int64, after time.Time) (e []Event, err error) { defer func(begin time.Time) { requestDuration.With( LabelMethod, "EventsForService", diff --git a/history/mock.go b/history/mock.go index 445097c8e..f16164bd2 100644 --- a/history/mock.go +++ b/history/mock.go @@ -23,7 +23,7 @@ func (m *Mock) AllEvents(_ time.Time, _ int64, _ time.Time) ([]Event, error) { return m.events, nil } -func (m *Mock) EventsForService(serviceID flux.ServiceID, _ time.Time, _ int64, _ time.Time) ([]Event, error) { +func (m *Mock) EventsForService(serviceID flux.ResourceID, _ time.Time, _ int64, _ time.Time) ([]Event, error) { m.RLock() defer m.RUnlock() var found []Event diff --git a/history/sql/pg.go b/history/sql/pg.go index cadefe9d5..f169cece1 100644 --- a/history/sql/pg.go +++ b/history/sql/pg.go @@ -55,7 +55,7 @@ func (db *pgDB) scanEvents(query squirrel.Sqlizer) ([]history.Event, error) { return nil, err } for _, id := range serviceIDs { - h.ServiceIDs = append(h.ServiceIDs, flux.MustParseServiceID(id)) + h.ServiceIDs = append(h.ServiceIDs, flux.MustParseResourceID(id)) } if len(metadataBytes) > 0 { @@ -91,7 +91,7 @@ func (db *pgDB) scanEvents(query squirrel.Sqlizer) ([]history.Event, error) { return events, rows.Err() } -func (db *pgDB) EventsForService(inst service.InstanceID, service flux.ServiceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { +func (db *pgDB) EventsForService(inst service.InstanceID, service flux.ResourceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { q := db.eventsQuery(). Where("instance_id = ?", string(inst)). Where("service_ids @> ?", pq.StringArray{service.String()}). diff --git a/history/sql/ql.go b/history/sql/ql.go index 93be49422..23f65be8d 100644 --- a/history/sql/ql.go +++ b/history/sql/ql.go @@ -85,7 +85,7 @@ func (db *qlDB) scanEvents(query squirrel.Sqlizer) ([]history.Event, error) { return events, rows.Err() } -func (db *qlDB) EventsForService(inst service.InstanceID, service flux.ServiceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { +func (db *qlDB) EventsForService(inst service.InstanceID, service flux.ResourceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { q := db.eventsQuery(). Where("instance_id = ?", string(inst)). Where("id(e) IN (select event_id from event_service_ids WHERE service_id = ?)", service.String()). @@ -139,7 +139,7 @@ func (db *qlDB) loadServiceIDs(events []history.Event) ([]history.Event, error) if err := rows.Scan(&id); err != nil { return nil, err } - e.ServiceIDs = append(e.ServiceIDs, flux.MustParseServiceID(id)) + e.ServiceIDs = append(e.ServiceIDs, flux.MustParseResourceID(id)) } if err := rows.Err(); err != nil { return nil, err diff --git a/history/sql/sql_test.go b/history/sql/sql_test.go index c5ce939b4..6e00fe063 100644 --- a/history/sql/sql_test.go +++ b/history/sql/sql_test.go @@ -58,22 +58,22 @@ func TestHistoryLog(t *testing.T) { defer db.Close() bailIfErr(t, db.LogEvent(instance, history.Event{ - ServiceIDs: []flux.ServiceID{flux.MustParseServiceID("namespace/service")}, + ServiceIDs: []flux.ResourceID{flux.MustParseResourceID("namespace/service")}, Type: "test", Message: "event 1", })) bailIfErr(t, db.LogEvent(instance, history.Event{ - ServiceIDs: []flux.ServiceID{flux.MustParseServiceID("namespace/other")}, + ServiceIDs: []flux.ResourceID{flux.MustParseResourceID("namespace/other")}, Type: "test", Message: "event 3", })) bailIfErr(t, db.LogEvent(instance, history.Event{ - ServiceIDs: []flux.ServiceID{flux.MustParseServiceID("namespace/service")}, + ServiceIDs: []flux.ResourceID{flux.MustParseResourceID("namespace/service")}, Type: "test", Message: "event 2", })) - es, err := db.EventsForService(instance, flux.MustParseServiceID("namespace/service"), time.Now().UTC(), -1, time.Unix(0, 0)) + es, err := db.EventsForService(instance, flux.MustParseResourceID("namespace/service"), time.Now().UTC(), -1, time.Unix(0, 0)) if err != nil { t.Fatal(err) } diff --git a/http/daemon/server.go b/http/daemon/server.go index 73f279c35..c259fae8e 100644 --- a/http/daemon/server.go +++ b/http/daemon/server.go @@ -140,9 +140,9 @@ func (s HTTPServer) UpdateImages(w http.ResponseWriter, r *http.Request) { return } - var excludes []flux.ServiceID + var excludes []flux.ResourceID for _, ex := range r.URL.Query()["exclude"] { - s, err := flux.ParseServiceID(ex) + s, err := flux.ParseResourceID(ex) if err != nil { transport.WriteError(w, r, http.StatusBadRequest, errors.Wrapf(err, "parsing excluded service %q", ex)) return diff --git a/http/server/server.go b/http/server/server.go index 457429c29..c9a060d43 100644 --- a/http/server/server.go +++ b/http/server/server.go @@ -182,9 +182,9 @@ func (s HTTPService) UpdateImages(w http.ResponseWriter, r *http.Request) { return } - var excludes []flux.ServiceID + var excludes []flux.ResourceID for _, ex := range r.URL.Query()["exclude"] { - s, err := flux.ParseServiceID(ex) + s, err := flux.ParseResourceID(ex) if err != nil { transport.WriteError(w, r, http.StatusBadRequest, errors.Wrapf(err, "parsing excluded service %q", ex)) return diff --git a/notifications/notifications_test.go b/notifications/notifications_test.go index 30deade47..bc739849b 100644 --- a/notifications/notifications_test.go +++ b/notifications/notifications_test.go @@ -17,7 +17,7 @@ func exampleRelease(t *testing.T) *history.ReleaseEventMetadata { img1a1, _ := flux.ParseImageID("img1:a1") img1a2, _ := flux.ParseImageID("img1:a2") exampleResult := update.Result{ - flux.MustParseServiceID("default/helloworld"): { + flux.MustParseResourceID("default/helloworld"): { Status: update.ReleaseStatusFailed, Error: "overall-release-error", PerContainer: []update.ContainerUpdate{ diff --git a/policy/policy.go b/policy/policy.go index 2ee3f3089..54b4cdb18 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -34,7 +34,7 @@ func Tag(policy Policy) bool { return strings.HasPrefix(string(policy), "tag.") } -type Updates map[flux.ServiceID]Update +type Updates map[flux.ResourceID]Update type Update struct { Add Set `json:"add"` @@ -110,17 +110,17 @@ func (s Set) ToStringMap() map[string]string { return m } -type ServiceMap map[flux.ServiceID]Set +type ServiceMap map[flux.ResourceID]Set -func (s ServiceMap) ToSlice() []flux.ServiceID { - slice := []flux.ServiceID{} +func (s ServiceMap) ToSlice() []flux.ResourceID { + slice := []flux.ResourceID{} for service, _ := range s { slice = append(slice, service) } return slice } -func (s ServiceMap) Contains(id flux.ServiceID) bool { +func (s ServiceMap) Contains(id flux.ResourceID) bool { _, ok := s[id] return ok } diff --git a/release/context.go b/release/context.go index 748f62017..ff8d40244 100644 --- a/release/context.go +++ b/release/context.go @@ -70,8 +70,8 @@ func (rc *ReleaseContext) SelectServices(results update.Result, filters ...updat return nil, err } - var ids []flux.ServiceID - definedMap := map[flux.ServiceID]*update.ServiceUpdate{} + var ids []flux.ResourceID + definedMap := map[flux.ResourceID]*update.ServiceUpdate{} for _, s := range defined { ids = append(ids, s.ServiceID) definedMap[s.ServiceID] = s @@ -107,7 +107,7 @@ func (rc *ReleaseContext) SelectServices(results update.Result, filters ...updat } // ... and missing services - filteredDefined := map[flux.ServiceID]*update.ServiceUpdate{} + filteredDefined := map[flux.ResourceID]*update.ServiceUpdate{} for k, s := range definedMap { fr := s.Filter(filters...) results[s.ServiceID] = fr diff --git a/release/releaser_test.go b/release/releaser_test.go index a5347f84c..7102194dc 100644 --- a/release/releaser_test.go +++ b/release/releaser_test.go @@ -24,7 +24,7 @@ var ( oldImageID, _ = flux.ParseImageID(oldImage) sidecarImage = "quay.io/weaveworks/sidecar:master-a000002" sidecarImageID, _ = flux.ParseImageID(sidecarImage) - hwSvcID, _ = flux.ParseServiceID("default/helloworld") + hwSvcID, _ = flux.ParseResourceID("default/helloworld") hwSvcSpec, _ = update.ParseServiceSpec(hwSvcID.String()) hwSvc = cluster.Service{ ID: hwSvcID, @@ -45,7 +45,7 @@ var ( oldLockedImg = "quay.io/weaveworks/locked-service:1" newLockedImg = "quay.io/weaveworks/locked-service:2" newLockedID, _ = flux.ParseImageID(newLockedImg) - lockedSvcID, _ = flux.ParseServiceID("default/locked-service") + lockedSvcID, _ = flux.ParseResourceID("default/locked-service") lockedSvcSpec, _ = update.ParseServiceSpec(lockedSvcID.String()) lockedSvc = cluster.Service{ ID: lockedSvcID, @@ -60,7 +60,7 @@ var ( } testSvc = cluster.Service{ - ID: flux.MustParseServiceID("default/test-service"), + ID: flux.MustParseResourceID("default/test-service"), Containers: cluster.ContainersOrExcuse{ Containers: []cluster.Container{ cluster.Container{ @@ -101,7 +101,7 @@ func Test_FilterLogic(t *testing.T) { AllServicesFunc: func(string) ([]cluster.Service, error) { return allSvcs, nil }, - SomeServicesFunc: func([]flux.ServiceID) ([]cluster.Service, error) { + SomeServicesFunc: func([]flux.ResourceID) ([]cluster.Service, error) { return []cluster.Service{ hwSvc, lockedSvc, @@ -123,10 +123,10 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{hwSvcSpec}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSuccess, PerContainer: []update.ContainerUpdate{ update.ContainerUpdate{ @@ -136,11 +136,11 @@ func Test_FilterLogic(t *testing.T) { }, }, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, @@ -151,10 +151,10 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{update.ServiceSpecAll}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{lockedSvcID}, + Excludes: []flux.ResourceID{lockedSvcID}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSuccess, PerContainer: []update.ContainerUpdate{ update.ContainerUpdate{ @@ -164,11 +164,11 @@ func Test_FilterLogic(t *testing.T) { }, }, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.Excluded, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.NotInCluster, }, @@ -179,10 +179,10 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{update.ServiceSpecAll}, ImageSpec: update.ImageSpecFromID(newImageID), Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSuccess, PerContainer: []update.ContainerUpdate{ update.ContainerUpdate{ @@ -192,11 +192,11 @@ func Test_FilterLogic(t *testing.T) { }, }, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.DifferentImage, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotInCluster, }, @@ -210,10 +210,10 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{update.ServiceSpecAll}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSuccess, PerContainer: []update.ContainerUpdate{ update.ContainerUpdate{ @@ -223,11 +223,11 @@ func Test_FilterLogic(t *testing.T) { }, }, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.Locked, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.NotInCluster, }, @@ -239,10 +239,10 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{hwSvcSpec, update.ServiceSpecAll}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSuccess, PerContainer: []update.ContainerUpdate{ update.ContainerUpdate{ @@ -252,11 +252,11 @@ func Test_FilterLogic(t *testing.T) { }, }, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.Locked, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.NotInCluster, }, @@ -268,22 +268,22 @@ func Test_FilterLogic(t *testing.T) { ServiceSpecs: []update.ServiceSpec{notInRepoSpec}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID(notInRepoService): update.ServiceResult{ + flux.MustParseResourceID(notInRepoService): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.NotInRepo, }, @@ -306,7 +306,7 @@ func Test_ImageStatus(t *testing.T) { AllServicesFunc: func(string) ([]cluster.Service, error) { return allSvcs, nil }, - SomeServicesFunc: func([]flux.ServiceID) ([]cluster.Service, error) { + SomeServicesFunc: func([]flux.ResourceID) ([]cluster.Service, error) { return []cluster.Service{ hwSvc, lockedSvc, @@ -338,18 +338,18 @@ func Test_ImageStatus(t *testing.T) { ServiceSpecs: []update.ServiceSpec{testSvcSpec}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.DoesNotUseImage, }, @@ -360,18 +360,18 @@ func Test_ImageStatus(t *testing.T) { ServiceSpecs: []update.ServiceSpec{hwSvcSpec}, ImageSpec: update.ImageSpecLatest, Kind: update.ReleaseKindExecute, - Excludes: []flux.ServiceID{}, + Excludes: []flux.ResourceID{}, }, Expected: update.Result{ - flux.MustParseServiceID("default/helloworld"): update.ServiceResult{ + flux.MustParseResourceID("default/helloworld"): update.ServiceResult{ Status: update.ReleaseStatusSkipped, Error: update.ImageUpToDate, }, - flux.MustParseServiceID("default/locked-service"): update.ServiceResult{ + flux.MustParseResourceID("default/locked-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, - flux.MustParseServiceID("default/test-service"): update.ServiceResult{ + flux.MustParseResourceID("default/test-service"): update.ServiceResult{ Status: update.ReleaseStatusIgnored, Error: update.NotIncluded, }, diff --git a/remote/mock.go b/remote/mock.go index bb4dae494..deafd2f42 100644 --- a/remote/mock.go +++ b/remote/mock.go @@ -98,8 +98,8 @@ var _ Platform = &MockPlatform{} func PlatformTestBattery(t *testing.T, wrap func(mock Platform) Platform) { // set up namespace := "the-space-of-names" - serviceID := flux.MustParseServiceID(namespace + "/service") - serviceList := []flux.ServiceID{serviceID} + serviceID := flux.MustParseResourceID(namespace + "/service") + serviceList := []flux.ResourceID{serviceID} services := flux.ServiceIDSet{} services.Add(serviceList) @@ -108,7 +108,7 @@ func PlatformTestBattery(t *testing.T, wrap func(mock Platform) Platform) { imageID, _ := flux.ParseImageID("quay.io/example.com/frob:v0.4.5") serviceAnswer := []flux.ServiceStatus{ flux.ServiceStatus{ - ID: flux.MustParseServiceID("foobar/hello"), + ID: flux.MustParseResourceID("foobar/hello"), Status: "ok", Containers: []flux.Container{ flux.Container{ @@ -125,7 +125,7 @@ func PlatformTestBattery(t *testing.T, wrap func(mock Platform) Platform) { imagesAnswer := []flux.ImageStatus{ flux.ImageStatus{ - ID: flux.MustParseServiceID("barfoo/yello"), + ID: flux.MustParseResourceID("barfoo/yello"), Containers: []flux.Container{ { Name: "flubnicator", diff --git a/resource/resource.go b/resource/resource.go index 0c1105377..95c819476 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -7,9 +7,9 @@ import ( // For the minute we just care about type Resource interface { - ResourceID() string // name, to correlate with what's in the cluster - ServiceIDs(map[string]Resource) []flux.ServiceID // ServiceIDs returns the associated services for this resource - Policy() policy.Set // policy for this resource; e.g., whether it is locked, automated, ignored - Source() string // where did this come from (informational) - Bytes() []byte // the definition, for sending to platform.Sync + ResourceID() string // name, to correlate with what's in the cluster + ServiceIDs(map[string]Resource) []flux.ResourceID // ServiceIDs returns the associated services for this resource + Policy() policy.Set // policy for this resource; e.g., whether it is locked, automated, ignored + Source() string // where did this come from (informational) + Bytes() []byte // the definition, for sending to platform.Sync } diff --git a/server/server.go b/server/server.go index 7d87bce64..627db5374 100644 --- a/server/server.go +++ b/server/server.go @@ -190,7 +190,7 @@ func (s *Server) History(inst service.InstanceID, spec update.ServiceSpec, befor return nil, errors.Wrap(err, "fetching all history events") } } else { - id, err := flux.ParseServiceID(string(spec)) + id, err := flux.ParseResourceID(string(spec)) if err != nil { return nil, errors.Wrapf(err, "parsing service ID from spec %s", spec) } diff --git a/service/instance/events.go b/service/instance/events.go index 6f6989da7..ababb1408 100644 --- a/service/instance/events.go +++ b/service/instance/events.go @@ -21,7 +21,7 @@ func (rw EventReadWriter) AllEvents(before time.Time, limit int64, after time.Ti return rw.db.AllEvents(rw.inst, before, limit, after) } -func (rw EventReadWriter) EventsForService(service flux.ServiceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { +func (rw EventReadWriter) EventsForService(service flux.ResourceID, before time.Time, limit int64, after time.Time) ([]history.Event, error) { return rw.db.EventsForService(rw.inst, service, before, limit, after) } diff --git a/update/automated.go b/update/automated.go index 35b994d61..47ec555f7 100644 --- a/update/automated.go +++ b/update/automated.go @@ -14,12 +14,12 @@ type Automated struct { } type Change struct { - ServiceID flux.ServiceID + ServiceID flux.ResourceID Container cluster.Container ImageID flux.ImageID } -func (a *Automated) Add(service flux.ServiceID, container cluster.Container, image flux.ImageID) { +func (a *Automated) Add(service flux.ResourceID, container cluster.Container, image flux.ImageID) { a.Changes = append(a.Changes, Change{service, container, image}) } @@ -147,18 +147,18 @@ func (a *Automated) calculateImageUpdates(rc ReleaseContext, candidates []*Servi return updates, nil } -func (a *Automated) serviceMap() map[flux.ServiceID][]Change { - set := map[flux.ServiceID][]Change{} +func (a *Automated) serviceMap() map[flux.ResourceID][]Change { + set := map[flux.ResourceID][]Change{} for _, change := range a.Changes { set[change.ServiceID] = append(set[change.ServiceID], change) } return set } -func (a *Automated) serviceIDs() []flux.ServiceID { - slice := []flux.ServiceID{} +func (a *Automated) serviceIDs() []flux.ResourceID { + slice := []flux.ResourceID{} for service, _ := range a.serviceMap() { - slice = append(slice, flux.MustParseServiceID(service.String())) + slice = append(slice, flux.MustParseResourceID(service.String())) } return slice } diff --git a/update/filter.go b/update/filter.go index f6129ab32..8ddec31df 100644 --- a/update/filter.go +++ b/update/filter.go @@ -42,7 +42,7 @@ func (f *SpecificImageFilter) Filter(u ServiceUpdate) ServiceResult { } type ExcludeFilter struct { - IDs []flux.ServiceID + IDs []flux.ResourceID } func (f *ExcludeFilter) Filter(u ServiceUpdate) ServiceResult { @@ -58,7 +58,7 @@ func (f *ExcludeFilter) Filter(u ServiceUpdate) ServiceResult { } type IncludeFilter struct { - IDs []flux.ServiceID + IDs []flux.ResourceID } func (f *IncludeFilter) Filter(u ServiceUpdate) ServiceResult { @@ -74,7 +74,7 @@ func (f *IncludeFilter) Filter(u ServiceUpdate) ServiceResult { } type LockedFilter struct { - IDs []flux.ServiceID + IDs []flux.ResourceID } func (f *LockedFilter) Filter(u ServiceUpdate) ServiceResult { diff --git a/update/print.go b/update/print.go index 90830f0c7..fd6dd24a1 100644 --- a/update/print.go +++ b/update/print.go @@ -12,7 +12,7 @@ func PrintResults(out io.Writer, results Result, verbose bool) { w := tabwriter.NewWriter(out, 0, 2, 2, ' ', 0) fmt.Fprintln(w, "SERVICE \tSTATUS \tUPDATES") for _, serviceID := range results.ServiceIDs() { - result := results[flux.MustParseServiceID(serviceID)] + result := results[flux.MustParseResourceID(serviceID)] switch result.Status { case ReleaseStatusIgnored: if !verbose { diff --git a/update/print_test.go b/update/print_test.go index 8d1ea778d..bb5ebb170 100644 --- a/update/print_test.go +++ b/update/print_test.go @@ -17,7 +17,7 @@ func TestPrintResults(t *testing.T) { { name: "basic, just results", result: Result{ - flux.MustParseServiceID("default/helloworld"): ServiceResult{ + flux.MustParseResourceID("default/helloworld"): ServiceResult{ Status: ReleaseStatusSuccess, Error: "", PerContainer: []ContainerUpdate{ @@ -38,7 +38,7 @@ default/helloworld success helloworld: quay.io/weaveworks/helloworld:master-a0 { name: "With an error, *and* results", result: Result{ - flux.MustParseServiceID("default/helloworld"): ServiceResult{ + flux.MustParseResourceID("default/helloworld"): ServiceResult{ Status: ReleaseStatusSuccess, Error: "test error", PerContainer: []ContainerUpdate{ @@ -60,10 +60,10 @@ default/helloworld success test error { name: "Service results should be sorted", result: Result{ - flux.MustParseServiceID("default/d"): ServiceResult{Status: ReleaseStatusSuccess}, - flux.MustParseServiceID("default/c"): ServiceResult{Status: ReleaseStatusSuccess}, - flux.MustParseServiceID("default/b"): ServiceResult{Status: ReleaseStatusSuccess}, - flux.MustParseServiceID("default/a"): ServiceResult{Status: ReleaseStatusSuccess}, + flux.MustParseResourceID("default/d"): ServiceResult{Status: ReleaseStatusSuccess}, + flux.MustParseResourceID("default/c"): ServiceResult{Status: ReleaseStatusSuccess}, + flux.MustParseResourceID("default/b"): ServiceResult{Status: ReleaseStatusSuccess}, + flux.MustParseResourceID("default/a"): ServiceResult{Status: ReleaseStatusSuccess}, }, expected: ` SERVICE STATUS UPDATES diff --git a/update/release.go b/update/release.go index 01cb31322..4b80e4deb 100644 --- a/update/release.go +++ b/update/release.go @@ -57,7 +57,7 @@ type ReleaseSpec struct { ServiceSpecs []ServiceSpec ImageSpec ImageSpec Kind ReleaseKind - Excludes []flux.ServiceID + Excludes []flux.ResourceID } // ReleaseType gives a one-word description of the release, mainly @@ -132,14 +132,14 @@ func (s ReleaseSpec) filters(rc ReleaseContext) ([]ServiceFilter, error) { } // Service filter - ids := []flux.ServiceID{} + ids := []flux.ResourceID{} for _, s := range s.ServiceSpecs { if s == ServiceSpecAll { // "" Overrides any other filters - ids = []flux.ServiceID{} + ids = []flux.ResourceID{} break } - id, err := flux.ParseServiceID(string(s)) + id, err := flux.ParseResourceID(string(s)) if err != nil { return nil, err } @@ -299,15 +299,15 @@ func ParseServiceSpec(s string) (ServiceSpec, error) { if s == string(ServiceSpecAll) { return ServiceSpecAll, nil } - id, err := flux.ParseServiceID(s) + id, err := flux.ParseResourceID(s) if err != nil { return "", errors.Wrap(err, "invalid service spec") } return ServiceSpec(id.String()), nil } -func (s ServiceSpec) AsID() (flux.ServiceID, error) { - return flux.ParseServiceID(string(s)) +func (s ServiceSpec) AsID() (flux.ResourceID, error) { + return flux.ParseResourceID(string(s)) } func (s ServiceSpec) String() string { diff --git a/update/result.go b/update/result.go index 8e83c44b8..485a0222a 100644 --- a/update/result.go +++ b/update/result.go @@ -18,7 +18,7 @@ const ( ReleaseStatusUnknown ServiceUpdateStatus = "unknown" ) -type Result map[flux.ServiceID]ServiceResult +type Result map[flux.ResourceID]ServiceResult func (r Result) ServiceIDs() []string { var result []string @@ -70,7 +70,7 @@ type ServiceResult struct { PerContainer []ContainerUpdate // what happened with each container } -func (fr ServiceResult) Msg(id flux.ServiceID) string { +func (fr ServiceResult) Msg(id flux.ResourceID) string { return fmt.Sprintf("%s service %s as it is %s", fr.Status, id.String(), fr.Error) } diff --git a/update/service.go b/update/service.go index 0d6fe7d16..d7d51cfd9 100644 --- a/update/service.go +++ b/update/service.go @@ -6,7 +6,7 @@ import ( ) type ServiceUpdate struct { - ServiceID flux.ServiceID + ServiceID flux.ResourceID Service cluster.Service ManifestPath string ManifestBytes []byte