2 * Copyright (c) 2018 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial Project
18 "istio.io/istio/pilot/pkg/config/kube/crd"
19 "istio.io/istio/pilot/pkg/model"
30 client, err = crd.NewClient("k8s.yml", model.ConfigDescriptor{
32 model.DestinationPolicy,
33 model.DestinationRule,
37 log.Log.Error("fail to init crd", err)
41 func Get(typ, namespace, name string) (*model.Config, bool) {
42 proto, err := protoSchema(typ)
44 log.Log.Informational("get resource error", err)
45 return &model.Config{}, false
47 return client.Get(proto.Type, name, namespace)
50 func protoSchema(typ string) (model.ProtoSchema, error) {
51 for _, desc := range client.ConfigDescriptor() {
53 case crd.ResourceName(desc.Type), crd.ResourceName(desc.Plural):
57 return model.ProtoSchema{}, errors.New("can not find this kind of resources:[" + typ + "]")
60 func List(typ, namespace string) ([]model.Config, error) {
61 proto, err := protoSchema(typ)
65 return client.List(proto.Type, namespace)