/
resource_interface.go
129 lines (121 loc) · 6.36 KB
/
resource_interface.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//nolint:dupl // Lines are similar but not duplicated and can't be refactored to avloid this error.
package resource
import (
"context"
configV1alpha1 "github.com/stolostron/submariner-addon/pkg/apis/submarinerconfig/v1alpha1"
cfgv1a1clnt "github.com/stolostron/submariner-addon/pkg/client/submarinerconfig/clientset/versioned/typed/submarinerconfig/v1alpha1"
"github.com/submariner-io/admiral/pkg/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
addonV1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonV1alpha1Client "open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1alpha1"
clusterV1Client "open-cluster-management.io/api/client/cluster/clientset/versioned/typed/cluster/v1"
clusterV1beta2Client "open-cluster-management.io/api/client/cluster/clientset/versioned/typed/cluster/v1beta2"
workclient "open-cluster-management.io/api/client/work/clientset/versioned/typed/work/v1"
clusterV1 "open-cluster-management.io/api/cluster/v1"
clusterV1beta2 "open-cluster-management.io/api/cluster/v1beta2"
workv1 "open-cluster-management.io/api/work/v1"
)
func ForManagedClusterSet(client clusterV1beta2Client.ManagedClusterSetInterface) resource.Interface[*clusterV1beta2.ManagedClusterSet] {
return &resource.InterfaceFuncs[*clusterV1beta2.ManagedClusterSet]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*clusterV1beta2.ManagedClusterSet, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *clusterV1beta2.ManagedClusterSet, options metav1.CreateOptions,
) (*clusterV1beta2.ManagedClusterSet, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *clusterV1beta2.ManagedClusterSet, options metav1.UpdateOptions,
) (*clusterV1beta2.ManagedClusterSet, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}
func ForManagedCluster(client clusterV1Client.ManagedClusterInterface) resource.Interface[*clusterV1.ManagedCluster] {
return &resource.InterfaceFuncs[*clusterV1.ManagedCluster]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*clusterV1.ManagedCluster, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *clusterV1.ManagedCluster, options metav1.CreateOptions) (*clusterV1.ManagedCluster, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *clusterV1.ManagedCluster, options metav1.UpdateOptions) (*clusterV1.ManagedCluster, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}
func ForAddon(client addonV1alpha1Client.ManagedClusterAddOnInterface) resource.Interface[*addonV1alpha1.ManagedClusterAddOn] {
return &resource.InterfaceFuncs[*addonV1alpha1.ManagedClusterAddOn]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*addonV1alpha1.ManagedClusterAddOn, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *addonV1alpha1.ManagedClusterAddOn, options metav1.CreateOptions,
) (*addonV1alpha1.ManagedClusterAddOn, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *addonV1alpha1.ManagedClusterAddOn, options metav1.UpdateOptions,
) (*addonV1alpha1.ManagedClusterAddOn, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}
func ForClusterAddon(client addonV1alpha1Client.ClusterManagementAddOnInterface) resource.Interface[*addonV1alpha1.ClusterManagementAddOn] {
return &resource.InterfaceFuncs[*addonV1alpha1.ClusterManagementAddOn]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*addonV1alpha1.ClusterManagementAddOn, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *addonV1alpha1.ClusterManagementAddOn, options metav1.CreateOptions,
) (*addonV1alpha1.ClusterManagementAddOn, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *addonV1alpha1.ClusterManagementAddOn, options metav1.UpdateOptions,
) (*addonV1alpha1.ClusterManagementAddOn, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}
func ForSubmarinerConfig(client cfgv1a1clnt.SubmarinerConfigInterface) resource.Interface[*configV1alpha1.SubmarinerConfig] {
return &resource.InterfaceFuncs[*configV1alpha1.SubmarinerConfig]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*configV1alpha1.SubmarinerConfig, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *configV1alpha1.SubmarinerConfig, options metav1.CreateOptions,
) (*configV1alpha1.SubmarinerConfig, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *configV1alpha1.SubmarinerConfig, options metav1.UpdateOptions,
) (*configV1alpha1.SubmarinerConfig, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}
func ForManifestWork(client workclient.ManifestWorkInterface) resource.Interface[*workv1.ManifestWork] {
return &resource.InterfaceFuncs[*workv1.ManifestWork]{
GetFunc: func(ctx context.Context, name string, options metav1.GetOptions) (*workv1.ManifestWork, error) {
return client.Get(ctx, name, options)
},
CreateFunc: func(ctx context.Context, obj *workv1.ManifestWork, options metav1.CreateOptions) (*workv1.ManifestWork, error) {
return client.Create(ctx, obj, options)
},
UpdateFunc: func(ctx context.Context, obj *workv1.ManifestWork, options metav1.UpdateOptions) (*workv1.ManifestWork, error) {
return client.Update(ctx, obj, options)
},
DeleteFunc: func(ctx context.Context, name string, options metav1.DeleteOptions) error {
return client.Delete(ctx, name, options)
},
}
}