-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientset.go
97 lines (81 loc) · 2.27 KB
/
clientset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package v1
import (
"context"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
)
type WorkFlowV1Interface interface {
WorkFlows(namespace string) WorkFlowInterface
}
type WorkFlowClient struct {
restClient rest.Interface
}
type WorkFlowInterface interface {
List() (*WorkflowList, error)
Get(name string) (*Workflow, error)
Put(name string, workflow *Workflow) (*Workflow, error)
//Create(*v1alpha1.Project) (*v1alpha1.Project, error)
//Watch(opts metav1.ListOptions) (watch.Interface, error)
}
type workflowclient struct {
restClient rest.Interface
ns string
}
func NewForConfig(config *rest.Config) (*WorkFlowClient, error) {
crdConfig := *config
crdConfig.ContentConfig.GroupVersion = &schema.GroupVersion{Group: "trinity.cloudlego.com", Version: "v1"}
crdConfig.APIPath = "/apis"
crdConfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent()
client, err := rest.RESTClientFor(&crdConfig)
if err != nil {
logrus.Fatalf("Error occured while creating workflow client:%v", err)
}
return &WorkFlowClient{restClient: client}, nil
}
func (c *WorkFlowClient) WorkFlows(namespace string) WorkFlowInterface {
return &workflowclient{
restClient: c.restClient,
ns: namespace,
}
}
func (c *workflowclient) List() (*WorkflowList, error) {
result := WorkflowList{}
err := c.restClient.
Get().
Namespace(c.ns).
Resource("workflows").
//VersionedParams(&opts, scheme.ParameterCodec).
Do(context.Background()).
Into(&result)
return &result, err
}
func (c *workflowclient) Get(name string) (*Workflow, error) {
result := Workflow{}
err := c.restClient.
Get().
Namespace(c.ns).
Resource("workflows").
Name(name).
SubResource("status").
//VersionedParams(&opts, scheme.ParameterCodec).
Do(context.Background()).
Into(&result)
return &result, err
}
func (c *workflowclient) Put(name string, workflow *Workflow) (*Workflow, error) {
result := Workflow{}
err := c.restClient.
Put().
Namespace(c.ns).
Resource("workflows").
Name(name).
SubResource("status").
Body(workflow).
//VersionedParams(&opts, scheme.ParameterCodec).
Do(context.Background()).
Into(&result)
return &result, err
}