1 Star 0 Fork 2

yanyue / cloudbases.io.kiali

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
types.go 17.63 KB
一键复制 编辑 原始数据 按行查看 历史
Hubery1003 提交于 2021-12-16 10:12 . first commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
package kubernetes
import (
"fmt"
"strings"
"github.com/kiali/kiali/config"
"k8s.io/api/apps/v1beta1"
autoscalingV1 "k8s.io/api/autoscaling/v1"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
// Networking
destinationRules = "destinationrules"
destinationRuleType = "DestinationRule"
destinationRuleTypeList = "DestinationRuleList"
gateways = "gateways"
gatewayType = "Gateway"
gatewayTypeList = "GatewayList"
serviceentries = "serviceentries"
serviceentryType = "ServiceEntry"
serviceentryTypeList = "ServiceEntryList"
virtualServices = "virtualservices"
virtualServiceType = "VirtualService"
virtualServiceTypeList = "VirtualServiceList"
// Quotas
quotaspecs = "quotaspecs"
quotaspecType = "QuotaSpec"
quotaspecTypeList = "QuotaSpecList"
quotaspecbindings = "quotaspecbindings"
quotaspecbindingType = "QuotaSpecBinding"
quotaspecbindingTypeList = "QuotaSpecBindingList"
// Policies
policies = "policies"
policyType = "Policy"
policyTypeList = "PolicyList"
//MeshPolicies
meshPolicies = "meshpolicies"
meshPolicyType = "MeshPolicy"
meshPolicyTypeList = "MeshPolicyList"
// Rbac
clusterrbacconfigs = "clusterrbacconfigs"
clusterrbacconfigType = "ClusterRbacConfig"
clusterrbacconfigTypeList = "ClusterRbacConfigList"
serviceroles = "serviceroles"
serviceroleType = "ServiceRole"
serviceroleTypeList = "ServiceRoleList"
servicerolebindings = "servicerolebindings"
servicerolebindingType = "ServiceRoleBinding"
servicerolebindingTypeList = "ServiceRoleBindingList"
// Config - Rules
rules = "rules"
ruleType = "rule"
ruleTypeList = "ruleList"
// Config - Adapters
circonuses = "circonuses"
circonusType = "circonus"
circonusTypeList = "circonusList"
deniers = "deniers"
denierType = "denier"
denierTypeList = "denierList"
fluentds = "fluentds"
fluentdType = "fluentd"
fluentdTypeList = "fluentdList"
fluentdLabel = "fluentd"
handlers = "handlers"
handlerType = "handler"
handlerTypeList = "handlerList"
kubernetesenvs = "kubernetesenvs"
kubernetesenvType = "kubernetesenv"
kubernetesenvTypeList = "kubernetesenvList"
listcheckers = "listcheckers"
listcheckerType = "listchecker"
listcheckerTypeList = "listcheckerList"
memquotas = "memquotas"
memquotaType = "memquota"
memquotaTypeList = "memquotaList"
opas = "opas"
opaType = "opa"
opaTypeList = "opaList"
prometheuses = "prometheuses"
prometheusType = "prometheus"
prometheusTypeList = "prometheusList"
rbacs = "rbacs"
rbacType = "rbac"
rbacTypeList = "rbacList"
servicecontrols = "servicecontrols"
servicecontrolType = "servicecontrol"
servicecontrolTypeList = "servicecontrolList"
solarwindses = "solarwindses"
solarwindsType = "solarwinds"
solarwindsTypeList = "solarwindsList"
stackdrivers = "stackdrivers"
stackdriverType = "stackdriver"
stackdriverTypeList = "stackdriverList"
statsds = "statsds"
statsdType = "statsd"
statsdTypeList = "statsdList"
stdios = "stdios"
stdioType = "stdio"
stdioTypeList = "stdioList"
// Config - Templates
apikeys = "apikeys"
apikeyType = "apikey"
apikeyTypeList = "apikeyList"
authorizations = "authorizations"
authorizationType = "authorization"
authorizationTypeList = "authorizationList"
checknothings = "checknothings"
checknothingType = "checknothing"
checknothingTypeList = "checknothingList"
kuberneteses = "kuberneteses"
kubernetesType = "kubernetes"
kubernetesTypeList = "kubernetesList"
listEntries = "listentries"
listEntryType = "listentry"
listEntryTypeList = "listentryList"
logentries = "logentries"
logentryType = "logentry"
logentryTypeList = "logentryList"
metrics = "metrics"
metricType = "metric"
metricTypeList = "metricList"
quotas = "quotas"
quotaType = "quota"
quotaTypeList = "quotaList"
reportnothings = "reportnothings"
reportnothingType = "reportnothing"
reportnothingTypeList = "reportnothingList"
servicecontrolreports = "servicecontrolreports"
servicecontrolreportType = "servicecontrolreport"
servicecontrolreportTypeList = "servicecontrolreportList"
)
var (
ConfigGroupVersion = schema.GroupVersion{
Group: "config.istio.io",
Version: "v1alpha2",
}
ApiConfigVersion = ConfigGroupVersion.Group + "/" + ConfigGroupVersion.Version
NetworkingGroupVersion = schema.GroupVersion{
Group: "networking.istio.io",
Version: "v1alpha3",
}
ApiNetworkingVersion = NetworkingGroupVersion.Group + "/" + NetworkingGroupVersion.Version
AuthenticationGroupVersion = schema.GroupVersion{
Group: "authentication.istio.io",
Version: "v1alpha1",
}
ApiAuthenticationVersion = AuthenticationGroupVersion.Group + "/" + AuthenticationGroupVersion.Version
RbacGroupVersion = schema.GroupVersion{
Group: "rbac.istio.io",
Version: "v1alpha1",
}
ApiRbacVersion = RbacGroupVersion.Group + "/" + RbacGroupVersion.Version
networkingTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: gatewayType,
collectionKind: gatewayTypeList,
},
{
objectKind: virtualServiceType,
collectionKind: virtualServiceTypeList,
},
{
objectKind: destinationRuleType,
collectionKind: destinationRuleTypeList,
},
{
objectKind: serviceentryType,
collectionKind: serviceentryTypeList,
},
}
configTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: ruleType,
collectionKind: ruleTypeList,
},
// Quota specs depends on Quota template but are not a "template" object itselft
{
objectKind: quotaspecType,
collectionKind: quotaspecTypeList,
},
{
objectKind: quotaspecbindingType,
collectionKind: quotaspecbindingTypeList,
},
}
authenticationTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: policyType,
collectionKind: policyTypeList,
},
{
objectKind: meshPolicyType,
collectionKind: meshPolicyTypeList,
},
}
// TODO Adapters and Templates can be loaded from external config for easy maintenance
adapterTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: circonusType,
collectionKind: circonusTypeList,
},
{
objectKind: denierType,
collectionKind: denierTypeList,
},
{
objectKind: fluentdType,
collectionKind: fluentdTypeList,
},
{
objectKind: handlerType,
collectionKind: handlerTypeList,
},
{
objectKind: kubernetesenvType,
collectionKind: kubernetesenvTypeList,
},
{
objectKind: listcheckerType,
collectionKind: listcheckerTypeList,
},
{
objectKind: memquotaType,
collectionKind: memquotaTypeList,
},
{
objectKind: opaType,
collectionKind: opaTypeList,
},
{
objectKind: prometheusType,
collectionKind: prometheusTypeList,
},
{
objectKind: rbacType,
collectionKind: rbacTypeList,
},
{
objectKind: servicecontrolType,
collectionKind: servicecontrolTypeList,
},
{
objectKind: solarwindsType,
collectionKind: solarwindsTypeList,
},
{
objectKind: stackdriverType,
collectionKind: stackdriverTypeList,
},
{
objectKind: statsdType,
collectionKind: statsdTypeList,
},
{
objectKind: stdioType,
collectionKind: stdioTypeList,
},
}
templateTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: apikeyType,
collectionKind: apikeyTypeList,
},
{
objectKind: authorizationType,
collectionKind: authorizationTypeList,
},
{
objectKind: checknothingType,
collectionKind: checknothingTypeList,
},
{
objectKind: kubernetesType,
collectionKind: kubernetesTypeList,
},
{
objectKind: listEntryType,
collectionKind: listEntryTypeList,
},
{
objectKind: logentryType,
collectionKind: logentryTypeList,
},
{
objectKind: metricType,
collectionKind: metricTypeList,
},
{
objectKind: quotaType,
collectionKind: quotaTypeList,
},
{
objectKind: reportnothingType,
collectionKind: reportnothingTypeList,
},
{
objectKind: servicecontrolreportType,
collectionKind: servicecontrolreportTypeList,
},
}
rbacTypes = []struct {
objectKind string
collectionKind string
}{
{
objectKind: clusterrbacconfigType,
collectionKind: clusterrbacconfigTypeList,
},
{
objectKind: serviceroleType,
collectionKind: serviceroleTypeList,
},
{
objectKind: servicerolebindingType,
collectionKind: servicerolebindingTypeList,
},
}
// A map to get the plural for a Istio type using the singlar type
// Used for fetch istio actions details, so only applied to handlers (adapters) and instances (templates) types
// It should be one entry per adapter/template
adapterPlurals = map[string]string{
circonusType: circonuses,
denierType: deniers,
fluentdType: fluentds,
handlerType: handlers,
kubernetesenvType: kubernetesenvs,
listcheckerType: listcheckers,
memquotaType: memquotas,
opaType: opas,
prometheusType: prometheuses,
rbacType: rbacs,
servicecontrolType: servicecontrols,
solarwindsType: solarwindses,
stackdriverType: stackdrivers,
statsdType: statsds,
stdioType: stdios,
}
templatePlurals = map[string]string{
apikeyType: apikeys,
authorizationType: authorizations,
checknothingType: checknothings,
kubernetesType: kuberneteses,
listEntryType: listEntries,
logentryType: logentries,
metricType: metrics,
quotaType: quotas,
reportnothingType: reportnothings,
servicecontrolreportType: servicecontrolreports,
}
PluralType = map[string]string{
// Networking
gateways: gatewayType,
virtualServices: virtualServiceType,
destinationRules: destinationRuleType,
serviceentries: serviceentryType,
// Main Config files
rules: ruleType,
quotaspecs: quotaspecType,
quotaspecbindings: quotaspecbindingType,
// Adapters
circonuses: circonusType,
deniers: denierType,
fluentds: fluentdType,
handlers: handlerType,
kubernetesenvs: kubernetesenvType,
listcheckers: listcheckerType,
memquotas: memquotaType,
opas: opaType,
prometheuses: prometheusType,
rbacs: rbacType,
servicecontrols: servicecontrolType,
solarwindses: solarwindsType,
stackdrivers: stackdriverType,
statsds: statsdType,
stdios: stdioType,
// Templates
apikeys: apikeyType,
authorizations: authorizationType,
checknothings: checknothingType,
kuberneteses: kubernetesType,
listEntries: listEntryType,
logentries: logentryType,
metrics: metricType,
quotas: quotaType,
reportnothings: reportnothingType,
servicecontrolreports: servicecontrolreportType,
// Policies
policies: policyType,
meshPolicies: meshPolicyType,
// Rbac
clusterrbacconfigs: clusterrbacconfigType,
serviceroles: serviceroleType,
servicerolebindings: servicerolebindingType,
}
)
// IstioObject is a k8s wrapper interface for config objects.
// Taken from istio.io
type IstioObject interface {
runtime.Object
GetSpec() map[string]interface{}
SetSpec(map[string]interface{})
GetObjectMeta() meta_v1.ObjectMeta
SetObjectMeta(meta_v1.ObjectMeta)
DeepCopyIstioObject() IstioObject
}
// IstioObjectList is a k8s wrapper interface for list config objects.
// Taken from istio.io
type IstioObjectList interface {
runtime.Object
GetItems() []IstioObject
}
// ServiceList holds list of services, pods and deployments
type ServiceList struct {
Services *v1.ServiceList
Pods *v1.PodList
Deployments *v1beta1.DeploymentList
}
// ServiceDetails is a wrapper to group full Service description, Endpoints and Pods.
// Used to fetch all details in a single operation instead to invoke individual APIs per each group.
type ServiceDetails struct {
Service *v1.Service `json:"service"`
Endpoints *v1.Endpoints `json:"endpoints"`
Deployments *v1beta1.DeploymentList `json:"deployments"`
Autoscalers *autoscalingV1.HorizontalPodAutoscalerList `json:"autoscalers"`
Pods []v1.Pod `json:"pods"`
}
// IstioDetails is a wrapper to group all Istio objects related to a Service.
// Used to fetch all Istio information in a single operation instead to invoke individual APIs per each group.
type IstioDetails struct {
VirtualServices []IstioObject `json:"virtualservices"`
DestinationRules []IstioObject `json:"destinationrules"`
ServiceEntries []IstioObject `json:"serviceentries"`
Gateways []IstioObject `json:"gateways"`
}
// MTLSDetails is a wrapper to group all Istio objects related to non-local mTLS configurations
type MTLSDetails struct {
DestinationRules []IstioObject `json:"destinationrules"`
MeshPolicies []IstioObject `json:"meshpolicies"`
}
type istioResponse struct {
result IstioObject
results []IstioObject
err error
}
// GenericIstioObject is a type to test Istio types defined by Istio as a Kubernetes extension.
type GenericIstioObject struct {
meta_v1.TypeMeta `json:",inline"`
meta_v1.ObjectMeta `json:"metadata"`
Spec map[string]interface{} `json:"spec"`
}
// GenericIstioObjectList is the generic Kubernetes API list wrapper
type GenericIstioObjectList struct {
meta_v1.TypeMeta `json:",inline"`
meta_v1.ListMeta `json:"metadata"`
Items []GenericIstioObject `json:"items"`
}
// GetSpec from a wrapper
func (in *GenericIstioObject) GetSpec() map[string]interface{} {
return in.Spec
}
// SetSpec for a wrapper
func (in *GenericIstioObject) SetSpec(spec map[string]interface{}) {
in.Spec = spec
}
// GetObjectMeta from a wrapper
func (in *GenericIstioObject) GetObjectMeta() meta_v1.ObjectMeta {
return in.ObjectMeta
}
// SetObjectMeta for a wrapper
func (in *GenericIstioObject) SetObjectMeta(metadata meta_v1.ObjectMeta) {
in.ObjectMeta = metadata
}
// GetItems from a wrapper
func (in *GenericIstioObjectList) GetItems() []IstioObject {
out := make([]IstioObject, len(in.Items))
for i := range in.Items {
out[i] = &in.Items[i]
}
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GenericIstioObject) DeepCopyInto(out *GenericIstioObject) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericIstioObject.
func (in *GenericIstioObject) DeepCopy() *GenericIstioObject {
if in == nil {
return nil
}
out := new(GenericIstioObject)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *GenericIstioObject) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyIstioObject is an autogenerated deepcopy function, copying the receiver, creating a new IstioObject.
func (in *GenericIstioObject) DeepCopyIstioObject() IstioObject {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GenericIstioObjectList) DeepCopyInto(out *GenericIstioObjectList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]GenericIstioObject, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericIstioObjectList.
func (in *GenericIstioObjectList) DeepCopy() *GenericIstioObjectList {
if in == nil {
return nil
}
out := new(GenericIstioObjectList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *GenericIstioObjectList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// Host represents the FQDN format for Istio hostnames
type Host struct {
Service string
Namespace string
Cluster string
}
// Parse takes as an input a hostname (simple or full FQDN), namespace and clusterName and returns a parsed Host struct
func ParseHost(hostName, namespace, cluster string) Host {
domainParts := strings.Split(hostName, ".")
host := Host{
Service: domainParts[0],
}
if len(domainParts) > 1 {
host.Namespace = domainParts[1]
if len(domainParts) > 2 {
host.Cluster = strings.Join(domainParts[2:], ".")
}
}
// Fill in missing details, we take precedence from the full hostname and not from DestinationRule details
if host.Cluster == "" {
if cluster != "" {
host.Cluster = cluster
} else {
host.Cluster = config.Get().ExternalServices.Istio.IstioIdentityDomain
}
}
if host.Namespace == "" {
host.Namespace = namespace
}
return host
}
// String outputs a full FQDN version of the Host
func (h Host) String() string {
return fmt.Sprintf("%s.%s.%s", h.Service, h.Namespace, h.Cluster)
}
1
https://gitee.com/programmer-zpz/cloudbases.io.kiali.git
git@gitee.com:programmer-zpz/cloudbases.io.kiali.git
programmer-zpz
cloudbases.io.kiali
cloudbases.io.kiali
v0.15.1

搜索帮助