example
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import ( "fmt" v1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/remotecommand" "log" "os")con...
简单的一个例子
1234567891011121314151617181920....gr, err := restmapper.GetAPIGroupResources(client.Discovery()) if err != nil { log.Fatal(err) } mapper := restmapper.NewDiscoveryRESTMapper(gr) mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version) if err != nil { log.F...
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package k8sconfigimport ( v1 "github.com/haojianxun/dbcore/pkg/apis/dbconfig/v1" "github.com/haojianxun/dbcore/pkg/controllers" "github.com/haojianxun/dbcore/pkg/dashboard" appsv1 "k8s.io/api/apps/v1" "os...
在mgr的地方添加即可开启
12345678mgr,err:=manager.New(K8sconfig, manager.Options{ Logger: logf.Log.WithName("dbconfig"), Leaderelection: true, LeaderElectionID: "mydbconfig-lock",//这个就是那个选主的名字 LeaderElectionNamespace: "default", //这个步在哪个空间中 })
这个是官方文档的说明
https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/
1234567891011121314151617181920212223242526272829303132333435//假设下面的前端提交的import(...."k8s.io/apimachinery/pkg/util/json")func main(){ctx:=context.Background()//create clientsetclientset:=con...
下面是个例子
他是用在测试中的 就是创建出一个假的client 而不是用真实环境中的client
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647package mainimport ( "context" "fmt" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubern...
1234567891011121314151617181920212223242526272829package mainimport ( "context" "fmt" "io" v1 "k8s.io/api/core/v1" "k8sapi/src/configs")func main(){ client:= configs.NewK8sConfig().InitClient() //req:= client.CoreV1().Pods("default").GetLogs("deploy-nginx-5745bb45d7-b7wsv",&v1.PodLogOpti...
前提:
要在crd中的定义yaml文件上写上这个
1234567status: type: object properties: replicas: type: integer ready: type: string
这个ready就是状态中要显示的
之后在设置自定义资源的时候 在type中也写上这个状态的字段 就是在status中(我加的字段是ready字段)
之后就代码的编写了
第一步 先要在控制器中去watch他的变化, 比如update的变化, 并写个函数
12345678910111213....if err = build...
example:
12345678910111213141516171819func (r *MemcachedReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { ... dep := &v1.Deployment{} err := r.Get(ctx, request.NamespacedName, dep) ... // A merge patch will preserve other fields ...
方法1:
12345678910111213func (this *ResourcesCtl) ListResources(c *gin.Context) goft.Json{ _,res,err:=this.Client.ServerGroupsAndResources() goft.Error(err) gRes:= make([]*GroupResources,0) for _,r := range res{ group,version:=this.GetGroupVersion(r.GroupVersion) gr:= &a...