Skip to content

Commit

Permalink
Reconcile labels and annotations for configuration/route (kubeflow#64)
Browse files Browse the repository at this point in the history
* Reconcile labels and annotations for configuration/route

* Undo var name change
  • Loading branch information
hougangliu authored and k8s-ci-robot committed May 7, 2019
1 parent c178dd7 commit ae0e0c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/reconciler/ksvc/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (c *ServiceReconciler) ReconcileConfiguarion(ctx context.Context, desiredCo
log.Info("Reconciling configuration diff (-desired, +observed): %s", "diff", diff)

configuration.Spec = desiredConfiguration.Spec
configuration.ObjectMeta.Labels = desiredConfiguration.ObjectMeta.Labels
configuration.ObjectMeta.Annotations = desiredConfiguration.ObjectMeta.Annotations
log.Info("Updating configuration", "namespace", configuration.Namespace, "name", configuration.Name)
err = c.client.Update(context.TODO(), configuration)
if err != nil {
Expand Down Expand Up @@ -101,6 +103,8 @@ func (c *ServiceReconciler) ReconcileRoute(ctx context.Context, desiredRoute *kn
log.Info("Reconciling route diff (-desired, +observed): %s", "diff", diff)

route.Spec = desiredRoute.Spec
route.ObjectMeta.Labels = desiredRoute.ObjectMeta.Labels
route.ObjectMeta.Annotations = desiredRoute.ObjectMeta.Annotations
log.Info("Updating route", "namespace", route.Namespace, "name", route.Name)
err = c.client.Update(context.TODO(), route)
if err != nil {
Expand Down
61 changes: 59 additions & 2 deletions pkg/reconciler/ksvc/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ func TestKnativeConfigurationReconcile(t *testing.T) {
},
},
},
"Reconcile new labels and annotations": {
update: true,
desiredConfiguration: &knservingv1alpha1.Configuration{
ObjectMeta: metav1.ObjectMeta{
Name: "mnist",
Namespace: "default",
Labels: map[string]string{
"serving.knative.dev/configuration": "dream",
},
Annotations: map[string]string{
"serving.knative.dev/lastPinned": "1111111111",
},
},
Spec: knservingv1alpha1.ConfigurationSpec{
RevisionTemplate: &knservingv1alpha1.RevisionTemplateSpec{
Spec: knservingv1alpha1.RevisionSpec{
Container: &v1.Container{
Image: tensorflow.TensorflowServingImageName + ":" +
v1alpha1.DefaultTensorflowVersion,
Command: []string{tensorflow.TensorflowEntrypointCommand},
Args: []string{
"--port=" + tensorflow.TensorflowServingGRPCPort,
"--rest_api_port=" + tensorflow.TensorflowServingRestPort,
"--model_name=mnist",
"--model_base_path=s3://test/mnist/export",
},
},
},
},
},
},
},
}

serviceReconciler := NewServiceReconciler(c)
Expand All @@ -127,7 +159,7 @@ func TestKnativeConfigurationReconcile(t *testing.T) {
if err != nil {
t.Errorf("Test %q failed: returned error: %v", name, err)
}
if diff := cmp.Diff(scenario.desiredConfiguration.Spec, configuration.Spec); diff != "" {
if diff := cmp.Diff(scenario.desiredConfiguration, configuration); diff != "" {
t.Errorf("Test %q unexpected configuration (-want +got): %v", name, diff)
}
}
Expand Down Expand Up @@ -202,6 +234,31 @@ func TestKnativeRouteReconcile(t *testing.T) {
},
},
},
"Reconcile new labels and annotations": {
update: true,
desiredRoute: &knservingv1alpha1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: "mnist",
Namespace: "default",
Labels: map[string]string{
"serving.knative.dev/route": "dream",
},
Annotations: map[string]string{
"cherub": "rock",
},
},
Spec: knservingv1alpha1.RouteSpec{
Traffic: []knservingv1alpha1.TrafficTarget{
{
TrafficTarget: v1beta1.TrafficTarget{
ConfigurationName: "mnist-default",
Percent: 100,
},
},
},
},
},
},
}

serviceReconciler := NewServiceReconciler(c)
Expand All @@ -218,7 +275,7 @@ func TestKnativeRouteReconcile(t *testing.T) {
if err != nil {
t.Errorf("Test %q failed: returned error: %v", name, err)
}
if diff := cmp.Diff(scenario.desiredRoute.Spec, route.Spec); diff != "" {
if diff := cmp.Diff(scenario.desiredRoute, route); diff != "" {
t.Errorf("Test %q unexpected configuration (-want +got): %v", name, diff)
}
}
Expand Down

0 comments on commit ae0e0c2

Please sign in to comment.