1 Star 0 Fork 0

不平凡的平凡/dogo

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ingresses.go 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
lixueping 提交于 2022-10-18 01:10 +08:00 . 新增常用公共方法
/*
Copyright 2019 The KubeSphere 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 ingress
import (
"context"
v1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"gitee.com/lflxp/dogo/plugin/apicache/pkg/api"
"gitee.com/lflxp/dogo/plugin/apicache/pkg/apiserver/query"
v1alpha3 "gitee.com/lflxp/dogo/plugin/apicache/pkg/resources/v1"
)
type ingressGetter struct {
client client.Client
}
func New(client client.Client) v1alpha3.Interface {
return &ingressGetter{client: client}
}
func (i *ingressGetter) Get(namespace, name string) (runtime.Object, error) {
ctx := context.Background()
cm := &v1.Ingress{}
err := i.client.Get(ctx, types.NamespacedName{Name: name}, cm)
return cm, err
}
func (i *ingressGetter) List(namespace string, query *query.Query) (*api.ListResult, error) {
ctx := context.Background()
list := &v1.IngressList{}
options := client.ListOptions{
LabelSelector: query.Selector(),
}
// first retrieves all tenant within given namespace
err := i.client.List(ctx, list, &options)
if err != nil {
return nil, err
}
var result []runtime.Object
for _, user := range list.Items {
tmp := user
result = append(result, &tmp)
}
return v1alpha3.DefaultList(result, query, i.compare, i.filter), nil
}
func (i *ingressGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
leftIngress, ok := left.(*v1.Ingress)
if !ok {
return false
}
rightIngress, ok := right.(*v1.Ingress)
if !ok {
return false
}
switch field {
case query.FieldUpdateTime:
fallthrough
default:
return v1alpha3.DefaultObjectMetaCompare(leftIngress.ObjectMeta, rightIngress.ObjectMeta, field)
}
}
func (i *ingressGetter) filter(object runtime.Object, filter query.Filter) bool {
deployment, ok := object.(*v1.Ingress)
if !ok {
return false
}
return v1alpha3.DefaultObjectMetaFilter(deployment.ObjectMeta, filter)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lflxp/dogo.git
git@gitee.com:lflxp/dogo.git
lflxp
dogo
dogo
v0.1.0

搜索帮助