Skip to content

Commit

Permalink
Rename methods and fields in multiController for ease of reading
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Nov 25, 2019
1 parent a2ea38f commit b5e6d0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/canary/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
func NewController(kubeClient kubernetes.Interface, flaggerClient clientset.Interface, logger *zap.SugaredLogger,
labels []string) Controller {
return &multiController{
deployers: map[VersionKind]Controller{
controllersByVersionKind: map[VersionKind]Controller{
VersionKindDeployment: newDeploymentController(kubeClient, flaggerClient, logger, labels),
VersionKindService: newServiceController(kubeClient, flaggerClient, logger),
},
Expand Down
32 changes: 16 additions & 16 deletions pkg/canary/multi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,67 @@ import (
)

type multiController struct {
deployers map[VersionKind]Controller
controllersByVersionKind map[VersionKind]Controller
}

func (m *multiController) IsPrimaryReady(cd *v1alpha3.Canary) (bool, error) {
return m.deployer(cd).IsPrimaryReady(cd)
return m.controllerFor(cd).IsPrimaryReady(cd)
}

func (m *multiController) IsCanaryReady(cd *v1alpha3.Canary) (bool, error) {
return m.deployer(cd).IsCanaryReady(cd)
return m.controllerFor(cd).IsCanaryReady(cd)
}

func (m *multiController) HasConfigChanged(cd *v1alpha3.Canary) (bool, error) {
return m.deployer(cd).HasConfigChanged(cd)
return m.controllerFor(cd).HasConfigChanged(cd)
}

func (m *multiController) SyncStatus(cd *v1alpha3.Canary, status v1alpha3.CanaryStatus) error {
return m.deployer(cd).SyncStatus(cd, status)
return m.controllerFor(cd).SyncStatus(cd, status)
}

func (m *multiController) SetStatusFailedChecks(cd *v1alpha3.Canary, val int) error {
return m.deployer(cd).SetStatusFailedChecks(cd, val)
return m.controllerFor(cd).SetStatusFailedChecks(cd, val)
}

func (m *multiController) SetStatusWeight(cd *v1alpha3.Canary, val int) error {
return m.deployer(cd).SetStatusWeight(cd, val)
return m.controllerFor(cd).SetStatusWeight(cd, val)
}

func (m *multiController) SetStatusIterations(cd *v1alpha3.Canary, val int) error {
return m.deployer(cd).SetStatusIterations(cd, val)
return m.controllerFor(cd).SetStatusIterations(cd, val)
}

func (m *multiController) SetStatusPhase(cd *v1alpha3.Canary, phase v1alpha3.CanaryPhase) error {
return m.deployer(cd).SetStatusPhase(cd, phase)
return m.controllerFor(cd).SetStatusPhase(cd, phase)
}

func (m *multiController) deployer(cd *v1alpha3.Canary) Controller {
d, ok := m.deployers[NewVersionKind(cd.Spec.TargetRef.APIVersion, cd.Spec.TargetRef.Kind)]
func (m *multiController) controllerFor(cd *v1alpha3.Canary) Controller {
d, ok := m.controllersByVersionKind[NewVersionKind(cd.Spec.TargetRef.APIVersion, cd.Spec.TargetRef.Kind)]
if !ok {
panic(fmt.Errorf("unsupported apiVersion and kind: %s, %s", cd.Spec.TargetRef.APIVersion, cd.Spec.TargetRef.Kind))
}
return d
}

func (m *multiController) Initialize(cd *v1alpha3.Canary, skipLivenessChecks bool) (label string, ports map[string]int32, err error) {
return m.deployer(cd).Initialize(cd, skipLivenessChecks)
return m.controllerFor(cd).Initialize(cd, skipLivenessChecks)
}

func (m *multiController) Promote(cd *v1alpha3.Canary) error {
return m.deployer(cd).Promote(cd)
return m.controllerFor(cd).Promote(cd)
}

func (m *multiController) HasTargetChanged(cd *v1alpha3.Canary) (bool, error) {
return m.deployer(cd).HasTargetChanged(cd)
return m.controllerFor(cd).HasTargetChanged(cd)
}

func (m *multiController) Scale(cd *v1alpha3.Canary, replicas int32) error {
return m.deployer(cd).Scale(cd, replicas)
return m.controllerFor(cd).Scale(cd, replicas)
}

func (m *multiController) ScaleUp(cd *v1alpha3.Canary) error {
return m.deployer(cd).ScaleUp(cd)
return m.controllerFor(cd).ScaleUp(cd)
}

func (m *multiController) MakeStatusConditions(canaryStatus v1alpha3.CanaryStatus,
Expand Down

0 comments on commit b5e6d0b

Please sign in to comment.