Skip to content

Commit

Permalink
Clean up some old variable names (knative#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
grantr authored Feb 21, 2018
1 parent 594d12b commit 5986a58
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/configuration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,16 @@ func generateRevisionName(u *v1alpha1.Configuration) (string, error) {
}

func (c *Controller) updateStatus(u *v1alpha1.Configuration) (*v1alpha1.Configuration, error) {
rtClient := c.elaclientset.ElafrosV1alpha1().Configurations(u.Namespace)
newu, err := rtClient.Get(u.Name, metav1.GetOptions{})
configClient := c.elaclientset.ElafrosV1alpha1().Configurations(u.Namespace)
newu, err := configClient.Get(u.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
newu.Status = u.Status

// TODO: for CRD there's no updatestatus, so use normal update
return rtClient.Update(newu)
// return rtClient.UpdateStatus(newu)
return configClient.Update(newu)
// return configClient.UpdateStatus(newu)
}

func (c *Controller) addRevisionEvent(obj interface{}) {
Expand Down
32 changes: 16 additions & 16 deletions pkg/controller/route/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (c *Controller) processNextWorkItem() bool {
// Run the syncHandler, passing it the namespace/name string of the
// Foo resource to be synced.
if err := c.syncHandler(key); err != nil {
return fmt.Errorf("error syncing '%s': %s", key, err.Error())
return fmt.Errorf("error syncing %q: %s", key, err.Error())
}
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
Expand Down Expand Up @@ -268,10 +268,10 @@ func (c *Controller) syncHandler(key string) error {
}

// Get the Route resource with this namespace/name
es, err := c.lister.Routes(namespace).Get(name)
route, err := c.lister.Routes(namespace).Get(name)

// Don't modify the informers copy
es = es.DeepCopy()
route = route.DeepCopy()

if err != nil {
// The resource may no longer exist, in which case we stop
Expand All @@ -284,22 +284,22 @@ func (c *Controller) syncHandler(key string) error {
return err
}

glog.Infof("Running reconcile Route for %s\n%+v\n", es.Name, es)
glog.Infof("Running reconcile Route for %s\n%+v\n", route.Name, route)

// Create a placeholder service that is simply used by istio as a placeholder.
// This service could eventually be the 'router' service that will get all the
// fallthrough traffic if there are no route rules (revisions to target).
// This is one way to implement the 0->1. For now, we'll just create a placeholder
// that selects nothing.
glog.Infof("Creating/Updating placeholder k8s services")
err = c.createPlaceholderService(es, namespace)
err = c.createPlaceholderService(route, namespace)
if err != nil {
return err
}

// Then create the Ingress rule for this service
glog.Infof("Creating or updating ingress rule")
err = c.createOrUpdateIngress(es, namespace)
err = c.createOrUpdateIngress(route, namespace)
if err != nil {
if !apierrs.IsAlreadyExists(err) {
glog.Infof("Failed to create ingress rule: %s", err)
Expand All @@ -309,7 +309,7 @@ func (c *Controller) syncHandler(key string) error {

// Then create the actual route rules.
glog.Infof("Creating istio route rules")
routes, err := c.createOrUpdateRoutes(es, namespace)
routes, err := c.createOrUpdateRoutes(route, namespace)
if err != nil {
glog.Infof("Failed to create Routes: %s", err)
return err
Expand All @@ -325,9 +325,9 @@ func (c *Controller) syncHandler(key string) error {
Percent: r.Weight,
})
}
es.Status.Traffic = traffic
route.Status.Traffic = traffic
}
updated, err := c.updateStatus(es)
updated, err := c.updateStatus(route)
if err != nil {
glog.Warningf("Failed to update service status: %s", err)
return err
Expand Down Expand Up @@ -395,12 +395,12 @@ func (c *Controller) getRouteForTrafficTarget(tt v1alpha1.TrafficTarget, ns stri
// If template specified, fetch last revision otherwise use Revision
revisionName := tt.Revision
if tt.Configuration != "" {
rtClient := c.elaclientset.ElafrosV1alpha1().Configurations(ns)
rt, err := rtClient.Get(tt.Configuration, metav1.GetOptions{})
configClient := c.elaclientset.ElafrosV1alpha1().Configurations(ns)
config, err := configClient.Get(tt.Configuration, metav1.GetOptions{})
if err != nil {
return RevisionRoute{}, err
}
revisionName = rt.Status.LatestReady
revisionName = config.Status.LatestReady
}
prClient := c.elaclientset.ElafrosV1alpha1().Revisions(ns)
rev, err := prClient.Get(revisionName, metav1.GetOptions{})
Expand Down Expand Up @@ -457,14 +457,14 @@ func (c *Controller) createOrUpdateRoutes(u *v1alpha1.Route, ns string) ([]Revis
}

func (c *Controller) updateStatus(u *v1alpha1.Route) (*v1alpha1.Route, error) {
esClient := c.elaclientset.ElafrosV1alpha1().Routes(u.Namespace)
newu, err := esClient.Get(u.Name, metav1.GetOptions{})
routeClient := c.elaclientset.ElafrosV1alpha1().Routes(u.Namespace)
newu, err := routeClient.Get(u.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
newu.Status = u.Status

// TODO: for CRD there's no updatestatus, so use normal update
return esClient.Update(newu)
// return rtClient.UpdateStatus(newu)
return routeClient.Update(newu)
// return routeClient.UpdateStatus(newu)
}
18 changes: 9 additions & 9 deletions pkg/controller/route/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package route

/* TODO tests:
- When a ES is created:
- When a Route is created:
- a namespace is created
- When a Revision is updated TODO
Expand Down Expand Up @@ -106,11 +106,11 @@ func newRunningTestController(t *testing.T) (
func TestCreateHSCreatesStuff(t *testing.T) {
kubeClient, elaClient, _, _, _, stopCh := newRunningTestController(t)
defer close(stopCh)
es := getTestRoute()
route := getTestRoute()
h := hooks.NewHooks()

// Look for the placeholder service to be created.
expectedServiceName := fmt.Sprintf("%s-service", es.Name)
expectedServiceName := fmt.Sprintf("%s-service", route.Name)
h.OnCreate(&kubeClient.Fake, "services", func(obj runtime.Object) hooks.HookResult {
s := obj.(*corev1.Service)
glog.Infof("checking service %s", s.Name)
Expand All @@ -119,24 +119,24 @@ func TestCreateHSCreatesStuff(t *testing.T) {
}
//TODO(grantr): The expected namespace is currently the same as the
//Route namespace, but that may change to expectedNamespace.
if es.Namespace != s.Namespace {
t.Errorf("service namespace was %s, not %s", s.Namespace, es.Namespace)
if route.Namespace != s.Namespace {
t.Errorf("service namespace was %s, not %s", s.Namespace, route.Namespace)
}
//TODO nginx port
return hooks.HookComplete
})

// Look for the ingress.
expectedIngressName := fmt.Sprintf("%s-ela-ingress", es.Name)
expectedIngressName := fmt.Sprintf("%s-ela-ingress", route.Name)
h.OnCreate(&kubeClient.Fake, "ingresses", func(obj runtime.Object) hooks.HookResult {
i := obj.(*v1beta1.Ingress)
if expectedIngressName != i.Name {
t.Errorf("ingress was not named %s", expectedIngressName)
}
//TODO(grantr): The expected namespace is currently the same as the
//Route namespace, but that may change to expectedNamespace.
if es.Namespace != i.Namespace {
t.Errorf("ingress namespace was %s, not %s", i.Namespace, es.Namespace)
if route.Namespace != i.Namespace {
t.Errorf("ingress namespace was %s, not %s", i.Namespace, route.Namespace)
}
return hooks.HookComplete
})
Expand All @@ -154,7 +154,7 @@ func TestCreateHSCreatesStuff(t *testing.T) {
// Look for the route.
//TODO(grantr): routing is WIP so no tests yet

elaClient.ElafrosV1alpha1().Routes("test").Create(es)
elaClient.ElafrosV1alpha1().Routes("test").Create(route)

if err := h.WaitForHooks(time.Second * 3); err != nil {
t.Error(err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func createValidCreateConfiguration() *admissionv1beta1.AdmissionRequest {
Operation: admissionv1beta1.Create,
Kind: metav1.GroupVersionKind{Kind: "Configuration"},
}
rt := createConfiguration(0)
marshaled, err := yaml.Marshal(rt)
config := createConfiguration(0)
marshaled, err := yaml.Marshal(config)
if err != nil {
panic("failed to marshal configuration")
}
Expand All @@ -248,8 +248,8 @@ func createValidCreateRoute() *admissionv1beta1.AdmissionRequest {
Operation: admissionv1beta1.Create,
Kind: metav1.GroupVersionKind{Kind: "Route"},
}
rt := createRoute(0)
marshaled, err := yaml.Marshal(rt)
route := createRoute(0)
marshaled, err := yaml.Marshal(route)
if err != nil {
panic("failed to marshal route")
}
Expand Down

0 comments on commit 5986a58

Please sign in to comment.