Skip to content

Commit

Permalink
Migrate serving to istio.io/client-go apis (#6041)
Browse files Browse the repository at this point in the history
* Update knative.dev/pkg

* Switch serving to istio's client apis
  • Loading branch information
Slavomir Kaslev authored and knative-prow-robot committed Nov 26, 2019
1 parent 3f8b4a0 commit 197028d
Show file tree
Hide file tree
Showing 341 changed files with 77,842 additions and 10,145 deletions.
108 changes: 63 additions & 45 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ required = [
name = "github.com/jetstack/cert-manager"
version = "v0.9.1"

[[constraint]]
name = "github.com/gogo/protobuf"
version = "v1.3.1"

[[constraint]]
name = "istio.io/api"
version = "1.4.0-beta.4"

[[constraint]]
name = "istio.io/client-go"
version = "1.4.0-beta.2"

[[override]]
name = "k8s.io/api"
version = "kubernetes-1.15.3"
Expand Down
12 changes: 6 additions & 6 deletions pkg/reconciler/accessor/istio/virtualservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import (
"context"
"fmt"

"istio.io/client-go/pkg/apis/networking/v1alpha3"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis/istio/v1alpha3"
sharedclientset "knative.dev/pkg/client/clientset/versioned"
istiolisters "knative.dev/pkg/client/listers/istio/v1alpha3"
istioclientset "knative.dev/pkg/client/istio/clientset/versioned"
istiolisters "knative.dev/pkg/client/istio/listers/networking/v1alpha3"
"knative.dev/pkg/controller"
"knative.dev/pkg/kmeta"
kaccessor "knative.dev/serving/pkg/reconciler/accessor"
)

// VirtualServiceAccessor is an interface for accessing VirtualService.
type VirtualServiceAccessor interface {
GetSharedClient() sharedclientset.Interface
GetIstioClient() istioclientset.Interface
GetVirtualServiceLister() istiolisters.VirtualServiceLister
}

Expand All @@ -50,7 +50,7 @@ func ReconcileVirtualService(ctx context.Context, owner kmeta.Accessor, desired
name := desired.Name
vs, err := vsAccessor.GetVirtualServiceLister().VirtualServices(ns).Get(name)
if apierrs.IsNotFound(err) {
vs, err = vsAccessor.GetSharedClient().NetworkingV1alpha3().VirtualServices(ns).Create(desired)
vs, err = vsAccessor.GetIstioClient().NetworkingV1alpha3().VirtualServices(ns).Create(desired)
if err != nil {
recorder.Eventf(owner, corev1.EventTypeWarning, "CreationFailed",
"Failed to create VirtualService %s/%s: %v", ns, name, err)
Expand All @@ -68,7 +68,7 @@ func ReconcileVirtualService(ctx context.Context, owner kmeta.Accessor, desired
// Don't modify the informers copy
existing := vs.DeepCopy()
existing.Spec = desired.Spec
vs, err = vsAccessor.GetSharedClient().NetworkingV1alpha3().VirtualServices(ns).Update(existing)
vs, err = vsAccessor.GetIstioClient().NetworkingV1alpha3().VirtualServices(ns).Update(existing)
if err != nil {
return nil, fmt.Errorf("failed to update VirtualService: %w", err)
}
Expand Down
41 changes: 21 additions & 20 deletions pkg/reconciler/accessor/istio/virtualservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (
"time"

"github.com/google/go-cmp/cmp"
istiov1alpha3 "istio.io/api/networking/v1alpha3"
"istio.io/client-go/pkg/apis/networking/v1alpha3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/pkg/apis/istio/v1alpha3"
sharedclientset "knative.dev/pkg/client/clientset/versioned"
sharedfake "knative.dev/pkg/client/clientset/versioned/fake"
informers "knative.dev/pkg/client/informers/externalversions"
fakesharedclient "knative.dev/pkg/client/injection/client/fake"
istiolisters "knative.dev/pkg/client/listers/istio/v1alpha3"
istioclientset "knative.dev/pkg/client/istio/clientset/versioned"
istiofake "knative.dev/pkg/client/istio/clientset/versioned/fake"
istioinformers "knative.dev/pkg/client/istio/informers/externalversions"
fakeistioclient "knative.dev/pkg/client/istio/injection/client/fake"
istiolisters "knative.dev/pkg/client/istio/listers/networking/v1alpha3"
"knative.dev/pkg/controller"
"knative.dev/pkg/ptr"

Expand Down Expand Up @@ -59,7 +60,7 @@ var (
Namespace: "default",
OwnerReferences: []metav1.OwnerReference{ownerRef},
},
Spec: v1alpha3.VirtualServiceSpec{
Spec: istiov1alpha3.VirtualService{
Hosts: []string{"origin.example.com"},
},
}
Expand All @@ -70,18 +71,18 @@ var (
Namespace: "default",
OwnerReferences: []metav1.OwnerReference{ownerRef},
},
Spec: v1alpha3.VirtualServiceSpec{
Spec: istiov1alpha3.VirtualService{
Hosts: []string{"desired.example.com"},
},
}
)

type FakeAccessor struct {
client sharedclientset.Interface
client istioclientset.Interface
vsLister istiolisters.VirtualServiceLister
}

func (f *FakeAccessor) GetSharedClient() sharedclientset.Interface {
func (f *FakeAccessor) GetIstioClient() istioclientset.Interface {
return f.client
}

Expand All @@ -93,10 +94,10 @@ func TestReconcileVirtualService_Create(t *testing.T) {
ctx, _ := SetupFakeContext(t)
ctx, cancel := context.WithCancel(ctx)

sharedClient := fakesharedclient.Get(ctx)
istioClient := fakeistioclient.Get(ctx)

h := NewHooks()
h.OnCreate(&sharedClient.Fake, "virtualservices", func(obj runtime.Object) HookResult {
h.OnCreate(&istioClient.Fake, "virtualservices", func(obj runtime.Object) HookResult {
got := obj.(*v1alpha3.VirtualService)
if diff := cmp.Diff(got, desired); diff != "" {
t.Logf("Unexpected VirtualService (-want, +got): %v", diff)
Expand All @@ -105,7 +106,7 @@ func TestReconcileVirtualService_Create(t *testing.T) {
return HookComplete
})

accessor, waitInformers := setup(ctx, []*v1alpha3.VirtualService{}, sharedClient, t)
accessor, waitInformers := setup(ctx, []*v1alpha3.VirtualService{}, istioClient, t)
defer func() {
cancel()
waitInformers()
Expand All @@ -122,15 +123,15 @@ func TestReconcileVirtualService_Update(t *testing.T) {
ctx, _ := SetupFakeContext(t)
ctx, cancel := context.WithCancel(ctx)

sharedClient := fakesharedclient.Get(ctx)
accessor, waitInformers := setup(ctx, []*v1alpha3.VirtualService{origin}, sharedClient, t)
istioClient := fakeistioclient.Get(ctx)
accessor, waitInformers := setup(ctx, []*v1alpha3.VirtualService{origin}, istioClient, t)
defer func() {
cancel()
waitInformers()
}()

h := NewHooks()
h.OnUpdate(&sharedClient.Fake, "virtualservices", func(obj runtime.Object) HookResult {
h.OnUpdate(&istioClient.Fake, "virtualservices", func(obj runtime.Object) HookResult {
got := obj.(*v1alpha3.VirtualService)
if diff := cmp.Diff(got, desired); diff != "" {
t.Logf("Unexpected VirtualService (-want, +got): %v", diff)
Expand All @@ -146,10 +147,10 @@ func TestReconcileVirtualService_Update(t *testing.T) {
}

func setup(ctx context.Context, vses []*v1alpha3.VirtualService,
sharedClient sharedclientset.Interface, t *testing.T) (*FakeAccessor, func()) {
istioClient istioclientset.Interface, t *testing.T) (*FakeAccessor, func()) {

fake := sharedfake.NewSimpleClientset()
informer := informers.NewSharedInformerFactory(fake, 0)
fake := istiofake.NewSimpleClientset()
informer := istioinformers.NewSharedInformerFactory(fake, 0)
vsInformer := informer.Networking().V1alpha3().VirtualServices()

for _, vs := range vses {
Expand All @@ -163,7 +164,7 @@ func setup(ctx context.Context, vses []*v1alpha3.VirtualService,
}

return &FakeAccessor{
client: sharedClient,
client: istioClient,
vsLister: vsInformer.Lister(),
}, waitInformers
}
6 changes: 3 additions & 3 deletions pkg/reconciler/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package ingress
import (
"context"

"knative.dev/pkg/apis/istio/v1alpha3"
gatewayinformer "knative.dev/pkg/client/injection/informers/istio/v1alpha3/gateway"
virtualserviceinformer "knative.dev/pkg/client/injection/informers/istio/v1alpha3/virtualservice"
v1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
endpointsinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/endpoints"
podinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/pod"
secretinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/secret"
serviceinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/service"
gatewayinformer "knative.dev/pkg/client/istio/injection/informers/networking/v1alpha3/gateway"
virtualserviceinformer "knative.dev/pkg/client/istio/injection/informers/networking/v1alpha3/virtualservice"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/tracker"
Expand Down
Loading

0 comments on commit 197028d

Please sign in to comment.