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

Commit

Permalink
Remove unnecessary methods from Store2, and moves handling of protobu…
Browse files Browse the repository at this point in the history
…f to `store` (#1120)

Automatic merge from submit-queue

Remove unnecessary methods from Store2, and moves handling of protobuf to `store`

**Release note**:

```release-note
none
```

This introduces `Store2Backend`, and keep `pkg/config/crd` untyped (spec is `map[string]interface{}`), and move the conversion part to `proto.Message` into `pkg/config/store`. With this, it is easier to add other types of store like FSstore, the same conversion logic can be reused.

Also, we've agreed that the previous `Store2` interface had too many methods which wouldn't be used actually. This simplifies the interface, as removing `RegisterKind` (integrated into `Init`), removing kinds parameter from `Watch`, and removing of `Put` / `Delete`.
  • Loading branch information
jmuk authored and istio-merge-robot committed Aug 24, 2017
1 parent 88973cd commit b5aead1
Show file tree
Hide file tree
Showing 18 changed files with 1,126 additions and 720 deletions.
21 changes: 0 additions & 21 deletions doc/dev/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,3 @@ You can also run a simple client to interact with the server:
--string_attributes source.uid=kubernetes://xyz.default
Check RPC returned OK
```

## Testing

Similar to Pilot, some tests for Mixer requires access to Kubernetes cluster
(version 1.7.0 or higher). Please configure your `kubectl` to point to a development
cluster (e.g. minikube) before building or invoking the tests and add a symbolic link
to your repository pointing to Kubernetes cluster credentials:

ln -s ~/.kube/config testdata/kubernetes/

_Note1_: If you are running Bazel in a VM (e.g. in Vagrant environment), copy
the kube config file on the host to testdata/kubernetes instead of symlinking it,
and change the paths to minikube certs.

cp ~/.kube/config testdata/kubernetes/
sed -i 's!/Users/<username>!/home/ubuntu!' testdata/kubernetes/config

Also, copy the same file to `/home/ubuntu/.kube/config` in the VM, and make
sure that the file is readable to user `ubuntu`.

See also [Pilot's guide of setting up test environment](https://github.com/istio/pilot/blob/master/doc/testing.md).
1 change: 1 addition & 0 deletions pkg/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
deps = [
"//pkg/adapter:go_default_library",
"//pkg/attribute:go_default_library",
"//pkg/config/crd:go_default_library",
"//pkg/config/descriptor:go_default_library",
"//pkg/config/proto:go_default_library",
"//pkg/config/redis:go_default_library",
Expand Down
22 changes: 7 additions & 15 deletions pkg/config/crd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"queue.go",
"init.go",
"resource.go",
"store.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/config/store:go_default_library",
"@com_github_gogo_protobuf//jsonpb:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/runtime:go_default_library",
Expand All @@ -31,25 +29,19 @@ go_test(
name = "go_default_test",
size = "medium",
srcs = [
"queue_test.go",
"resource_test.go",
"store_test.go",
],
library = ":go_default_library",
deps = [
"//pkg/config/proto:go_default_library",
"//pkg/config/store:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1/unstructured:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/schema:go_default_library",
"@io_k8s_client_go//dynamic:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
"@io_k8s_client_go//plugin/pkg/client/auth/gcp:go_default_library",
"@io_k8s_client_go//plugin/pkg/client/auth/oidc:go_default_library",
"@io_k8s_apimachinery//pkg/runtime:go_default_library",
"@io_k8s_apimachinery//pkg/watch:go_default_library",
"@io_k8s_client_go//discovery:go_default_library",
"@io_k8s_client_go//discovery/fake:go_default_library",
"@io_k8s_client_go//rest:go_default_library",
"@io_k8s_client_go//tools/clientcmd:go_default_library",
"@io_k8s_client_go//testing:go_default_library",
"@io_k8s_client_go//tools/cache:go_default_library",
],
)
91 changes: 91 additions & 0 deletions pkg/config/crd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package crd

import (
"net/url"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
// import GKE cluster authentication plugin
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
// import OIDC cluster authentication plugin, e.g. for Tectonic
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

"istio.io/mixer/pkg/config/store"
)

// defaultDiscoveryBuilder builds the actual discovery client using the kubernetes config.
func defaultDiscoveryBuilder(conf *rest.Config) (discovery.DiscoveryInterface, error) {
client, err := discovery.NewDiscoveryClientForConfig(conf)
return client, err
}

// dynamicListenerWatcherBuilder is the builder of cache.ListerWatcher by using actual
// k8s.io/client-go/dynamic.Client.
type dynamicListerWatcherBuilder struct {
client *dynamic.Client
}

func newDynamicListenerWatcherBuilder(conf *rest.Config) (listerWatcherBuilderInterface, error) {
client, err := dynamic.NewClient(conf)
if err != nil {
return nil, err
}
return &dynamicListerWatcherBuilder{client}, nil
}

func (b *dynamicListerWatcherBuilder) build(res metav1.APIResource) cache.ListerWatcher {
return b.client.Resource(&res, "")
}

// NewStore creates a new Store instance.
func NewStore(u *url.URL) (store.Store2Backend, error) {
kubeconfig := u.Path
namespaces := u.Query().Get("ns")
conf, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, err
}
conf.APIPath = "/apis"
conf.GroupVersion = &schema.GroupVersion{Group: apiGroup, Version: apiVersion}
s := &Store{
conf: conf,
discoveryBuilder: defaultDiscoveryBuilder,
listerWatcherBuilder: newDynamicListenerWatcherBuilder,
}
if len(namespaces) > 0 {
s.ns = map[string]bool{}
for _, n := range strings.Split(namespaces, ",") {
s.ns[n] = true
}
}
return s, nil
}

// Register registers this module as a Store2Backend.
// Do not use 'init()' for automatic registration; linker will drop
// the whole module because it looks unused.
func Register(builders map[string]store.Store2Builder) {
builders["k8s"] = NewStore
builders["kube"] = NewStore
builders["kubernetes"] = NewStore
}
69 changes: 0 additions & 69 deletions pkg/config/crd/queue.go

This file was deleted.

92 changes: 0 additions & 92 deletions pkg/config/crd/queue_test.go

This file was deleted.

Loading

0 comments on commit b5aead1

Please sign in to comment.