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

Commit

Permalink
Revert all the renamings breaking the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Mar 5, 2019
1 parent 5ea5a71 commit 92a3aac
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 142 deletions.
6 changes: 3 additions & 3 deletions api/v11/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/weaveworks/flux/api/v6"
)

type ListWorkloadsOptions struct {
type ListServicesOptions struct {
Namespace string
Workloads []flux.ResourceID
Services []flux.ResourceID
}

type Server interface {
v10.Server

ListWorkloadsWithOptions(ctx context.Context, opts ListWorkloadsOptions) ([]v6.WorkloadStatus, error)
ListServicesWithOptions(ctx context.Context, opts ListServicesOptions) ([]v6.ControllerStatus, error)
}

type Upstream interface {
Expand Down
6 changes: 3 additions & 3 deletions api/v6/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ImageStatus struct {
Containers []Container
}

// ReadOnlyReason enumerates the reasons that a workload is
// ReadOnlyReason enumerates the reasons that a controller is
// considered read-only. The zero value is considered "OK", since the
// zero value is what prior versions of the daemon will effectively
// send.
Expand All @@ -30,7 +30,7 @@ const (
ReadOnlyNotReady ReadOnlyReason = "NotReady"
)

type WorkloadStatus struct {
type ControllerStatus struct {
ID flux.ResourceID
Containers []Container
ReadOnly ReadOnlyReason
Expand Down Expand Up @@ -68,7 +68,7 @@ type NotDeprecated interface {
Export(context.Context) ([]byte, error)

// v6
ListWorkloads(ctx context.Context, namespace string) ([]WorkloadStatus, error)
ListServices(ctx context.Context, namespace string) ([]ControllerStatus, error)
ListImages(ctx context.Context, spec update.ResourceSpec) ([]ImageStatus, error)
UpdateManifests(context.Context, update.Spec) (job.ID, error)
SyncStatus(ctx context.Context, ref string) ([]string, error)
Expand Down
6 changes: 3 additions & 3 deletions cmd/fluxctl/list_workloads_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (opts *workloadListOpts) RunE(cmd *cobra.Command, args []string) error {

ctx := context.Background()

workloads, err := opts.API.ListWorkloads(ctx, opts.namespace)
workloads, err := opts.API.ListServices(ctx, opts.namespace)
if err != nil {
return err
}
Expand All @@ -70,7 +70,7 @@ func (opts *workloadListOpts) RunE(cmd *cobra.Command, args []string) error {
return nil
}

type workloadStatusByName []v6.WorkloadStatus
type workloadStatusByName []v6.ControllerStatus

func (s workloadStatusByName) Len() int {
return len(s)
Expand All @@ -84,7 +84,7 @@ func (s workloadStatusByName) Swap(a, b int) {
s[a], s[b] = s[b], s[a]
}

func policies(s v6.WorkloadStatus) string {
func policies(s v6.ControllerStatus) string {
var ps []string
if s.Automated {
ps = append(ps, string(policy.Automated))
Expand Down
4 changes: 2 additions & 2 deletions cmd/fluxctl/release_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (opts *workloadReleaseOpts) RunE(cmd *cobra.Command, args []string) error {
fmt.Fprintf(cmd.OutOrStderr(), "Monitoring rollout ...\n")
for {
completed := 0
workloads, err := opts.API.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{Workloads: result.Result.AffectedResources()})
workloads, err := opts.API.ListServicesWithOptions(ctx, v11.ListServicesOptions{Services: result.Result.AffectedResources()})
if err != nil {
return err
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func (opts *workloadReleaseOpts) RunE(cmd *cobra.Command, args []string) error {
}
}

func writeRolloutStatus(workload v6.WorkloadStatus, verbosity int) {
func writeRolloutStatus(workload v6.ControllerStatus, verbosity int) {
w := newTabwriter()
fmt.Fprintf(w, "WORKLOAD\tCONTAINER\tIMAGE\tRELEASE\tREPLICAS\n")

Expand Down
16 changes: 8 additions & 8 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ func (d *Daemon) getResources(ctx context.Context) (map[string]resource.Resource
return resources, globalReadOnly, nil
}

func (d *Daemon) ListWorkloads(ctx context.Context, namespace string) ([]v6.WorkloadStatus, error) {
return d.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{Namespace: namespace})
func (d *Daemon) ListServices(ctx context.Context, namespace string) ([]v6.ControllerStatus, error) {
return d.ListServicesWithOptions(ctx, v11.ListServicesOptions{Namespace: namespace})
}

func (d *Daemon) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWorkloadsOptions) ([]v6.WorkloadStatus, error) {
if opts.Namespace != "" && len(opts.Workloads) > 0 {
func (d *Daemon) ListServicesWithOptions(ctx context.Context, opts v11.ListServicesOptions) ([]v6.ControllerStatus, error) {
if opts.Namespace != "" && len(opts.Services) > 0 {
return nil, errors.New("cannot filter by 'namespace' and 'workloads' at the same time")
}

var clusterWorkloads []cluster.Workload
var err error
if len(opts.Workloads) > 0 {
clusterWorkloads, err = d.Cluster.SomeWorkloads(opts.Workloads)
if len(opts.Services) > 0 {
clusterWorkloads, err = d.Cluster.SomeWorkloads(opts.Services)
} else {
clusterWorkloads, err = d.Cluster.AllWorkloads(opts.Namespace)
}
Expand All @@ -123,7 +123,7 @@ func (d *Daemon) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWork
return nil, err
}

var res []v6.WorkloadStatus
var res []v6.ControllerStatus
for _, workload := range clusterWorkloads {
readOnly := v6.ReadOnlyOK
var policies policy.Set
Expand All @@ -140,7 +140,7 @@ func (d *Daemon) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWork
if workload.SyncError != nil {
syncError = workload.SyncError.Error()
}
res = append(res, v6.WorkloadStatus{
res = append(res, v6.ControllerStatus{
ID: workload.ID,
Containers: containers2containers(workload.ContainersOrNil()),
ReadOnly: readOnly,
Expand Down
14 changes: 7 additions & 7 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestDaemon_ListWorkloads(t *testing.T) {
ctx := context.Background()

// No namespace
s, err := d.ListWorkloads(ctx, "")
s, err := d.ListServices(ctx, "")
if err != nil {
t.Fatalf("Error: %s", err.Error())
}
Expand All @@ -116,7 +116,7 @@ func TestDaemon_ListWorkloads(t *testing.T) {
}

// Just namespace
s, err = d.ListWorkloads(ctx, ns)
s, err = d.ListServices(ctx, ns)
if err != nil {
t.Fatalf("Error: %s", err.Error())
}
Expand All @@ -125,7 +125,7 @@ func TestDaemon_ListWorkloads(t *testing.T) {
}

// Invalid NS
s, err = d.ListWorkloads(ctx, invalidNS)
s, err = d.ListServices(ctx, invalidNS)
if err != nil {
t.Fatalf("Error: %s", err.Error())
}
Expand All @@ -143,7 +143,7 @@ func TestDaemon_ListWorkloadsWithOptions(t *testing.T) {
ctx := context.Background()

t.Run("no filter", func(t *testing.T) {
s, err := d.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{})
s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{})
if err != nil {
t.Fatalf("Error: %s", err.Error())
}
Expand All @@ -152,7 +152,7 @@ func TestDaemon_ListWorkloadsWithOptions(t *testing.T) {
}
})
t.Run("filter id", func(t *testing.T) {
s, err := d.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{
s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "",
Services: []flux.ResourceID{flux.MustParseResourceID(wl)}})
if err != nil {
Expand All @@ -164,7 +164,7 @@ func TestDaemon_ListWorkloadsWithOptions(t *testing.T) {
})

t.Run("filter id and namespace", func(t *testing.T) {
_, err := d.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{
_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "foo",
Services: []flux.ResourceID{flux.MustParseResourceID(wl)}})
if err == nil {
Expand All @@ -173,7 +173,7 @@ func TestDaemon_ListWorkloadsWithOptions(t *testing.T) {
})

t.Run("filter unsupported id kind", func(t *testing.T) {
_, err := d.ListWorkloadsWithOptions(ctx, v11.ListWorkloadsOptions{
_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "foo",
Services: []flux.ResourceID{flux.MustParseResourceID("default:unsupportedkind/goodbyeworld")}})
if err == nil {
Expand Down
14 changes: 7 additions & 7 deletions http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ func New(c *http.Client, router *mux.Router, endpoint string, t Token) *Client {
}
}

func (c *Client) ListWorkloads(ctx context.Context, namespace string) ([]v6.WorkloadStatus, error) {
var res []v6.WorkloadStatus
err := c.Get(ctx, &res, transport.ListWorkloads, "namespace", namespace)
func (c *Client) ListServices(ctx context.Context, namespace string) ([]v6.ControllerStatus, error) {
var res []v6.ControllerStatus
err := c.Get(ctx, &res, transport.ListServices, "namespace", namespace)
return res, err
}

func (c *Client) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWorkloadsOptions) ([]v6.WorkloadStatus, error) {
var res []v6.WorkloadStatus
func (c *Client) ListServicesWithOptions(ctx context.Context, opts v11.ListServicesOptions) ([]v6.ControllerStatus, error) {
var res []v6.ControllerStatus
var services []string
for _, svc := range opts.Workloads {
for _, svc := range opts.Services {
services = append(services, svc.String())
}
err := c.Get(ctx, &res, transport.ListWorkloadsWithOptions, "namespace", opts.Namespace, "services", strings.Join(services, ","))
err := c.Get(ctx, &res, transport.ListServicesWithOptions, "namespace", opts.Namespace, "services", strings.Join(services, ","))
return res, err
}

Expand Down
12 changes: 6 additions & 6 deletions http/daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewRouter() *mux.Router {

func NewHandler(s api.Server, r *mux.Router) http.Handler {
handle := HTTPServer{s}
r.Get(transport.ListWorkloads).HandlerFunc(handle.ListWorkloadsWithOptions)
r.Get(transport.ListWorkloadsWithOptions).HandlerFunc(handle.ListWorkloadsWithOptions)
r.Get(transport.ListServices).HandlerFunc(handle.ListServicesWithOptions)
r.Get(transport.ListServicesWithOptions).HandlerFunc(handle.ListServicesWithOptions)
r.Get(transport.ListImages).HandlerFunc(handle.ListImagesWithOptions)
r.Get(transport.ListImagesWithOptions).HandlerFunc(handle.ListImagesWithOptions)
r.Get(transport.UpdateManifests).HandlerFunc(handle.UpdateManifests)
Expand Down Expand Up @@ -146,8 +146,8 @@ func (s HTTPServer) UpdateManifests(w http.ResponseWriter, r *http.Request) {
transport.JSONResponse(w, r, jobID)
}

func (s HTTPServer) ListWorkloadsWithOptions(w http.ResponseWriter, r *http.Request) {
var opts v11.ListWorkloadsOptions
func (s HTTPServer) ListServicesWithOptions(w http.ResponseWriter, r *http.Request) {
var opts v11.ListServicesOptions
opts.Namespace = r.URL.Query().Get("namespace")
services := r.URL.Query().Get("services")
if services != "" {
Expand All @@ -157,11 +157,11 @@ func (s HTTPServer) ListWorkloadsWithOptions(w http.ResponseWriter, r *http.Requ
transport.WriteError(w, r, http.StatusBadRequest, errors.Wrapf(err, "parsing service spec %q", svc))
return
}
opts.Workloads = append(opts.Workloads, id)
opts.Services = append(opts.Services, id)
}
}

res, err := s.server.ListWorkloadsWithOptions(r.Context(), opts)
res, err := s.server.ListServicesWithOptions(r.Context(), opts)
if err != nil {
transport.ErrorResponse(w, r, err)
return
Expand Down
18 changes: 9 additions & 9 deletions http/routes.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package http

const (
ListWorkloads = "ListWorkloads"
ListWorkloadsWithOptions = "ListWorkloadsWithOptions"
ListImages = "ListImages"
ListImagesWithOptions = "ListImagesWithOptions"
UpdateManifests = "UpdateManifests"
JobStatus = "JobStatus"
SyncStatus = "SyncStatus"
Export = "Export"
GitRepoConfig = "GitRepoConfig"
ListServices = "ListServices"
ListServicesWithOptions = "ListServicesWithOptions"
ListImages = "ListImages"
ListImagesWithOptions = "ListImagesWithOptions"
UpdateManifests = "UpdateManifests"
JobStatus = "JobStatus"
SyncStatus = "SyncStatus"
Export = "Export"
GitRepoConfig = "GitRepoConfig"

UpdateImages = "UpdateImages"
UpdatePolicies = "UpdatePolicies"
Expand Down
4 changes: 2 additions & 2 deletions http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func DeprecateVersions(r *mux.Router, versions ...string) {
func NewAPIRouter() *mux.Router {
r := mux.NewRouter()

r.NewRoute().Name(ListWorkloads).Methods("GET").Path("/v6/services")
r.NewRoute().Name(ListWorkloadsWithOptions).Methods("GET").Path("/v11/services")
r.NewRoute().Name(ListServices).Methods("GET").Path("/v6/services")
r.NewRoute().Name(ListServicesWithOptions).Methods("GET").Path("/v11/services")
r.NewRoute().Name(ListImages).Methods("GET").Path("/v6/images")
r.NewRoute().Name(ListImagesWithOptions).Methods("GET").Path("/v10/images")

Expand Down
12 changes: 6 additions & 6 deletions remote/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ func (p *ErrorLoggingServer) Export(ctx context.Context) (config []byte, err err
return p.server.Export(ctx)
}

func (p *ErrorLoggingServer) ListWorkloads(ctx context.Context, maybeNamespace string) (_ []v6.WorkloadStatus, err error) {
func (p *ErrorLoggingServer) ListServices(ctx context.Context, maybeNamespace string) (_ []v6.ControllerStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListWorkloads", "error", err)
p.logger.Log("method", "ListServices", "error", err)
}
}()
return p.server.ListWorkloads(ctx, maybeNamespace)
return p.server.ListServices(ctx, maybeNamespace)
}

func (p *ErrorLoggingServer) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWorkloadsOptions) (_ []v6.WorkloadStatus, err error) {
func (p *ErrorLoggingServer) ListServicesWithOptions(ctx context.Context, opts v11.ListServicesOptions) (_ []v6.ControllerStatus, err error) {
defer func() {
if err != nil {
p.logger.Log("method", "ListWorkloadsWithOptions", "error", err)
p.logger.Log("method", "ListServicesWithOptions", "error", err)
}
}()
return p.server.ListWorkloadsWithOptions(ctx, opts)
return p.server.ListServicesWithOptions(ctx, opts)
}

func (p *ErrorLoggingServer) ListImages(ctx context.Context, spec update.ResourceSpec) (_ []v6.ImageStatus, err error) {
Expand Down
12 changes: 6 additions & 6 deletions remote/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ func (i *instrumentedServer) Export(ctx context.Context) (config []byte, err err
return i.s.Export(ctx)
}

func (i *instrumentedServer) ListWorkloads(ctx context.Context, namespace string) (_ []v6.WorkloadStatus, err error) {
func (i *instrumentedServer) ListServices(ctx context.Context, namespace string) (_ []v6.ControllerStatus, err error) {
defer func(begin time.Time) {
requestDuration.With(
fluxmetrics.LabelMethod, "ListWorkloads",
fluxmetrics.LabelMethod, "ListServices",
fluxmetrics.LabelSuccess, fmt.Sprint(err == nil),
).Observe(time.Since(begin).Seconds())
}(time.Now())
return i.s.ListWorkloads(ctx, namespace)
return i.s.ListServices(ctx, namespace)
}

func (i *instrumentedServer) ListWorkloadsWithOptions(ctx context.Context, opts v11.ListWorkloadsOptions) (_ []v6.WorkloadStatus, err error) {
func (i *instrumentedServer) ListServicesWithOptions(ctx context.Context, opts v11.ListServicesOptions) (_ []v6.ControllerStatus, err error) {
defer func(begin time.Time) {
requestDuration.With(
fluxmetrics.LabelMethod, "ListWorkloadsWithOptions",
fluxmetrics.LabelMethod, "ListServicesWithOptions",
fluxmetrics.LabelSuccess, fmt.Sprint(err == nil),
).Observe(time.Since(begin).Seconds())
}(time.Now())
return i.s.ListWorkloadsWithOptions(ctx, opts)
return i.s.ListServicesWithOptions(ctx, opts)
}

func (i *instrumentedServer) ListImages(ctx context.Context, spec update.ResourceSpec) (_ []v6.ImageStatus, err error) {
Expand Down
Loading

0 comments on commit 92a3aac

Please sign in to comment.