75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
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())
|
|
}
|