Skip to content

Commit 583761b

Browse files
api: add v1beta1 conversion and types for operatorconfig
Signed-off-by: Niraj Yadav <niryadav@redhat.com>
1 parent 148b0a0 commit 583761b

20 files changed

+7698
-3
lines changed

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,17 @@ resources:
104104
spoke:
105105
- v1alpha1
106106
webhookVersion: v1
107+
- api:
108+
crdVersion: v1
109+
namespaced: true
110+
domain: ceph.io
111+
group: csi
112+
kind: OperatorConfig
113+
path: github.com/ceph/ceph-csi-operator/api/csi/v1beta1
114+
version: v1beta1
115+
webhooks:
116+
conversion: true
117+
spoke:
118+
- v1alpha1
119+
webhookVersion: v1
107120
version: "3"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 OperatorConfig (v1alpha1) to the Hub version (v1beta1).
29+
func (src *OperatorConfig) ConvertTo(dstRaw conversion.Hub) error {
30+
dst, ok := dstRaw.(*csiv1beta1.OperatorConfig)
31+
if !ok {
32+
return errors.New("convertto: failed to cast to v1beta1 OperatorConfig")
33+
}
34+
35+
log.Printf("ConvertTo: Converting OperatorConfig 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+
if src.Spec.DriverSpecDefaults != nil {
41+
cSpec := ConvertAlphaDriverToBeta(*src.Spec.DriverSpecDefaults)
42+
dst.Spec.DriverSpecDefaults = &cSpec
43+
}
44+
45+
return nil
46+
}
47+
48+
// ConvertFrom converts the Hub version (v1beta1) to this OperatorConfig (v1alpha1).
49+
func (dst *OperatorConfig) ConvertFrom(srcRaw conversion.Hub) error {
50+
src, ok := srcRaw.(*csiv1beta1.OperatorConfig)
51+
if !ok {
52+
return errors.New("convertto: failed to cast to v1beta1 OperatorConfig")
53+
}
54+
55+
log.Printf("ConvertFrom: Converting OperatorConfig 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+
if src.Spec.DriverSpecDefaults != nil {
61+
cSpec := ConvertBetaDriverToAlpha(*src.Spec.DriverSpecDefaults)
62+
dst.Spec.DriverSpecDefaults = &cSpec
63+
}
64+
return nil
65+
}

api/csi/v1beta1/groupversion_info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4444
&ClientProfile{}, &ClientProfileList{},
4545
&ClientProfileMapping{}, &ClientProfileMappingList{},
4646
&Driver{}, &DriverList{},
47+
&OperatorConfig{}, &OperatorConfigList{},
4748
)
4849
metav1.AddToGroupVersion(scheme, GroupVersion)
4950
return nil
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 (*OperatorConfig) Hub() {}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// OperatorLogSpec provide log related settings for the operator
24+
type OperatorLogSpec struct {
25+
// Operator's log level
26+
// +kubebuilder:validation:Optional
27+
// +kubebuilder:validation:Minimum=0
28+
// +kubebuilder:validation:Maximum=3
29+
Verbosity int `json:"verbosity,omitempty"`
30+
}
31+
32+
// OperatorConfigSpec defines the desired state of OperatorConfig
33+
type OperatorConfigSpec struct {
34+
// +kubebuilder:validation:Optional
35+
Log *OperatorLogSpec `json:"log,omitempty"`
36+
37+
// Allow overwrite of hardcoded defaults for any driver managed by this operator
38+
// +kubebuilder:validation:Optional
39+
DriverSpecDefaults *DriverSpec `json:"driverSpecDefaults,omitempty"`
40+
}
41+
42+
// OperatorConfigStatus defines the observed state of OperatorConfig
43+
type OperatorConfigStatus struct {
44+
}
45+
46+
// +kubebuilder:object:root=true
47+
// +kubebuilder:storageversion
48+
// +kubebuilder:conversion:hub
49+
// +kubebuilder:subresource:status
50+
51+
// OperatorConfig is the Schema for the operatorconfigs API
52+
type OperatorConfig struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ObjectMeta `json:"metadata,omitempty"`
55+
56+
Spec OperatorConfigSpec `json:"spec,omitempty"`
57+
Status OperatorConfigStatus `json:"status,omitempty"`
58+
}
59+
60+
// +kubebuilder:object:root=true
61+
62+
// OperatorConfigList contains a list of OperatorConfig
63+
type OperatorConfigList struct {
64+
metav1.TypeMeta `json:",inline"`
65+
metav1.ListMeta `json:"metadata,omitempty"`
66+
Items []OperatorConfig `json:"items"`
67+
}

api/csi/v1beta1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ func main() {
274274
os.Exit(1)
275275
}
276276
}
277+
// nolint:goconst
278+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
279+
if err = webhookcsiv1beta1.SetupOperatorConfigWebhookWithManager(mgr); err != nil {
280+
setupLog.Error(err, "unable to create webhook", "webhook", "OperatorConfig")
281+
os.Exit(1)
282+
}
283+
}
277284
//+kubebuilder:scaffold:builder
278285

279286
if metricsCertWatcher != nil {

0 commit comments

Comments
 (0)