|
| 1 | +/* |
| 2 | +Copyright 2024 Kong, Inc. |
| 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 | + konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +// KongDataplaneCertificate is the schema for KongDataplaneCertificate API which defines a KongDataplaneCertificate entity. |
| 25 | +// |
| 26 | +// +genclient |
| 27 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 28 | +// +kubebuilder:object:root=true |
| 29 | +// +kubebuilder:resource:scope=Namespaced |
| 30 | +// +kubebuilder:storageversion |
| 31 | +// +kubebuilder:subresource:status |
| 32 | +// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status` |
| 33 | +// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set" |
| 34 | +// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : (!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed" |
| 35 | +// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.cert == self.spec.cert", message="spec.cert is immutable when an entity is already Programmed" |
| 36 | +// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet" |
| 37 | +type KongDataplaneCertificate struct { |
| 38 | + metav1.TypeMeta `json:",inline"` |
| 39 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 40 | + |
| 41 | + Spec KongDataplaneCertificateSpec `json:"spec"` |
| 42 | + |
| 43 | + // +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}} |
| 44 | + Status KongDataplaneCertificateStatus `json:"status,omitempty"` |
| 45 | +} |
| 46 | + |
| 47 | +// KongDataplaneCertificateSpec defines the spec for a KongDataplaneCertificate. |
| 48 | +type KongDataplaneCertificateSpec struct { |
| 49 | + // ControlPlaneRef is a reference to a Konnect ControlPlane this KongDataplaneCertificate is associated with. |
| 50 | + // +optional |
| 51 | + ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"` |
| 52 | + |
| 53 | + // KongDataplaneCertificateAPISpec are the attributes of the KongDataplaneCertificate itself. |
| 54 | + KongDataplaneCertificateAPISpec `json:",inline"` |
| 55 | +} |
| 56 | + |
| 57 | +// KongDataplaneCertificateAPISpec defines the attributes of a Kong DP certificate. |
| 58 | +type KongDataplaneCertificateAPISpec struct { |
| 59 | + // Cert is the certificate in PEM format. Once the certificate gets programmed this field becomes immutable. |
| 60 | + // +kubebuilder:validation:MinLength=1 |
| 61 | + Cert string `json:"cert"` |
| 62 | +} |
| 63 | + |
| 64 | +// KongDataplaneCertificateStatus defines the status for a KongDataplaneCertificate. |
| 65 | +type KongDataplaneCertificateStatus struct { |
| 66 | + // Konnect contains the Konnect entity status. |
| 67 | + // +optional |
| 68 | + Konnect *konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"` |
| 69 | + |
| 70 | + // Conditions describe the status of the Konnect entity. |
| 71 | + // +listType=map |
| 72 | + // +listMapKey=type |
| 73 | + // +kubebuilder:validation:MinItems=1 |
| 74 | + // +kubebuilder:validation:MaxItems=8 |
| 75 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 76 | +} |
| 77 | + |
| 78 | +// +kubebuilder:object:root=true |
| 79 | + |
| 80 | +// KongDataplaneCertificateList contains a list of Kong Keys. |
| 81 | +type KongDataplaneCertificateList struct { |
| 82 | + metav1.TypeMeta `json:",inline"` |
| 83 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 84 | + Items []KongDataplaneCertificate `json:"items"` |
| 85 | +} |
| 86 | + |
| 87 | +func init() { |
| 88 | + SchemeBuilder.Register(&KongDataplaneCertificate{}, &KongDataplaneCertificateList{}) |
| 89 | +} |
0 commit comments