1 // Copyright 2020 Datawire. All rights reserved 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /////////////////////////////////////////////////////////////////////////// 16 // Important: Run "make generate-fast" to regenerate code after modifying 17 // this file. 18 /////////////////////////////////////////////////////////////////////////// 19 20 package v3alpha1 21 22 import ( 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 ) 25 26 // DevPortalContentSpec defines the content origin 27 type DevPortalContentSpec struct { 28 URL string `json:"url,omitempty"` 29 Branch string `json:"branch,omitempty"` 30 Dir string `json:"dir,omitempty"` 31 } 32 33 // DevPortalSelectorSpec is the selector for filtering mappings 34 // that are used in this DevPortal. They can be filtered by things like 35 // namespace, labels, etc... 36 type DevPortalSelectorSpec struct { 37 // MatchNamespaces is a list of namespaces that will be included in 38 // this DevPortal. 39 MatchNamespaces []string `json:"matchNamespaces,omitempty"` 40 41 // MatchLabels specifies the list of labels that must be present 42 // in Mappings for being present in this DevPortal. 43 MatchLabels map[string]string `json:"matchLabels,omitempty"` 44 } 45 46 // DevPortalDocsSpec is a static documentation definition: 47 // instead of using a Selector for finding documentation for services, 48 // users can provide a static list of <service>:<URL> tuples. These services 49 // will be shown in the Dev Portal with the documentation obtained from 50 // this URL. 51 type DevPortalDocsSpec struct { 52 // Service is the service being documented 53 Service string `json:"service,omitempty"` 54 55 // URL is the URL used for obtaining docs 56 URL string `json:"url,omitempty"` 57 58 // Timeout specifies the amount of time devportal will wait 59 // for the downstream service to report an openapi spec back 60 Timeout *MillisecondDuration `json:"timeout_ms,omitempty"` 61 } 62 63 // DevPortalSearchSpec allows configuration over search functionality for the DevPortal 64 type DevPortalSearchSpec struct { 65 Enabled *bool `json:"enabled,omitempty"` 66 67 // Type of search. 68 // "title-only" does a fuzzy search over openapi and page titles 69 // "all-content" will fuzzy search over all openapi and page content. 70 // "title-only" is the default. 71 // warning: using all-content may incur a larger memory footprint 72 // +kubebuilder:validation:Enum={"title-only", "all-content"} 73 Type string `json:"type,omitempty"` 74 } 75 76 // DevPortalSpec defines the desired state of DevPortal 77 type DevPortalSpec struct { 78 AmbassadorID AmbassadorID `json:"ambassador_id,omitempty"` 79 80 // Default must be true when this is the default DevPortal 81 Default *bool `json:"default,omitempty"` 82 83 // Content specifies where the content shown in the DevPortal come from 84 Content *DevPortalContentSpec `json:"content,omitempty"` 85 86 // Docs is a static docs definition 87 Docs []*DevPortalDocsSpec `json:"docs,omitempty"` 88 89 // Selector is used for choosing what is shown in the DevPortal 90 Selector *DevPortalSelectorSpec `json:"selector,omitempty"` 91 92 // Describes how to display "services" in the DevPortal. Default namespace.name 93 // +kubebuilder:validation:Enum={"namespace.name", "name.prefix"} 94 NamingScheme string `json:"naming_scheme,omitempty"` 95 96 Search *DevPortalSearchSpec `json:"search,omitempty"` 97 98 // Configures this DevPortal to use server definitions from the openAPI doc instead of 99 // rewriting them based on the url used for the connection. 100 PreserveServers *bool `json:"preserve_servers,omitempty"` 101 } 102 103 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 104 105 // DevPortal is the Schema for the DevPortals API 106 // 107 // DevPortal resources specify the `what` and `how` is shown in a DevPortal: 108 // 109 // 1. `what` is in a DevPortal can be controlled with 110 // 111 // - a `selector`, that can be used for filtering `Mappings`. 112 // 113 // - a `docs` listing of (services, url) 114 // 115 // 2. `how` is a pointer to some `contents` (a checkout of a Git repository 116 // with go-templates/markdown/css). 117 // 118 // Multiple `DevPortal`s can exist in the cluster, and the Dev Portal server 119 // will show them at different endpoints. A `DevPortal` resource with a special 120 // name, `ambassador`, will be used for configuring the default Dev Portal 121 // (served at `/docs/` by default). 122 // 123 // +kubebuilder:object:root=true 124 // +kubebuilder:resource:path=devportals,scope=Namespaced 125 type DevPortal struct { 126 metav1.TypeMeta `json:""` 127 metav1.ObjectMeta `json:"metadata,omitempty"` 128 129 Spec DevPortalSpec `json:"spec,omitempty"` 130 } 131 132 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 133 134 // DevPortalList contains a list of DevPortals. 135 // 136 // +kubebuilder:object:root=true 137 type DevPortalList struct { 138 metav1.TypeMeta `json:""` 139 metav1.ListMeta `json:"metadata,omitempty"` 140 Items []DevPortal `json:"items"` 141 } 142 143 func init() { 144 SchemeBuilder.Register(&DevPortal{}, &DevPortalList{}) 145 } 146