halkyon.io/api@v1.0.0-rc.6/capability/v1beta1/types.go (about) 1 package v1beta1 2 3 import ( 4 "halkyon.io/api/v1beta1" 5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 6 "k8s.io/apimachinery/pkg/runtime/schema" 7 "strings" 8 ) 9 10 const Kind string = "Capability" 11 12 // CapabilitySpec defines the desired state of Capability 13 // +k8s:openapi-gen=true 14 type CapabilitySpec struct { 15 // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster 16 // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file 17 // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html 18 19 /* 20 category: <database>, <logging>,<metrics> 21 type: postgres (if category is database) 22 version: <version of the DB or prometheus or ...> to be installed 23 secretName: <secret_name_to_be_created> // Is used by kubedb postgres and is optional as some capability provider does not need to create a secret 24 parameters: 25 // LIST OF PARAMETERS WILL BE MAPPED TO EACH CATEGORY ! 26 - name: DB_USER // WILL BE USED TO CREATE THE DB SECRET 27 value: "admin" 28 - name: DB_PASSWORD // WILL BE USED TO CREATE THE DB SECRET 29 value: "admin" 30 */ 31 Category CapabilityCategory `json:"category"` 32 Type CapabilityType `json:"type"` 33 Version string `json:"version"` 34 Parameters []v1beta1.NameValuePair `json:"parameters,omitempty"` 35 } 36 37 func (in CapabilitySpec) Matches(requested CapabilitySpec) bool { 38 // first check that category and type match 39 if requested.Category.Equals(in.Category) && requested.Type.Equals(in.Type) { 40 // if we're asking for a specific version then we need to provide a capability with that version 41 // todo: implement range matching on version? 42 return len(requested.Version) == 0 || requested.Version == in.Version 43 } 44 return false 45 } 46 47 type CapabilityCategory string 48 49 func (cc CapabilityCategory) String() string { 50 return string(cc) 51 } 52 53 func (cc CapabilityCategory) Equals(other CapabilityCategory) bool { 54 return strings.ToLower(cc.String()) == strings.ToLower(other.String()) 55 } 56 57 type CapabilityType string 58 59 func (ct CapabilityType) String() string { 60 return string(ct) 61 } 62 63 func (ct CapabilityType) Equals(other CapabilityType) bool { 64 return strings.ToLower(ct.String()) == strings.ToLower(other.String()) 65 } 66 67 const ( 68 DatabaseCategory CapabilityCategory = "Database" 69 PostgresType CapabilityType = "Postgres" 70 71 MetricCategory CapabilityCategory = "Metric" 72 LoggingCategory CapabilityCategory = "Logging" 73 ) 74 75 // CapabilityStatus defines the observed state of Capability 76 // +k8s:openapi-gen=true 77 type CapabilityStatus struct { 78 // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 79 // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file 80 // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html 81 v1beta1.Status 82 } 83 84 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 85 86 // Capability is the Schema for the Services API 87 // +k8s:openapi-gen=true 88 // +genclient 89 type Capability struct { 90 metav1.TypeMeta `json:",inline"` 91 metav1.ObjectMeta `json:"metadata,omitempty"` 92 93 Spec CapabilitySpec `json:"spec,omitempty"` 94 Status CapabilityStatus `json:"status,omitempty"` 95 } 96 97 func (in *Capability) GetGroupVersionKind() schema.GroupVersionKind { 98 return SchemeGroupVersion.WithKind(Kind) 99 } 100 101 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 102 103 // CapabilityList contains a list of Capability 104 type CapabilityList struct { 105 metav1.TypeMeta `json:",inline"` 106 metav1.ListMeta `json:"metadata,omitempty"` 107 Items []Capability `json:"items"` 108 }