remove dependency on kubernetes repo (#1651)
remove dependency on kubernetes/kubernetes repo
This commit is contained in:
@@ -2,11 +2,11 @@ package options
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
apiserverconfig "k8s.io/apiserver/pkg/apis/config"
|
apiserverconfig "k8s.io/apiserver/pkg/apis/config"
|
||||||
cliflag "k8s.io/component-base/cli/flag"
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/client/leaderelectionconfig"
|
|
||||||
kubesphereconfig "kubesphere.io/kubesphere/pkg/server/config"
|
kubesphereconfig "kubesphere.io/kubesphere/pkg/server/config"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
||||||
@@ -59,7 +59,7 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
|
|||||||
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"))
|
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"))
|
||||||
|
|
||||||
fs := fss.FlagSet("leaderelection")
|
fs := fss.FlagSet("leaderelection")
|
||||||
leaderelectionconfig.BindFlags(s.LeaderElection, fs)
|
s.bindLeaderElectionFlags(s.LeaderElection, fs)
|
||||||
|
|
||||||
kfs := fss.FlagSet("klog")
|
kfs := fss.FlagSet("klog")
|
||||||
local := flag.NewFlagSet("klog", flag.ExitOnError)
|
local := flag.NewFlagSet("klog", flag.ExitOnError)
|
||||||
@@ -80,3 +80,26 @@ func (s *KubeSphereControllerManagerOptions) Validate() []error {
|
|||||||
errs = append(errs, s.OpenPitrixOptions.Validate()...)
|
errs = append(errs, s.OpenPitrixOptions.Validate()...)
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *KubeSphereControllerManagerOptions) bindLeaderElectionFlags(l *apiserverconfig.LeaderElectionConfiguration, fs *pflag.FlagSet) {
|
||||||
|
fs.BoolVar(&l.LeaderElect, "leader-elect", l.LeaderElect, ""+
|
||||||
|
"Start a leader election client and gain leadership before "+
|
||||||
|
"executing the main loop. Enable this when running replicated "+
|
||||||
|
"components for high availability.")
|
||||||
|
fs.DurationVar(&l.LeaseDuration.Duration, "leader-elect-lease-duration", l.LeaseDuration.Duration, ""+
|
||||||
|
"The duration that non-leader candidates will wait after observing a leadership "+
|
||||||
|
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
|
||||||
|
"slot. This is effectively the maximum duration that a leader can be stopped "+
|
||||||
|
"before it is replaced by another candidate. This is only applicable if leader "+
|
||||||
|
"election is enabled.")
|
||||||
|
fs.DurationVar(&l.RenewDeadline.Duration, "leader-elect-renew-deadline", l.RenewDeadline.Duration, ""+
|
||||||
|
"The interval between attempts by the acting master to renew a leadership slot "+
|
||||||
|
"before it stops leading. This must be less than or equal to the lease duration. "+
|
||||||
|
"This is only applicable if leader election is enabled.")
|
||||||
|
fs.DurationVar(&l.RetryPeriod.Duration, "leader-elect-retry-period", l.RetryPeriod.Duration, ""+
|
||||||
|
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||||
|
"of a leadership. This is only applicable if leader election is enabled.")
|
||||||
|
fs.StringVar(&l.ResourceLock, "leader-elect-resource-lock", l.ResourceLock, ""+
|
||||||
|
"The type of resource object that is used for locking during "+
|
||||||
|
"leader election. Supported options are `endpoints` (default) and `configmaps`.")
|
||||||
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -141,7 +141,6 @@ require (
|
|||||||
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect
|
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect
|
||||||
k8s.io/klog v0.4.0
|
k8s.io/klog v0.4.0
|
||||||
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5
|
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5
|
||||||
k8s.io/kubernetes v1.13.6
|
|
||||||
kubesphere.io/im v0.1.0 // indirect
|
kubesphere.io/im v0.1.0 // indirect
|
||||||
openpitrix.io/iam v0.1.0 // indirect
|
openpitrix.io/iam v0.1.0 // indirect
|
||||||
openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c
|
openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c
|
||||||
@@ -423,7 +422,6 @@ replace (
|
|||||||
k8s.io/gengo => k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a
|
k8s.io/gengo => k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a
|
||||||
k8s.io/klog => k8s.io/klog v0.4.0
|
k8s.io/klog => k8s.io/klog v0.4.0
|
||||||
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5
|
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5
|
||||||
k8s.io/kubernetes => k8s.io/kubernetes v1.13.6
|
|
||||||
k8s.io/utils => k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5
|
k8s.io/utils => k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5
|
||||||
kubesphere.io/im => kubesphere.io/im v0.1.0
|
kubesphere.io/im => kubesphere.io/im v0.1.0
|
||||||
openpitrix.io/iam => openpitrix.io/iam v0.1.0
|
openpitrix.io/iam => openpitrix.io/iam v0.1.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -495,8 +495,6 @@ k8s.io/klog v0.4.0 h1:lCJCxf/LIowc2IGS9TPjWDyXY4nOmdGdfcwwDQCOURQ=
|
|||||||
k8s.io/klog v0.4.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
k8s.io/klog v0.4.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||||
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5 h1:MH8SvyTlIiLt8b1oHy4Dtp1zPpLGp6lTOjvfzPTkoQE=
|
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5 h1:MH8SvyTlIiLt8b1oHy4Dtp1zPpLGp6lTOjvfzPTkoQE=
|
||||||
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
|
k8s.io/kube-openapi v0.0.0-20181109181836-c59034cc13d5/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
|
||||||
k8s.io/kubernetes v1.13.6 h1:eUAUryzMLFmi4ZY8kMOUtLG5lHp2PUx5WOmy4RVaobk=
|
|
||||||
k8s.io/kubernetes v1.13.6/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
|
|
||||||
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
|
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
|
||||||
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||||
kubesphere.io/im v0.1.0 h1:Isu/WBOawUb4fzSlQeD1f6Vbq9pqFS0PmDg8v8iFYaY=
|
kubesphere.io/im v0.1.0 h1:Isu/WBOawUb4fzSlQeD1f6Vbq9pqFS0PmDg8v8iFYaY=
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ mkdir -p "${_tmp}"
|
|||||||
|
|
||||||
# Add the require directive
|
# Add the require directive
|
||||||
echo "Running: go get ${dep}@${sha}"
|
echo "Running: go get ${dep}@${sha}"
|
||||||
go get -m -d "${dep}@${sha}"
|
go get -d "${dep}@${sha}"
|
||||||
|
|
||||||
# Find the resolved version
|
# Find the resolved version
|
||||||
rev=$(go mod edit -json | jq -r ".Require[] | select(.Path == \"${dep}\") | .Version")
|
rev=$(go mod edit -json | jq -r ".Require[] | select(.Path == \"${dep}\") | .Version")
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
log "k8s.io/klog"
|
log "k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
servicemeshinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions/servicemesh/v1alpha2"
|
servicemeshinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions/servicemesh/v1alpha2"
|
||||||
servicemeshlisters "kubesphere.io/kubesphere/pkg/client/listers/servicemesh/v1alpha2"
|
servicemeshlisters "kubesphere.io/kubesphere/pkg/client/listers/servicemesh/v1alpha2"
|
||||||
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
||||||
@@ -85,10 +84,6 @@ func NewApplicationController(serviceInformer coreinformers.ServiceInformer,
|
|||||||
broadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "application-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "application-controller"})
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("virtualservice_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &ApplicationController{
|
v := &ApplicationController{
|
||||||
client: client,
|
client: client,
|
||||||
applicationClient: applicationClient,
|
applicationClient: applicationClient,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
log "k8s.io/klog"
|
log "k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
|
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
|
||||||
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
||||||
|
|
||||||
@@ -90,10 +89,6 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor
|
|||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "destinationrule-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "destinationrule-controller"})
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("virtualservice_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &DestinationRuleController{
|
v := &DestinationRuleController{
|
||||||
client: client,
|
client: client,
|
||||||
destinationRuleClient: destinationRuleClient,
|
destinationRuleClient: destinationRuleClient,
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import (
|
|||||||
batchv1informers "k8s.io/client-go/informers/batch/v1"
|
batchv1informers "k8s.io/client-go/informers/batch/v1"
|
||||||
batchv1listers "k8s.io/client-go/listers/batch/v1"
|
batchv1listers "k8s.io/client-go/listers/batch/v1"
|
||||||
log "k8s.io/klog"
|
log "k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
@@ -64,11 +62,6 @@ type JobController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewJobController(jobInformer batchv1informers.JobInformer, client clientset.Interface) *JobController {
|
func NewJobController(jobInformer batchv1informers.JobInformer, client clientset.Interface) *JobController {
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("job_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &JobController{
|
v := &JobController{
|
||||||
client: client,
|
client: client,
|
||||||
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "job"),
|
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "job"),
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||||
"time"
|
"time"
|
||||||
@@ -53,10 +52,6 @@ func NewController(devopsclientset devopsclient.Interface,
|
|||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "s2ibinary-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "s2ibinary-controller"})
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("s2ibinary_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &S2iBinaryController{
|
v := &S2iBinaryController{
|
||||||
client: client,
|
client: client,
|
||||||
devopsClient: devopsclientset,
|
devopsClient: devopsclientset,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -60,10 +59,6 @@ func NewController(devopsclientset devopsclient.Interface, s2iclientset s2iclien
|
|||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "s2irun-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "s2irun-controller"})
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("s2irun_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &S2iRunController{
|
v := &S2iRunController{
|
||||||
client: client,
|
client: client,
|
||||||
devopsClient: devopsclientset,
|
devopsClient: devopsclientset,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
log "k8s.io/klog"
|
log "k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/util/metrics"
|
|
||||||
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
"kubesphere.io/kubesphere/pkg/controller/virtualservice/util"
|
||||||
|
|
||||||
istioclient "github.com/knative/pkg/client/clientset/versioned"
|
istioclient "github.com/knative/pkg/client/clientset/versioned"
|
||||||
@@ -87,10 +86,6 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
|
|||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "virtualservice-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "virtualservice-controller"})
|
||||||
|
|
||||||
if client != nil && client.CoreV1().RESTClient().GetRateLimiter() != nil {
|
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("virtualservice_controller", client.CoreV1().RESTClient().GetRateLimiter())
|
|
||||||
}
|
|
||||||
|
|
||||||
v := &VirtualServiceController{
|
v := &VirtualServiceController{
|
||||||
client: client,
|
client: client,
|
||||||
virtualServiceClient: virtualServiceClient,
|
virtualServiceClient: virtualServiceClient,
|
||||||
|
|||||||
202
vendor/k8s.io/kubernetes/LICENSE
generated
vendored
202
vendor/k8s.io/kubernetes/LICENSE
generated
vendored
@@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
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.
|
|
||||||
29
vendor/k8s.io/kubernetes/pkg/client/leaderelectionconfig/BUILD
generated
vendored
29
vendor/k8s.io/kubernetes/pkg/client/leaderelectionconfig/BUILD
generated
vendored
@@ -1,29 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = ["config.go"],
|
|
||||||
importpath = "k8s.io/kubernetes/pkg/client/leaderelectionconfig",
|
|
||||||
deps = [
|
|
||||||
"//staging/src/k8s.io/apiserver/pkg/apis/config:go_default_library",
|
|
||||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [":package-srcs"],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
||||||
53
vendor/k8s.io/kubernetes/pkg/client/leaderelectionconfig/config.go
generated
vendored
53
vendor/k8s.io/kubernetes/pkg/client/leaderelectionconfig/config.go
generated
vendored
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2017 The Kubernetes 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 leaderelectionconfig
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
apiserverconfig "k8s.io/apiserver/pkg/apis/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// DefaultLeaseDuration defines a default duration of lease.
|
|
||||||
DefaultLeaseDuration = 15 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
// BindFlags binds the LeaderElectionConfiguration struct fields to a flagset
|
|
||||||
func BindFlags(l *apiserverconfig.LeaderElectionConfiguration, fs *pflag.FlagSet) {
|
|
||||||
fs.BoolVar(&l.LeaderElect, "leader-elect", l.LeaderElect, ""+
|
|
||||||
"Start a leader election client and gain leadership before "+
|
|
||||||
"executing the main loop. Enable this when running replicated "+
|
|
||||||
"components for high availability.")
|
|
||||||
fs.DurationVar(&l.LeaseDuration.Duration, "leader-elect-lease-duration", l.LeaseDuration.Duration, ""+
|
|
||||||
"The duration that non-leader candidates will wait after observing a leadership "+
|
|
||||||
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
|
|
||||||
"slot. This is effectively the maximum duration that a leader can be stopped "+
|
|
||||||
"before it is replaced by another candidate. This is only applicable if leader "+
|
|
||||||
"election is enabled.")
|
|
||||||
fs.DurationVar(&l.RenewDeadline.Duration, "leader-elect-renew-deadline", l.RenewDeadline.Duration, ""+
|
|
||||||
"The interval between attempts by the acting master to renew a leadership slot "+
|
|
||||||
"before it stops leading. This must be less than or equal to the lease duration. "+
|
|
||||||
"This is only applicable if leader election is enabled.")
|
|
||||||
fs.DurationVar(&l.RetryPeriod.Duration, "leader-elect-retry-period", l.RetryPeriod.Duration, ""+
|
|
||||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
|
||||||
"of a leadership. This is only applicable if leader election is enabled.")
|
|
||||||
fs.StringVar(&l.ResourceLock, "leader-elect-resource-lock", l.ResourceLock, ""+
|
|
||||||
"The type of resource object that is used for locking during "+
|
|
||||||
"leader election. Supported options are `endpoints` (default) and `configmaps`.")
|
|
||||||
}
|
|
||||||
39
vendor/k8s.io/kubernetes/pkg/util/metrics/BUILD
generated
vendored
39
vendor/k8s.io/kubernetes/pkg/util/metrics/BUILD
generated
vendored
@@ -1,39 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
"go_test",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = ["util.go"],
|
|
||||||
importpath = "k8s.io/kubernetes/pkg/util/metrics",
|
|
||||||
deps = [
|
|
||||||
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
|
|
||||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
go_test(
|
|
||||||
name = "go_default_test",
|
|
||||||
srcs = ["util_test.go"],
|
|
||||||
embed = [":go_default_library"],
|
|
||||||
deps = [
|
|
||||||
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [":package-srcs"],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
||||||
76
vendor/k8s.io/kubernetes/pkg/util/metrics/util.go
generated
vendored
76
vendor/k8s.io/kubernetes/pkg/util/metrics/util.go
generated
vendored
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2015 The Kubernetes 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 metrics
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
metricsLock sync.Mutex
|
|
||||||
rateLimiterMetrics = make(map[string]*rateLimiterMetric)
|
|
||||||
)
|
|
||||||
|
|
||||||
type rateLimiterMetric struct {
|
|
||||||
metric prometheus.Gauge
|
|
||||||
stopCh chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerRateLimiterMetric(ownerName string) error {
|
|
||||||
metricsLock.Lock()
|
|
||||||
defer metricsLock.Unlock()
|
|
||||||
|
|
||||||
if _, ok := rateLimiterMetrics[ownerName]; ok {
|
|
||||||
// only register once in Prometheus. We happen to see an ownerName reused in parallel integration tests.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
metric := prometheus.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Name: "rate_limiter_use",
|
|
||||||
Subsystem: ownerName,
|
|
||||||
Help: fmt.Sprintf("A metric measuring the saturation of the rate limiter for %v", ownerName),
|
|
||||||
})
|
|
||||||
if err := prometheus.Register(metric); err != nil {
|
|
||||||
return fmt.Errorf("error registering rate limiter usage metric: %v", err)
|
|
||||||
}
|
|
||||||
stopCh := make(chan struct{})
|
|
||||||
rateLimiterMetrics[ownerName] = &rateLimiterMetric{
|
|
||||||
metric: metric,
|
|
||||||
stopCh: stopCh,
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterMetricAndTrackRateLimiterUsage registers a metric ownerName_rate_limiter_use in prometheus to track
|
|
||||||
// how much used rateLimiter is and starts a goroutine that updates this metric every updatePeriod
|
|
||||||
func RegisterMetricAndTrackRateLimiterUsage(ownerName string, rateLimiter flowcontrol.RateLimiter) error {
|
|
||||||
if err := registerRateLimiterMetric(ownerName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// TODO: determine how to track rate limiter saturation
|
|
||||||
// See discussion at https://go-review.googlesource.com/c/time/+/29958#message-4caffc11669cadd90e2da4c05122cfec50ea6a22
|
|
||||||
// go wait.Until(func() {
|
|
||||||
// metricsLock.Lock()
|
|
||||||
// defer metricsLock.Unlock()
|
|
||||||
// rateLimiterMetrics[ownerName].metric.Set()
|
|
||||||
// }, updatePeriod, rateLimiterMetrics[ownerName].stopCh)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
6
vendor/modules.txt
vendored
6
vendor/modules.txt
vendored
@@ -1320,13 +1320,7 @@ k8s.io/kube-openapi/pkg/handler
|
|||||||
k8s.io/kube-openapi/pkg/util
|
k8s.io/kube-openapi/pkg/util
|
||||||
k8s.io/kube-openapi/pkg/util/proto
|
k8s.io/kube-openapi/pkg/util/proto
|
||||||
k8s.io/kube-openapi/pkg/util/sets
|
k8s.io/kube-openapi/pkg/util/sets
|
||||||
# k8s.io/kubernetes v1.13.6 => k8s.io/kubernetes v1.13.6
|
|
||||||
k8s.io/kubernetes/pkg/client/leaderelectionconfig
|
|
||||||
k8s.io/kubernetes/pkg/util/metrics
|
|
||||||
# openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c => openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c
|
# openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c => openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c
|
||||||
openpitrix.io/openpitrix/pkg/client
|
|
||||||
openpitrix.io/openpitrix/pkg/client/access
|
|
||||||
openpitrix.io/openpitrix/pkg/client/account
|
|
||||||
openpitrix.io/openpitrix/pkg/config
|
openpitrix.io/openpitrix/pkg/config
|
||||||
openpitrix.io/openpitrix/pkg/constants
|
openpitrix.io/openpitrix/pkg/constants
|
||||||
openpitrix.io/openpitrix/pkg/db
|
openpitrix.io/openpitrix/pkg/db
|
||||||
|
|||||||
73
vendor/openpitrix.io/openpitrix/pkg/client/access/client.go
generated
vendored
73
vendor/openpitrix.io/openpitrix/pkg/client/access/client.go
generated
vendored
@@ -1,73 +0,0 @@
|
|||||||
// Copyright 2018 The OpenPitrix Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a Apache license
|
|
||||||
// that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package access
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
accountclient "openpitrix.io/openpitrix/pkg/client/account"
|
|
||||||
"openpitrix.io/openpitrix/pkg/constants"
|
|
||||||
"openpitrix.io/openpitrix/pkg/logger"
|
|
||||||
"openpitrix.io/openpitrix/pkg/manager"
|
|
||||||
"openpitrix.io/openpitrix/pkg/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Client struct {
|
|
||||||
pb.AccessManagerClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClient() (*Client, error) {
|
|
||||||
conn, err := manager.NewClient(constants.AccountServiceHost, constants.AccountServicePort)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Client{
|
|
||||||
AccessManagerClient: pb.NewAccessManagerClient(conn),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) CheckActionBundleUser(ctx context.Context, actionBundleIds []string, userId string) bool {
|
|
||||||
users, err := c.GetActionBundleUsers(ctx, actionBundleIds)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, user := range users {
|
|
||||||
if user.GetUserId().GetValue() == userId {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetActionBundleRoles(ctx context.Context, actionBundleIds []string) ([]*pb.Role, error) {
|
|
||||||
response, err := c.DescribeRoles(ctx, &pb.DescribeRolesRequest{
|
|
||||||
ActionBundleId: actionBundleIds,
|
|
||||||
Status: []string{constants.StatusActive},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "Describe roles failed: %+v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.RoleSet, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetActionBundleUsers(ctx context.Context, actionBundleIds []string) ([]*pb.User, error) {
|
|
||||||
roles, err := c.GetActionBundleRoles(ctx, actionBundleIds)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var roleIds []string
|
|
||||||
for _, role := range roles {
|
|
||||||
roleIds = append(roleIds, role.RoleId)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountClient, err := accountclient.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "Get account manager client failed: %+v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return accountClient.GetRoleUsers(ctx, roleIds)
|
|
||||||
}
|
|
||||||
142
vendor/openpitrix.io/openpitrix/pkg/client/account/client.go
generated
vendored
142
vendor/openpitrix.io/openpitrix/pkg/client/account/client.go
generated
vendored
@@ -1,142 +0,0 @@
|
|||||||
// Copyright 2018 The OpenPitrix Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a Apache license
|
|
||||||
// that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"openpitrix.io/openpitrix/pkg/constants"
|
|
||||||
"openpitrix.io/openpitrix/pkg/logger"
|
|
||||||
"openpitrix.io/openpitrix/pkg/manager"
|
|
||||||
"openpitrix.io/openpitrix/pkg/pb"
|
|
||||||
"openpitrix.io/openpitrix/pkg/util/pbutil"
|
|
||||||
"openpitrix.io/openpitrix/pkg/util/stringutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Client struct {
|
|
||||||
pb.AccountManagerClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClient() (*Client, error) {
|
|
||||||
conn, err := manager.NewClient(constants.AccountServiceHost, constants.AccountServicePort)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Client{
|
|
||||||
AccountManagerClient: pb.NewAccountManagerClient(conn),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetUsers(ctx context.Context, userIds []string) ([]*pb.User, error) {
|
|
||||||
var internalUsers []*pb.User
|
|
||||||
var noInternalUserIds []string
|
|
||||||
for _, userId := range userIds {
|
|
||||||
if stringutil.StringIn(userId, constants.InternalUsers) {
|
|
||||||
internalUsers = append(internalUsers, &pb.User{
|
|
||||||
UserId: pbutil.ToProtoString(userId),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
noInternalUserIds = append(noInternalUserIds, userId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(noInternalUserIds) == 0 {
|
|
||||||
return internalUsers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := c.DescribeUsers(ctx, &pb.DescribeUsersRequest{
|
|
||||||
UserId: noInternalUserIds,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "Describe users %s failed: %+v", noInternalUserIds, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(response.UserSet) != len(noInternalUserIds) {
|
|
||||||
logger.Error(ctx, "Describe users %s with return count [%d]", userIds, len(response.UserSet)+len(internalUsers))
|
|
||||||
return nil, fmt.Errorf("describe users %s with return count [%d]", userIds, len(response.UserSet)+len(internalUsers))
|
|
||||||
}
|
|
||||||
response.UserSet = append(response.UserSet, internalUsers...)
|
|
||||||
return response.UserSet, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetUser(ctx context.Context, userId string) (*pb.User, error) {
|
|
||||||
users, err := c.GetUsers(ctx, []string{userId})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(users) == 0 {
|
|
||||||
return nil, fmt.Errorf("not found user [%s]", userId)
|
|
||||||
}
|
|
||||||
return users[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetUserGroupPath(ctx context.Context, userId string) (string, error) {
|
|
||||||
var userGroupPath string
|
|
||||||
|
|
||||||
response, err := c.DescribeUsersDetail(ctx, &pb.DescribeUsersRequest{
|
|
||||||
UserId: []string{userId},
|
|
||||||
})
|
|
||||||
if err != nil || len(response.UserDetailSet) == 0 {
|
|
||||||
logger.Error(ctx, "Describe user [%s] failed: %+v", userId, err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
groups := response.UserDetailSet[0].GroupSet
|
|
||||||
|
|
||||||
//If one user under different groups, get the highest group path.
|
|
||||||
minLevel := math.MaxInt32
|
|
||||||
for _, group := range groups {
|
|
||||||
level := len(strings.Split(group.GroupPath.GetValue(), "."))
|
|
||||||
if level < minLevel {
|
|
||||||
minLevel = level
|
|
||||||
userGroupPath = group.GetGroupPath().GetValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return userGroupPath, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetRoleUsers(ctx context.Context, roleIds []string) ([]*pb.User, error) {
|
|
||||||
response, err := c.DescribeUsers(ctx, &pb.DescribeUsersRequest{
|
|
||||||
RoleId: roleIds,
|
|
||||||
Status: []string{constants.StatusActive},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "Describe users failed: %+v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.UserSet, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetIsvFromUser(ctx context.Context, userId string) (*pb.User, error) {
|
|
||||||
groupPath, err := c.GetUserGroupPath(ctx, userId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rootGroupId := strings.Split(groupPath, ".")[0]
|
|
||||||
|
|
||||||
describeUsersResponse, err := c.DescribeUsers(ctx, &pb.DescribeUsersRequest{
|
|
||||||
RootGroupId: []string{rootGroupId},
|
|
||||||
Status: []string{constants.StatusActive},
|
|
||||||
RoleId: []string{constants.RoleIsv},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(ctx, "Failed to describe users: %+v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(describeUsersResponse.UserSet) == 0 {
|
|
||||||
logger.Error(ctx, "Isv not exist with root group id [%s]", rootGroupId)
|
|
||||||
return nil, fmt.Errorf("isv not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
return describeUsersResponse.UserSet[0], nil
|
|
||||||
}
|
|
||||||
35
vendor/openpitrix.io/openpitrix/pkg/client/client.go
generated
vendored
35
vendor/openpitrix.io/openpitrix/pkg/client/client.go
generated
vendored
@@ -1,35 +0,0 @@
|
|||||||
// Copyright 2018 The OpenPitrix Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a Apache license
|
|
||||||
// that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
accessclient "openpitrix.io/openpitrix/pkg/client/access"
|
|
||||||
"openpitrix.io/openpitrix/pkg/pb"
|
|
||||||
"openpitrix.io/openpitrix/pkg/sender"
|
|
||||||
"openpitrix.io/openpitrix/pkg/util/ctxutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetSystemUserToContext(ctx context.Context) context.Context {
|
|
||||||
return ctxutil.ContextWithSender(ctx, sender.GetSystemSender())
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetUserToContext(ctx context.Context, userId, apiMethod string) (context.Context, error) {
|
|
||||||
accessClient, err := accessclient.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response, err := accessClient.CanDo(ctx, &pb.CanDoRequest{
|
|
||||||
UserId: userId,
|
|
||||||
ApiMethod: apiMethod,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
userSender := sender.New(response.UserId, sender.OwnerPath(response.OwnerPath), sender.OwnerPath(response.AccessPath))
|
|
||||||
return ctxutil.ContextWithSender(ctx, userSender), nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user