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

Commit

Permalink
Rename service(s) to controller(s)
Browse files Browse the repository at this point in the history
There was a mixture of the term _service_ and _controller_ throughout the whole
codebase meaning the same thing. It was confusing for the newcomer and
unpleasant to read.

I don't know if the term _service_ was supposed to be an abstraction agnostic
to Kubernetes for _things which can be updated_ in a cluster. If so, it was
leaking considerably, including `fluxctl` and data structure names.

I left "service(s)" strings/identifiers as is were unavoidable to preserve
backwards compatibility (e.g. URL pathas and query parameters, serialized data
structure fields exposed to the http client etc ...).
  • Loading branch information
2opremio committed Feb 28, 2019
1 parent d76ecab commit 0d5cc37
Show file tree
Hide file tree
Showing 40 changed files with 489 additions and 489 deletions.
8 changes: 4 additions & 4 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 ListServicesOptions struct {
Namespace string
Services []flux.ResourceID
type ListControllersOptions struct {
Namespace string
Controllers []flux.ResourceID
}

type Server interface {
v10.Server

ListServicesWithOptions(ctx context.Context, opts ListServicesOptions) ([]v6.ControllerStatus, error)
ListControllersWithOptions(ctx context.Context, opts ListControllersOptions) ([]v6.ControllerStatus, error)
}

type Upstream interface {
Expand Down
2 changes: 1 addition & 1 deletion api/v6/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type NotDeprecated interface {
Export(context.Context) ([]byte, error)

// v6
ListServices(ctx context.Context, namespace string) ([]ControllerStatus, error)
ListControllers(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
18 changes: 9 additions & 9 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
"github.com/weaveworks/flux/policy"
)

// Constants for workload ready status. These are defined here so that
Expand Down Expand Up @@ -100,13 +100,13 @@ func (s Controller) ContainersOrError() ([]resource.Container, error) {

// These errors all represent logical problems with cluster
// configuration, and may be recoverable; e.g., it might be fine if a
// service does not have a matching RC/deployment.
// controller does not have a matching RC/deployment.
var (
ErrEmptySelector = errors.New("empty selector")
ErrWrongResourceKind = errors.New("new definition does not match existing resource")
ErrNoMatchingService = errors.New("no matching service")
ErrServiceHasNoSelector = errors.New("service has no selector")
ErrNoMatching = errors.New("no matching replication controllers or deployments")
ErrMultipleMatching = errors.New("multiple matching replication controllers or deployments")
ErrNoMatchingImages = errors.New("no matching images")
ErrEmptySelector = errors.New("empty selector")
ErrWrongResourceKind = errors.New("new definition does not match existing resource")
ErrNoMatchingController = errors.New("no matching controller")
ErrControllerHasNoSelector = errors.New("controller has no selector")
ErrNoMatching = errors.New("no matching replication controllers or deployments")
ErrMultipleMatching = errors.New("multiple matching replication controllers or deployments")
ErrNoMatchingImages = errors.New("no matching images")
)
4 changes: 2 additions & 2 deletions cluster/kubernetes/testfiles/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ var ResourceMap = map[flux.ResourceID]string{
flux.MustParseResourceID("default:daemonset/init"): "init.yaml",
}

// ServiceMap ... given a base path, construct the map representing
// ControllerMap ... given a base path, construct the map representing
// the services given in the test data. Must be kept in sync with
// `Files` below. TODO(michael): derive from ResourceMap, or similar.
func ServiceMap(dir string) map[flux.ResourceID][]string {
func ControllerMap(dir string) map[flux.ResourceID][]string {
return map[flux.ResourceID][]string{
flux.MustParseResourceID("default:deployment/helloworld"): []string{filepath.Join(dir, "helloworld-deploy.yaml")},
flux.MustParseResourceID("default:deployment/locked-service"): []string{filepath.Join(dir, "locked-service-deploy.yaml")},
Expand Down
22 changes: 11 additions & 11 deletions cluster/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (

// Doubles as a cluster.Cluster and cluster.Manifests implementation
type Mock struct {
AllServicesFunc func(maybeNamespace string) ([]Controller, error)
SomeServicesFunc func([]flux.ResourceID) ([]Controller, error)
PingFunc func() error
ExportFunc func() ([]byte, error)
SyncFunc func(SyncSet) error
PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
UpdateImageFunc func(def []byte, id flux.ResourceID, container string, newImageID image.Ref) ([]byte, error)
LoadManifestsFunc func(base string, paths []string) (map[string]resource.Resource, error)
UpdatePoliciesFunc func([]byte, flux.ResourceID, policy.Update) ([]byte, error)
AllControllersFunc func(maybeNamespace string) ([]Controller, error)
SomeControllersFunc func([]flux.ResourceID) ([]Controller, error)
PingFunc func() error
ExportFunc func() ([]byte, error)
SyncFunc func(SyncSet) error
PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
UpdateImageFunc func(def []byte, id flux.ResourceID, container string, newImageID image.Ref) ([]byte, error)
LoadManifestsFunc func(base string, paths []string) (map[string]resource.Resource, error)
UpdatePoliciesFunc func([]byte, flux.ResourceID, policy.Update) ([]byte, error)
}

func (m *Mock) AllControllers(maybeNamespace string) ([]Controller, error) {
return m.AllServicesFunc(maybeNamespace)
return m.AllControllersFunc(maybeNamespace)
}

func (m *Mock) SomeControllers(s []flux.ResourceID) ([]Controller, error) {
return m.SomeServicesFunc(s)
return m.SomeControllersFunc(s)
}

func (m *Mock) Ping() error {
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 @@ -17,7 +17,7 @@ type controllerAutomateOpts struct {
service string
}

func newServiceAutomate(parent *rootOpts) *controllerAutomateOpts {
func newControllerAutomate(parent *rootOpts) *controllerAutomateOpts {
return &controllerAutomateOpts{rootOpts: parent}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/list_controllers_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (opts *controllerListOpts) RunE(cmd *cobra.Command, args []string) error {

ctx := context.Background()

controllers, err := opts.API.ListServices(ctx, opts.namespace)
controllers, err := opts.API.ListControllers(ctx, opts.namespace)
if err != nil {
return err
}
Expand Down
42 changes: 21 additions & 21 deletions cmd/fluxctl/release_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error

ctx := context.Background()
spec := update.ReleaseImageSpec{
ServiceSpecs: controllers,
ImageSpec: image,
Kind: kind,
Excludes: excludes,
Force: opts.force,
ControllerSpecs: controllers,
ImageSpec: image,
Kind: kind,
Excludes: excludes,
Force: opts.force,
}
jobID, err := opts.API.UpdateManifests(ctx, update.Spec{
Type: update.Images,
Expand Down Expand Up @@ -196,28 +196,28 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error
fmt.Fprintf(cmd.OutOrStderr(), "Monitoring rollout ...\n")
for {
completed := 0
services, err := opts.API.ListServicesWithOptions(ctx, v11.ListServicesOptions{Services: result.Result.AffectedResources()})
controllers, err := opts.API.ListControllersWithOptions(ctx, v11.ListControllersOptions{Controllers: result.Result.AffectedResources()})
if err != nil {
return err
}

for _, service := range services {
writeRolloutStatus(service, opts.verbosity)
for _, controller := range controllers {
writeRolloutStatus(controller, opts.verbosity)

if service.Status == cluster.StatusReady {
if controller.Status == cluster.StatusReady {
completed++
}

if service.Rollout.Messages != nil {
fmt.Fprintf(cmd.OutOrStderr(), "There was a problem releasing %s:\n", service.ID)
for _, msg := range service.Rollout.Messages {
if controller.Rollout.Messages != nil {
fmt.Fprintf(cmd.OutOrStderr(), "There was a problem releasing %s:\n", controller.ID)
for _, msg := range controller.Rollout.Messages {
fmt.Fprintf(cmd.OutOrStderr(), "%s\n", msg)
}
return nil
}
}

if completed == len(services) {
if completed == len(controllers) {
fmt.Fprintf(cmd.OutOrStderr(), "All controllers ready.\n")
return nil
}
Expand All @@ -226,24 +226,24 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error
}
}

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

if len(service.Containers) > 0 {
c := service.Containers[0]
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d/%d", service.ID, c.Name, c.Current.ID, service.Status, service.Rollout.Updated, service.Rollout.Desired)
if len(controller.Containers) > 0 {
c := controller.Containers[0]
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d/%d", controller.ID, c.Name, c.Current.ID, controller.Status, controller.Rollout.Updated, controller.Rollout.Desired)
if verbosity > 0 {
fmt.Fprintf(w, " (%d outdated, %d ready)", service.Rollout.Outdated, service.Rollout.Ready)
fmt.Fprintf(w, " (%d outdated, %d ready)", controller.Rollout.Outdated, controller.Rollout.Ready)
}
fmt.Fprintf(w, "\n")
for _, c := range service.Containers[1:] {
for _, c := range controller.Containers[1:] {
fmt.Fprintf(w, "\t%s\t%s\t\t\n", c.Name, c.Current.ID)
}
} else {
fmt.Fprintf(w, "%s\t\t\t%s\t%d/%d", service.ID, service.Status, service.Rollout.Updated, service.Rollout.Desired)
fmt.Fprintf(w, "%s\t\t\t%s\t%d/%d", controller.ID, controller.Status, controller.Rollout.Updated, controller.Rollout.Desired)
if verbosity > 0 {
fmt.Fprintf(w, " (%d outdated, %d ready)", service.Rollout.Outdated, service.Rollout.Ready)
fmt.Fprintf(w, " (%d outdated, %d ready)", controller.Rollout.Outdated, controller.Rollout.Ready)
}
fmt.Fprintf(w, "\n")
}
Expand Down
30 changes: 15 additions & 15 deletions cmd/fluxctl/release_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ func TestReleaseCommand_CLIConversion(t *testing.T) {
expectedSpec update.ReleaseImageSpec
}{
{[]string{"--update-all-images", "--all"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
ControllerSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--all", "--dry-run"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindPlan,
ControllerSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindPlan,
}},
{[]string{"--update-image=alpine:latest", "--all"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: "alpine:latest",
Kind: update.ReleaseKindExecute,
ControllerSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: "alpine:latest",
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--controller=deployment/flux"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{"default:deployment/flux"},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
ControllerSpecs: []update.ResourceSpec{"default:deployment/flux"},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--all", "--exclude=deployment/test,deployment/yeah"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
ControllerSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Excludes: []flux.ResourceID{
flux.MustParseResourceID("default:deployment/test"),
flux.MustParseResourceID("default:deployment/yeah"),
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (opts *rootOpts) Command() *cobra.Command {
newControllerShow(opts).Command(),
newControllerList(opts).Command(),
newControllerRelease(opts).Command(),
newServiceAutomate(opts).Command(),
newControllerAutomate(opts).Command(),
newControllerDeautomate(opts).Command(),
newControllerLock(opts).Command(),
newControllerUnlock(opts).Command(),
Expand Down
Loading

0 comments on commit 0d5cc37

Please sign in to comment.