提交 ece90498 编写于 作者: H hongming 提交者: zryfish

automatically create kubeconfig

Signed-off-by: Nhongming <talonwan@yunify.com>
上级 da0ca36d
...@@ -30,16 +30,8 @@ spec: ...@@ -30,16 +30,8 @@ spec:
properties: properties:
manager: manager:
type: string type: string
quotas:
type: object
type: object type: object
status: status:
properties:
quotas:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: object
type: object type: object
version: v1alpha1 version: v1alpha1
status: status:
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package v1alpha1 package v1alpha1
import ( import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
...@@ -28,15 +27,13 @@ import ( ...@@ -28,15 +27,13 @@ import (
// WorkspaceSpec defines the desired state of Workspace // WorkspaceSpec defines the desired state of Workspace
type WorkspaceSpec struct { type WorkspaceSpec struct {
Manager string `json:"manager,omitempty"` Manager string `json:"manager,omitempty"`
Quotas v1.ResourceQuotaSpec `json:"quotas,omitempty"`
} }
// WorkspaceStatus defines the observed state of Workspace // WorkspaceStatus defines the observed state of Workspace
type WorkspaceStatus struct { type WorkspaceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file // Important: Run "make" to regenerate code after modifying this file
Quotas v1.ResourceQuotaStatus `json:"quotas,omitempty"`
} }
// +genclient // +genclient
......
...@@ -21,7 +21,7 @@ limitations under the License. ...@@ -21,7 +21,7 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
) )
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
...@@ -29,8 +29,8 @@ func (in *Workspace) DeepCopyInto(out *Workspace) { ...@@ -29,8 +29,8 @@ func (in *Workspace) DeepCopyInto(out *Workspace) {
*out = *in *out = *in
out.TypeMeta = in.TypeMeta out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec) out.Spec = in.Spec
in.Status.DeepCopyInto(&out.Status) out.Status = in.Status
return return
} }
...@@ -88,7 +88,6 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object { ...@@ -88,7 +88,6 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *WorkspaceSpec) DeepCopyInto(out *WorkspaceSpec) { func (in *WorkspaceSpec) DeepCopyInto(out *WorkspaceSpec) {
*out = *in *out = *in
in.Quotas.DeepCopyInto(&out.Quotas)
return return
} }
...@@ -105,7 +104,6 @@ func (in *WorkspaceSpec) DeepCopy() *WorkspaceSpec { ...@@ -105,7 +104,6 @@ func (in *WorkspaceSpec) DeepCopy() *WorkspaceSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *WorkspaceStatus) DeepCopyInto(out *WorkspaceStatus) { func (in *WorkspaceStatus) DeepCopyInto(out *WorkspaceStatus) {
*out = *in *out = *in
in.Quotas.DeepCopyInto(&out.Quotas)
return return
} }
......
...@@ -19,6 +19,7 @@ package resources ...@@ -19,6 +19,7 @@ package resources
import ( import (
"github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/errors" "kubesphere.io/kubesphere/pkg/errors"
...@@ -42,6 +43,7 @@ func ApplicationHandler(req *restful.Request, resp *restful.Response) { ...@@ -42,6 +43,7 @@ func ApplicationHandler(req *restful.Request, resp *restful.Response) {
if len(clusterId) > 0 { if len(clusterId) > 0 {
app, err := applications.GetApp(clusterId) app, err := applications.GetApp(clusterId)
if err != nil { if err != nil {
glog.Errorln("get application error", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return return
} }
...@@ -66,14 +68,13 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response) ...@@ -66,14 +68,13 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
clusterId := req.QueryParameter("cluster_id") clusterId := req.QueryParameter("cluster_id")
conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam)) conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam))
if err != nil { if err != nil {
if err != nil { resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err)) return
return
}
} }
if len(clusterId) > 0 { if len(clusterId) > 0 {
app, err := applications.GetApp(clusterId) app, err := applications.GetApp(clusterId)
if err != nil { if err != nil {
glog.Errorln("get app failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return return
} }
...@@ -84,6 +85,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response) ...@@ -84,6 +85,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
namespace, err := resources.GetResource("", resources.Namespaces, namespaceName) namespace, err := resources.GetResource("", resources.Namespaces, namespaceName)
if err != nil { if err != nil {
glog.Errorln("get namespace failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return return
} }
...@@ -95,6 +97,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response) ...@@ -95,6 +97,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
} }
if runtimeId == "" { if runtimeId == "" {
glog.Errorln("runtime id not found")
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.New("openpitrix runtime not init")) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.New("openpitrix runtime not init"))
return return
} }
...@@ -102,6 +105,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response) ...@@ -102,6 +105,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
result, err := applications.ListApplication(runtimeId, conditions, limit, offset) result, err := applications.ListApplication(runtimeId, conditions, limit, offset)
if err != nil { if err != nil {
glog.Errorln("list applications failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return return
} }
......
...@@ -19,6 +19,7 @@ package resources ...@@ -19,6 +19,7 @@ package resources
import ( import (
"github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"net/http" "net/http"
"kubesphere.io/kubesphere/pkg/errors" "kubesphere.io/kubesphere/pkg/errors"
...@@ -47,7 +48,14 @@ func GetKubeconfig(req *restful.Request, resp *restful.Response) { ...@@ -47,7 +48,14 @@ func GetKubeconfig(req *restful.Request, resp *restful.Response) {
kubectlConfig, err := kubeconfig.GetKubeConfig(user) kubectlConfig, err := kubeconfig.GetKubeConfig(user)
if err != nil { if err != nil {
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) if k8serr.IsNotFound(err) {
// recreate
kubeconfig.CreateKubeConfig(user)
resp.WriteHeaderAndEntity(http.StatusNotFound, errors.Wrap(err))
} else {
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
}
return return
} }
......
...@@ -19,9 +19,9 @@ limitations under the License. ...@@ -19,9 +19,9 @@ limitations under the License.
package versioned package versioned
import ( import (
"k8s.io/client-go/discovery" discovery "k8s.io/client-go/discovery"
"k8s.io/client-go/rest" rest "k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol" flowcontrol "k8s.io/client-go/util/flowcontrol"
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2"
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1"
) )
......
...@@ -19,10 +19,10 @@ limitations under the License. ...@@ -19,10 +19,10 @@ limitations under the License.
package fake package fake
import ( import (
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer" serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
......
...@@ -19,10 +19,10 @@ limitations under the License. ...@@ -19,10 +19,10 @@ limitations under the License.
package scheme package scheme
import ( import (
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer" serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
......
...@@ -19,9 +19,9 @@ limitations under the License. ...@@ -19,9 +19,9 @@ limitations under the License.
package fake package fake
import ( import (
"k8s.io/client-go/rest" rest "k8s.io/client-go/rest"
"k8s.io/client-go/testing" testing "k8s.io/client-go/testing"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1"
) )
type FakeTenantV1alpha1 struct { type FakeTenantV1alpha1 struct {
......
...@@ -19,13 +19,13 @@ limitations under the License. ...@@ -19,13 +19,13 @@ limitations under the License.
package fake package fake
import ( import (
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" labels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema" schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" types "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch" watch "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/testing" testing "k8s.io/client-go/testing"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
) )
// FakeWorkspaces implements WorkspaceInterface // FakeWorkspaces implements WorkspaceInterface
......
...@@ -19,9 +19,9 @@ limitations under the License. ...@@ -19,9 +19,9 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"k8s.io/apimachinery/pkg/runtime/serializer" serializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest" rest "k8s.io/client-go/rest"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme" "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
) )
......
...@@ -21,12 +21,12 @@ package v1alpha1 ...@@ -21,12 +21,12 @@ package v1alpha1
import ( import (
"time" "time"
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" types "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch" watch "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/rest" rest "k8s.io/client-go/rest"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme" scheme "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
) )
// WorkspacesGetter has a method to return a WorkspaceInterface. // WorkspacesGetter has a method to return a WorkspaceInterface.
......
...@@ -19,18 +19,18 @@ limitations under the License. ...@@ -19,18 +19,18 @@ limitations under the License.
package externalversions package externalversions
import ( import (
"reflect" reflect "reflect"
"sync" sync "sync"
"time" time "time"
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache" cache "k8s.io/client-go/tools/cache"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned" versioned "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/servicemesh" servicemesh "kubesphere.io/kubesphere/pkg/client/informers/externalversions/servicemesh"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant" tenant "kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant"
) )
// SharedInformerOption defines the functional option type for SharedInformerFactory. // SharedInformerOption defines the functional option type for SharedInformerFactory.
......
...@@ -21,10 +21,10 @@ package externalversions ...@@ -21,10 +21,10 @@ package externalversions
import ( import (
"fmt" "fmt"
"k8s.io/apimachinery/pkg/runtime/schema" schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache" cache "k8s.io/client-go/tools/cache"
"kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2" v1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
) )
// GenericInformer is type of SharedIndexInformer which will locate and delegate to other // GenericInformer is type of SharedIndexInformer which will locate and delegate to other
......
...@@ -19,8 +19,8 @@ limitations under the License. ...@@ -19,8 +19,8 @@ limitations under the License.
package tenant package tenant
import ( import (
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant/v1alpha1"
) )
// Interface provides access to each of this group's versions. // Interface provides access to each of this group's versions.
......
...@@ -19,7 +19,7 @@ limitations under the License. ...@@ -19,7 +19,7 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
) )
// Interface provides access to all the informers in this group version. // Interface provides access to all the informers in this group version.
......
...@@ -19,16 +19,16 @@ limitations under the License. ...@@ -19,16 +19,16 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"time" time "time"
"k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch" watch "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache" cache "k8s.io/client-go/tools/cache"
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned" versioned "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces" internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
"kubesphere.io/kubesphere/pkg/client/listers/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/client/listers/tenant/v1alpha1"
) )
// WorkspaceInformer provides access to a shared informer and lister for // WorkspaceInformer provides access to a shared informer and lister for
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1" v1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
) )
// WorkspaceLister helps list Workspaces. // WorkspaceLister helps list Workspaces.
......
...@@ -96,6 +96,7 @@ func GetApp(clusterId string) (*Application, error) { ...@@ -96,6 +96,7 @@ func GetApp(clusterId string) (*Application, error) {
item, err := openpitrix.GetCluster(clusterId) item, err := openpitrix.GetCluster(clusterId)
if err != nil { if err != nil {
glog.Error(err)
return nil, err return nil, err
} }
......
...@@ -30,7 +30,6 @@ import ( ...@@ -30,7 +30,6 @@ import (
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models" "kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/iam/policy" "kubesphere.io/kubesphere/pkg/models/iam/policy"
"kubesphere.io/kubesphere/pkg/models/kubeconfig"
"kubesphere.io/kubesphere/pkg/models/kubectl" "kubesphere.io/kubesphere/pkg/models/kubectl"
"kubesphere.io/kubesphere/pkg/models/resources" "kubesphere.io/kubesphere/pkg/models/resources"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
...@@ -39,6 +38,7 @@ import ( ...@@ -39,6 +38,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/sliceutil" "kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
"time"
) )
const ( const (
...@@ -643,9 +643,6 @@ func CreateClusterRoleBinding(username string, clusterRoleName string) error { ...@@ -643,9 +643,6 @@ func CreateClusterRoleBinding(username string, clusterRoleName string) error {
glog.Errorln("create cluster role binding", err) glog.Errorln("create cluster role binding", err)
return err return err
} }
if err := kubeconfig.CreateKubeConfig(username); err != nil {
glog.Errorln("create user kubeconfig failed", username, err)
}
if clusterRoleName == constants.ClusterAdmin { if clusterRoleName == constants.ClusterAdmin {
if err := kubectl.CreateKubectlDeploy(username); err != nil { if err := kubectl.CreateKubectlDeploy(username); err != nil {
glog.Errorln("create user terminal pod failed", username, err) glog.Errorln("create user terminal pod failed", username, err)
...@@ -667,17 +664,21 @@ func CreateClusterRoleBinding(username string, clusterRoleName string) error { ...@@ -667,17 +664,21 @@ func CreateClusterRoleBinding(username string, clusterRoleName string) error {
return err return err
} }
if found.RoleRef.Name == constants.ClusterAdmin { if found.RoleRef.Name == constants.ClusterAdmin {
if err := kubeconfig.DelKubeConfig(username); err != nil {
glog.Error("delete user kubeconfig failed", username, err)
}
if err := kubectl.DelKubectlDeploy(username); err != nil { if err := kubectl.DelKubectlDeploy(username); err != nil {
glog.Error("delete user terminal pod failed", username, err) glog.Error("delete user terminal pod failed", username, err)
} }
} }
_, err = k8s.Client().RbacV1().ClusterRoleBindings().Create(clusterRoleBinding) maxRetries := 3
if err != nil { for i := 0; i < maxRetries; i++ {
glog.Errorln("create cluster role binding", err) _, err = k8s.Client().RbacV1().ClusterRoleBindings().Create(clusterRoleBinding)
return err if apierrors.IsAlreadyExists(err) {
time.Sleep(300 * time.Millisecond)
continue
}
if err != nil {
glog.Errorln("create cluster role binding", err)
return err
}
} }
return nil return nil
} }
......
...@@ -24,6 +24,8 @@ import ( ...@@ -24,6 +24,8 @@ import (
"io/ioutil" "io/ioutil"
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models/kubeconfig"
"kubesphere.io/kubesphere/pkg/models/kubectl"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/simple/client/k8s" "kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/redis" "kubesphere.io/kubesphere/pkg/simple/client/redis"
...@@ -499,16 +501,24 @@ func DeleteUser(username string) error { ...@@ -499,16 +501,24 @@ func DeleteUser(username string) error {
deleteRequest := ldap.NewDelRequest(fmt.Sprintf("uid=%s,%s", username, ldapclient.UserSearchBase), nil) deleteRequest := ldap.NewDelRequest(fmt.Sprintf("uid=%s,%s", username, ldapclient.UserSearchBase), nil)
err = conn.Del(deleteRequest) if err = conn.Del(deleteRequest); err != nil {
if err != nil {
glog.Errorln("delete user", err) glog.Errorln("delete user", err)
return err return err
} }
err = deleteRoleBindings(username) if err = deleteRoleBindings(username); err != nil {
glog.Errorln("delete user role bindings failed", username, err)
}
if err := kubeconfig.DelKubeConfig(username); err != nil {
glog.Errorln("delete user kubeconfig failed", username, err)
}
return err if err := kubectl.DelKubectlDeploy(username); err != nil {
glog.Errorln("delete user terminal pod failed", username, err)
}
return nil
} }
func deleteRoleBindings(username string) error { func deleteRoleBindings(username string) error {
...@@ -686,6 +696,10 @@ func CreateUser(user *models.User) (*models.User, error) { ...@@ -686,6 +696,10 @@ func CreateUser(user *models.User) (*models.User, error) {
setAvatar(user.Username, user.AvatarUrl) setAvatar(user.Username, user.AvatarUrl)
} }
if err := kubeconfig.CreateKubeConfig(user.Username); err != nil {
glog.Errorln("create user kubeconfig failed", user.Username, err)
}
if user.ClusterRole != "" { if user.ClusterRole != "" {
err := CreateClusterRoleBinding(user.Username, user.ClusterRole) err := CreateClusterRoleBinding(user.Username, user.ClusterRole)
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/params" "kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil" "kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort" "sort"
"strings" "strings"
...@@ -60,6 +61,14 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool { ...@@ -60,6 +61,14 @@ func (*jobSearcher) match(match map[string]string, item *batchv1.Job) bool {
if jobStatus(item) != v { if jobStatus(item) != v {
return false return false
} }
case includeCronJob:
if v == "false" && k8sutil.IsControlledBy(item.OwnerReferences, cronJobKind, "") {
return false
}
case includeS2iRun:
if v == "false" && k8sutil.IsControlledBy(item.OwnerReferences, s2iRunKind, "") {
return false
}
case Name: case Name:
names := strings.Split(v, "|") names := strings.Split(v, "|")
if !sliceutil.HasString(names, item.Name) { if !sliceutil.HasString(names, item.Name) {
......
...@@ -68,6 +68,10 @@ const ( ...@@ -68,6 +68,10 @@ const (
annotation = "annotation" annotation = "annotation"
Keyword = "keyword" Keyword = "keyword"
status = "status" status = "status"
includeCronJob = "includeCronJob"
cronJobKind = "CronJob"
s2iRunKind = "S2iRun"
includeS2iRun = "includeS2iRun"
running = "running" running = "running"
paused = "paused" paused = "paused"
updating = "updating" updating = "updating"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册