kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/types/v1beta2/federatednotificationreceiver_types.go (about) 1 /* 2 Copyright 2020 KubeSphere Authors 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 v1beta2 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "kubesphere.io/api/notification/v2beta1" 22 "kubesphere.io/api/notification/v2beta2" 23 "kubesphere.io/api/types/v1beta1" 24 "sigs.k8s.io/controller-runtime/pkg/conversion" 25 ) 26 27 const ( 28 ResourcePluralFederatedNotificationReceiver = "federatednotificationreceivers" 29 ResourceSingularFederatedNotificationReceiver = "federatednotificationreceiver" 30 FederatedNotificationReceiverKind = "FederatedNotificationReceiver" 31 ) 32 33 // +genclient 34 // +genclient:nonNamespaced 35 // +kubebuilder:object:root=true 36 // +k8s:openapi-gen=true 37 // +kubebuilder:resource:scope=Cluster 38 // +kubebuilder:subresource:status 39 40 type FederatedNotificationReceiver struct { 41 metav1.TypeMeta `json:",inline"` 42 metav1.ObjectMeta `json:"metadata,omitempty"` 43 Spec FederatedNotificationReceiverSpec `json:"spec"` 44 45 Status *GenericFederatedStatus `json:"status,omitempty"` 46 } 47 48 type FederatedNotificationReceiverSpec struct { 49 Template NotificationReceiverTemplate `json:"template"` 50 Placement GenericPlacementFields `json:"placement"` 51 Overrides []GenericOverrideItem `json:"overrides,omitempty"` 52 } 53 54 type NotificationReceiverTemplate struct { 55 // +kubebuilder:pruning:PreserveUnknownFields 56 metav1.ObjectMeta `json:"metadata,omitempty"` 57 Spec v2beta2.ReceiverSpec `json:"spec,omitempty"` 58 } 59 60 // +kubebuilder:object:root=true 61 // +k8s:openapi-gen=true 62 63 // FederatedNotificationReceiverList contains a list of federatednotificationreceiverlists 64 type FederatedNotificationReceiverList struct { 65 metav1.TypeMeta `json:",inline"` 66 metav1.ListMeta `json:"metadata,omitempty"` 67 Items []FederatedNotificationReceiver `json:"items"` 68 } 69 70 // ConvertTo converts this Config to the Hub version (v1beta1). 71 func (src *FederatedNotificationReceiver) ConvertTo(dstRaw conversion.Hub) error { 72 73 dst := dstRaw.(*v1beta1.FederatedNotificationReceiver) 74 dst.ObjectMeta = src.ObjectMeta 75 76 srcReceiver := v2beta2.Receiver{ 77 Spec: src.Spec.Template.Spec, 78 } 79 dstReceiver := &v2beta1.Receiver{} 80 if err := srcReceiver.ConvertTo(dstReceiver); err != nil { 81 return err 82 } 83 84 dst.Spec = v1beta1.FederatedNotificationReceiverSpec{ 85 Template: v1beta1.NotificationReceiverTemplate{ 86 Spec: dstReceiver.Spec, 87 }, 88 Placement: convertPlacementTo(src.Spec.Placement), 89 Overrides: convertOverridesTo(src.Spec.Overrides), 90 } 91 92 return nil 93 } 94 95 // ConvertFrom converts from the Hub version (v1beta1) to this version. 96 func (dst *FederatedNotificationReceiver) ConvertFrom(srcRaw conversion.Hub) error { 97 98 src := srcRaw.(*v1beta1.FederatedNotificationReceiver) 99 dst.ObjectMeta = src.ObjectMeta 100 101 srcReceiver := v2beta1.Receiver{ 102 Spec: src.Spec.Template.Spec, 103 } 104 dstReceiver := &v2beta2.Receiver{} 105 if err := dstReceiver.ConvertFrom(&srcReceiver); err != nil { 106 return err 107 } 108 109 dst.Spec = FederatedNotificationReceiverSpec{ 110 Template: NotificationReceiverTemplate{ 111 Spec: dstReceiver.Spec, 112 }, 113 Placement: convertPlacementFrom(src.Spec.Placement), 114 Overrides: convertOverridesFrom(src.Spec.Overrides), 115 } 116 117 return nil 118 }