feat(crd): add kube api and crds
This commit is contained in:
74
internal/crd/client/client.go
Normal file
74
internal/crd/client/client.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type FlinkJobInterface interface {
|
||||
List(opts metav1.ListOptions) (*v1alpha1.FlinkJobList, error)
|
||||
Get(name string, options metav1.GetOptions) (*v1alpha1.FlinkJob, error)
|
||||
Create(*v1alpha1.FlinkJob) (*v1alpha1.FlinkJob, error)
|
||||
Watch(opts metav1.ListOptions) (watch.Interface, error)
|
||||
// ...
|
||||
}
|
||||
|
||||
type FlinkJobClient struct {
|
||||
restClient rest.Interface
|
||||
ns string
|
||||
}
|
||||
|
||||
func (c *FlinkJobClient) List(opts metav1.ListOptions) (*v1alpha1.FlinkJobList, error) {
|
||||
result := v1alpha1.FlinkJobList{}
|
||||
err := c.restClient.
|
||||
Get().
|
||||
Namespace(c.ns).
|
||||
Resource("FlinkJobs").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Do(context.Background()).
|
||||
Into(&result)
|
||||
|
||||
return &result, err
|
||||
}
|
||||
|
||||
func (c *FlinkJobClient) Get(name string, opts metav1.GetOptions) (*v1alpha1.FlinkJob, error) {
|
||||
result := v1alpha1.FlinkJob{}
|
||||
err := c.restClient.
|
||||
Get().
|
||||
Namespace(c.ns).
|
||||
Resource("FlinkJobs").
|
||||
Name(name).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Do(context.Background()).
|
||||
Into(&result)
|
||||
|
||||
return &result, err
|
||||
}
|
||||
|
||||
func (c *FlinkJobClient) Create(FlinkJob *v1alpha1.FlinkJob) (*v1alpha1.FlinkJob, error) {
|
||||
result := v1alpha1.FlinkJob{}
|
||||
err := c.restClient.
|
||||
Post().
|
||||
Namespace(c.ns).
|
||||
Resource("FlinkJobs").
|
||||
Body(FlinkJob).
|
||||
Do(context.Background()).
|
||||
Into(&result)
|
||||
|
||||
return &result, err
|
||||
}
|
||||
|
||||
func (c *FlinkJobClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
opts.Watch = true
|
||||
return c.restClient.
|
||||
Get().
|
||||
Namespace(c.ns).
|
||||
Resource("FlinkJobs").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Watch(context.Background())
|
||||
}
|
||||
Reference in New Issue
Block a user