Skip to content

Commit cb917a1

Browse files
api: add v1beta1 conversion and types for clientprofile
Signed-off-by: Niraj Yadav <[email protected]>
1 parent 5dd4321 commit cb917a1

19 files changed

+938
-0
lines changed

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,17 @@ resources:
6565
spoke:
6666
- v1alpha1
6767
webhookVersion: v1
68+
- api:
69+
crdVersion: v1
70+
namespaced: true
71+
domain: ceph.io
72+
group: csi
73+
kind: ClientProfile
74+
path: github.com/ceph/ceph-csi-operator/api/csi/v1beta1
75+
version: v1beta1
76+
webhooks:
77+
conversion: true
78+
spoke:
79+
- v1alpha1
80+
webhookVersion: v1
6881
version: "3"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"errors"
21+
"log"
22+
23+
"sigs.k8s.io/controller-runtime/pkg/conversion"
24+
25+
csiv1beta1 "github.com/ceph/ceph-csi-operator/api/csi/v1beta1"
26+
)
27+
28+
// ConvertTo converts this ClientProfile (v1alpha1) to the Hub version (v1beta1).
29+
func (src *ClientProfile) ConvertTo(dstRaw conversion.Hub) error {
30+
dst, ok := dstRaw.(*csiv1beta1.ClientProfile)
31+
if !ok {
32+
return errors.New("convertto: failed to cast to v1beta1 ClientProfile")
33+
}
34+
35+
log.Printf("ConvertTo: Converting ClientProfile from Spoke version v1alpha1 to Hub version v1beta1;"+
36+
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
37+
38+
dst.ObjectMeta = src.ObjectMeta
39+
40+
dst.Spec.CephConnectionRef = src.Spec.CephConnectionRef
41+
dst.Spec.CephFs = (*csiv1beta1.CephFsConfigSpec)(src.Spec.CephFs)
42+
dst.Spec.Nfs = (*csiv1beta1.NfsConfigSpec)(src.Spec.Nfs)
43+
dst.Spec.Rbd = (*csiv1beta1.RbdConfigSpec)(src.Spec.Rbd)
44+
45+
return nil
46+
}
47+
48+
// ConvertFrom converts the Hub version (v1beta1) to this ClientProfile (v1alpha1).
49+
func (dst *ClientProfile) ConvertFrom(srcRaw conversion.Hub) error {
50+
src, ok := srcRaw.(*csiv1beta1.ClientProfile)
51+
if !ok {
52+
return errors.New("convertfrom: failed to cast to v1beta1 ClientProfile")
53+
}
54+
55+
log.Printf("ConvertFrom: Converting ClientProfile from Hub version v1beta1 to Spoke version v1alpha1;"+
56+
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
57+
58+
dst.ObjectMeta = src.ObjectMeta
59+
60+
dst.Spec.CephConnectionRef = src.Spec.CephConnectionRef
61+
dst.Spec.CephFs = (*CephFsConfigSpec)(src.Spec.CephFs)
62+
dst.Spec.Nfs = (*NfsConfigSpec)(src.Spec.Nfs)
63+
dst.Spec.Rbd = (*RbdConfigSpec)(src.Spec.Rbd)
64+
65+
return nil
66+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
20+
21+
// Hub marks this type as a conversion hub.
22+
func (*ClientProfile) Hub() {}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// CephFsConfigSpec defines the desired CephFs configuration
25+
type CephFsConfigSpec struct {
26+
// +kubebuilder:validation:Optional
27+
SubVolumeGroup string `json:"subVolumeGroup,omitempty"`
28+
29+
// +kubebuilder:validation:Optional
30+
KernelMountOptions map[string]string `json:"kernelMountOptions,omitempty"`
31+
32+
// +kubebuilder:validation:Optional
33+
FuseMountOptions map[string]string `json:"fuseMountOptions,omitempty"`
34+
35+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
36+
// +kubebuilder:validation:Optional
37+
RadosNamespace *string `json:"radosNamespace,omitempty"`
38+
}
39+
40+
// RbdConfigSpec defines the desired RBD configuration
41+
type RbdConfigSpec struct {
42+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
43+
// +kubebuilder:validation:Optional
44+
RadosNamespace string `json:"radosNamespace,omitempty"`
45+
}
46+
47+
// NfsConfigSpec cdefines the desired NFS configuration
48+
type NfsConfigSpec struct {
49+
}
50+
51+
// ClientProfileSpec defines the desired state of Ceph CSI
52+
// configuration for volumes and snapshots configured to use
53+
// this profile
54+
type ClientProfileSpec struct {
55+
// +kubebuilder:validation:Required
56+
// +kubebuilder:validation:XValidation:rule=self.name != "",message="'.name' cannot be empty"
57+
CephConnectionRef corev1.LocalObjectReference `json:"cephConnectionRef"`
58+
59+
// +kubebuilder:validation:Optional
60+
CephFs *CephFsConfigSpec `json:"cephFs,omitempty"`
61+
62+
// +kubebuilder:validation:Optional
63+
Rbd *RbdConfigSpec `json:"rbd,omitempty"`
64+
65+
// +kubebuilder:validation:Optional
66+
Nfs *NfsConfigSpec `json:"nfs,omitempty"`
67+
}
68+
69+
// ClientProfileStatus defines the observed state of Ceph CSI
70+
// configuration for volumes and snapshots configured to use
71+
// this profile
72+
type ClientProfileStatus struct {
73+
}
74+
75+
// +kubebuilder:object:root=true
76+
// +kubebuilder:storageversion
77+
// +kubebuilder:conversion:hub
78+
// +kubebuilder:subresource:status
79+
80+
// ClientProfile is the Schema for the clientprofiles API
81+
type ClientProfile struct {
82+
metav1.TypeMeta `json:",inline"`
83+
metav1.ObjectMeta `json:"metadata,omitempty"`
84+
85+
Spec ClientProfileSpec `json:"spec,omitempty"`
86+
Status ClientProfileStatus `json:"status,omitempty"`
87+
}
88+
89+
// +kubebuilder:object:root=true
90+
91+
// ClientProfileList contains a list of ClientProfile
92+
type ClientProfileList struct {
93+
metav1.TypeMeta `json:",inline"`
94+
metav1.ListMeta `json:"metadata,omitempty"`
95+
Items []ClientProfile `json:"items"`
96+
}

api/csi/v1beta1/groupversion_info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
func addKnownTypes(scheme *runtime.Scheme) error {
4242
scheme.AddKnownTypes(GroupVersion,
4343
&CephConnection{}, &CephConnectionList{},
44+
&ClientProfile{}, &ClientProfileList{},
4445
)
4546
metav1.AddToGroupVersion(scheme, GroupVersion)
4647
return nil

api/csi/v1beta1/zz_generated.deepcopy.go

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)