Skip to content

Commit 4407f84

Browse files
committed
generate crd using controller-gen
Signed-off-by: Shovan Maity <[email protected]>
1 parent 8cda47f commit 4407f84

23 files changed

+776
-142
lines changed

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ QUAY_USERNAME ?= shovanmaity
22
LATEST_TAG ?= latest
33
IMAGE_TAG ?= 0.0.1
44

5+
.PHONY: crd-gen
6+
crd-gen:
7+
controller-gen crd:crdVersions=v1 paths=./client/apis/kvm.io/v1
8+
controller-gen object paths=./client/apis/kvm.io/v1/types.go
9+
510
##
611
.PHONY: rsync-image
712
rsync-image:

app/populator/claim/controller.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"k8s.io/client-go/tools/cache"
2929
"k8s.io/client-go/util/workqueue"
3030
"k8s.io/klog/v2"
31+
32+
internalv1 "github.com/shovanmaity/kvm/client/apis/kvm.io/v1"
3133
)
3234

3335
const (
@@ -215,13 +217,13 @@ func (c *controller) syncPvc(ctx context.Context, key, namespace, name string) (
215217
}
216218
return false, err
217219
}
218-
populator := VolumeClaimPopulator{}
220+
populator := internalv1.VolumeClaimPopulator{}
219221
if err := runtime.DefaultUnstructuredConverter.
220222
FromUnstructured(unstructured.UnstructuredContent(), &populator); err != nil {
221223
return false, err
222224
}
223225
// Get source PVC
224-
source, err := c.pvcLister.PersistentVolumeClaims(namespace).Get(populator.Spec.Name)
226+
source, err := c.pvcLister.PersistentVolumeClaims(namespace).Get(populator.Spec.PVCName)
225227
if err != nil {
226228
klog.V(2).Infof("Error getting pvc, error: `%s`.", err)
227229
if errors.IsNotFound(err) {
@@ -231,7 +233,7 @@ func (c *controller) syncPvc(ctx context.Context, key, namespace, name string) (
231233
return false, err
232234
}
233235
// If source and pvc name is same then skip
234-
if pvc.Name == populator.Spec.Name {
236+
if pvc.Name == populator.Spec.PVCName {
235237
return true, nil
236238
}
237239
// If storageclass is not present in pvc and storageclass is not matching then skip it

app/populator/claim/types.go

-20
This file was deleted.

app/populator/rsync/main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"k8s.io/apimachinery/pkg/runtime"
1111
"k8s.io/apimachinery/pkg/runtime/schema"
1212
"k8s.io/klog/v2"
13+
14+
internalv1 "github.com/shovanmaity/kvm/client/apis/kvm.io/v1"
1315
)
1416

1517
const (
@@ -46,7 +48,7 @@ func main() {
4648
}
4749

4850
func getPopulatorCmds(rawBlock bool, u *unstructured.Unstructured) ([]string, error) {
49-
populator := RsyncPopulator{}
51+
populator := internalv1.RsyncPopulator{}
5052
err := runtime.DefaultUnstructuredConverter.
5153
FromUnstructured(u.UnstructuredContent(), &populator)
5254
if nil != err {
@@ -59,23 +61,23 @@ func getPopulatorCmds(rawBlock bool, u *unstructured.Unstructured) ([]string, er
5961
}
6062

6163
func getPopulatorArgs(rawBlock bool, u *unstructured.Unstructured) ([]string, error) {
62-
populator := RsyncPopulator{}
64+
populator := internalv1.RsyncPopulator{}
6365
err := runtime.DefaultUnstructuredConverter.
6466
FromUnstructured(u.UnstructuredContent(), &populator)
6567
if nil != err {
6668
return nil, err
6769
}
6870
args := []string{
6971
"-rv",
70-
"rsync://" + populator.Spec.Username + "@" + populator.Spec.Service +
71-
":873" + populator.Spec.Path,
72+
"rsync://" + populator.Spec.Username + "@" +
73+
populator.Spec.URL + populator.Spec.Path,
7274
mountPath,
7375
}
7476
return args, nil
7577
}
7678

7779
func getPopulatorEnvs(u *unstructured.Unstructured) ([]corev1.EnvVar, error) {
78-
populator := RsyncPopulator{}
80+
populator := internalv1.RsyncPopulator{}
7981
err := runtime.DefaultUnstructuredConverter.
8082
FromUnstructured(u.UnstructuredContent(), &populator)
8183
if nil != err {

app/populator/rsync/types.go

-23
This file was deleted.

client/apis/kvm.io/v1/doc.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// +k8s:deepcopy-gen=package
2+
// +groupName=kvm.io
3+
4+
package v1

client/apis/kvm.io/v1/register.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package v1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
)
8+
9+
// GroupName is the group name use in this package.
10+
const GroupName = "kvm.io"
11+
12+
var (
13+
// SchemeBuilder is the new scheme builder
14+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
15+
// AddToScheme adds to scheme
16+
AddToScheme = SchemeBuilder.AddToScheme
17+
// SchemeGroupVersion is the group version used to register these objects.
18+
SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
19+
)
20+
21+
// Resource takes an unqualified resource and returns a Group-qualified GroupResource.
22+
func Resource(resource string) schema.GroupResource {
23+
return SchemeGroupVersion.WithResource(resource).GroupResource()
24+
}
25+
26+
func init() {
27+
// We only register manually written functions here. The registration of the
28+
// generated functions takes place in the generated files. The separation
29+
// makes the code compile even when the generated files are missing.
30+
SchemeBuilder.Register(addKnownTypes)
31+
}
32+
33+
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
34+
func addKnownTypes(scheme *runtime.Scheme) error {
35+
scheme.AddKnownTypes(SchemeGroupVersion,
36+
&RsyncPopulator{},
37+
&RsyncPopulatorList{},
38+
)
39+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
40+
return nil
41+
}

client/apis/kvm.io/v1/types.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// +kubebuilder:object:generate=true
2+
package v1
3+
4+
import (
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
)
7+
8+
// +genclient
9+
// +genclient:nonNamespaced
10+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
11+
// RsyncPopulator is a volume populator that helps
12+
// to create a volume from any rsync source.
13+
type RsyncPopulator struct {
14+
metav1.TypeMeta `json:",inline"`
15+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
16+
17+
// Spec contains details of rsync source/ rsync daemon. Rsync client will
18+
// use these information to get the data for the volume.
19+
Spec RsyncPopulatorSpec `json:"spec"`
20+
}
21+
22+
// RsyncPopulatorSpec contains the information of rsync daemon.
23+
type RsyncPopulatorSpec struct {
24+
// Username is used as credential to access rsync daemon by the client.
25+
Username string `json:"username"`
26+
// Password is used as credential to access rsync daemon by the client.
27+
Password string `json:"password"`
28+
// Path represent mount path of the volume which we want to sync by the clinet.
29+
Path string `json:"path"`
30+
// URL is rsync daemon url it can be dns can be ip:port. Client will use
31+
// it to connect and get the data from daemon.
32+
URL string `json:"url"`
33+
}
34+
35+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
36+
// RsyncPopulatorList is a list of RsyncPopulator objects
37+
type RsyncPopulatorList struct {
38+
metav1.TypeMeta `json:",inline"`
39+
// +optional
40+
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
41+
42+
// List of RsyncPopulators
43+
Items []RsyncPopulator `json:"items" protobuf:"bytes,2,rep,name=items"`
44+
}
45+
46+
// +genclient
47+
// +genclient:nonNamespaced
48+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
49+
// VolumeClaimPopulator is a volume populator that helps to rename a
50+
// PVC by applying patch on the PV of older PVC with new PVC.
51+
type VolumeClaimPopulator struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ObjectMeta `json:"metadata,omitempty"`
54+
// Spec contains volume claim information. ie - PVC name
55+
Spec VolumeClaimPopulatorSpec `json:"spec"`
56+
}
57+
58+
// VolumeClaimPopulatorSpec contains information on Volume Claim.
59+
type VolumeClaimPopulatorSpec struct {
60+
// PVCName is the name of the pvc which we want to rename.
61+
PVCName string `json:"pvcName"`
62+
}
63+
64+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
65+
// VolumeClaimPopulatorList is a list of VolumeClaimPopulator objects
66+
type VolumeClaimPopulatorList struct {
67+
metav1.TypeMeta `json:",inline"`
68+
// +optional
69+
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
70+
71+
// List of VolumeClaimPopulators
72+
Items []VolumeClaimPopulator `json:"items" protobuf:"bytes,2,rep,name=items"`
73+
}

0 commit comments

Comments
 (0)