github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/types/api/v2/application_types.go (about) 1 /* 2 Copyright 2023 alibaba. 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 v2 18 19 import ( 20 "time" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 ) 24 25 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 26 27 // ApplicationSpec defines the desired state of Application 28 type ApplicationSpec struct { 29 //Cmds raw command line which has the highest priority, is mutually exclusive with the AppNames parameter 30 // it could be overwritten from ClusterSpec.CMD and cli flags, and it is not required. 31 Cmds []string `json:"cmds,omitempty"` 32 33 //LaunchApps This field allows user to specify the app names they want to launch. 34 // it could be overwritten from ClusterSpec.APPNames and cli flags. 35 LaunchApps []string `json:"launchApps,omitempty"` 36 37 // Configs Additional configurations for the specified app 38 //it will override the default launch command and delete command, as well as the corresponding app files. 39 Configs []ApplicationConfig `json:"configs,omitempty"` 40 } 41 42 type ApplicationConfig struct { 43 // the AppName 44 Name string `json:"name,omitempty"` 45 46 // Env is a set of key value pair. 47 // it is app level, only this app will be aware of its existence, 48 // it is used to render app files, or as an environment variable for app startup and deletion commands 49 // it takes precedence over ApplicationSpec.Env. 50 Env []string `json:"env,omitempty"` 51 52 //Files indicates that how to modify the specific app files. 53 Files []AppFile `json:"files,omitempty"` 54 55 // app Launch customization 56 Launch *Launch `json:"launch,omitempty"` 57 58 // app Delete customization 59 //Delete *Delete `json:"delete,omitempty"` 60 } 61 62 type Strategy string 63 64 const ( 65 OverWriteStrategy Strategy = "overwrite" 66 MergeStrategy Strategy = "merge" 67 ) 68 69 type AppFile struct { 70 // Path represents the path to write the Values, required. 71 Path string `json:"path,omitempty"` 72 73 //PreProcessor pre mutate the whole Values. 74 //PreProcessor string `json:"preProcessor,omitempty"` 75 76 // Enumeration value is "merge", "overwrite", "render". default value is "overwrite". 77 // OverWriteStrategy : this will overwrite the FilePath with the Data. 78 // MergeStrategy: this will merge the FilePath with the Data, and only yaml files format are supported 79 Strategy Strategy `json:"strategy,omitempty"` 80 81 // Data real app launch need. 82 // it could be raw content, yaml data, yaml section data, key-value pairs, and so on. 83 Data string `json:"data,omitempty"` 84 } 85 86 type Delete struct { 87 // raw cmds support 88 Cmds []string `json:"cmds,omitempty"` 89 } 90 91 type Launch struct { 92 // Cmds raw cmds support, not required, exclusive with app type. 93 Cmds []string `json:"cmds,omitempty"` 94 95 // Helm represents the helm app type 96 //Helm *Helm `json:"helm,omitempty"` 97 98 // Shell represents the shell app type 99 //Shell *Shell `json:"shell,omitempty"` 100 101 // Kube represents the kube app type, 102 // The reason why this is an arrays that it can support operations on resources in different namespaces. 103 //Kube []Kubectl `json:"kube,omitempty"` 104 } 105 106 type Helm struct { 107 // Name will omit the chart values NAME parameter. 108 Name string `json:"Name,omitempty"` 109 110 //Chart 111 //There are five different ways you can express the chart you want to install: 112 //1. By chart reference: helm install mymaria example/mariadb 113 //2. By path to a packaged chart: helm install mynginx ./nginx-1.2.3.tgz 114 //3. By path to an unpacked chart directory: helm install mynginx ./nginx 115 //4. By absolute URL: helm install mynginx https://example.com/charts/nginx-1.2.3.tgz 116 //5. By chart reference and repo url: helm install --repo https://example.com/charts/ mynginx nginx 117 Chart string `json:"chart,omitempty"` 118 119 //Namespace specifies that where the chart package is installed in 120 //it override String to fully override common.names.namespace 121 Namespace string 122 123 //CreateNamespace: create the release namespace if not present 124 CreateNamespace bool `json:"createNamespace,omitempty"` 125 126 //DisableHooks: prevent hooks from running during install 127 DisableHooks bool `json:"disableHooks,omitempty"` 128 129 //SkipCRDs: if set, no CRDs will be installed. By default, CRDs are installed if not already present 130 SkipCRDs bool `json:"skipCRDs,omitempty"` 131 132 //Timeout to wait for any individual Kubernetes operation (like Jobs for hooks) 133 Timeout time.Duration `json:"timeout,omitempty"` 134 135 // Wait: if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet 136 // are in a ready state before marking the release as successful. It will wait for as long as Timeout 137 Wait bool `json:"wait,omitempty"` 138 139 // ValueFiles specify values in a YAML file or a URL, it can specify multiple. 140 ValueFiles []string `json:"valueFiles,omitempty"` 141 142 //set Values on the command line ,it can specify multiple or separate values with commas: key1=val1,key2=val2. 143 Values []string `json:"values,omitempty"` 144 } 145 146 type Shell struct { 147 // the environment variables to execute the shell file 148 Envs []string `json:"envs,omitempty"` 149 150 //FilePath represents the shell file path 151 FilePaths []string `json:"filePaths,omitempty"` 152 } 153 154 type Kubectl struct { 155 //FileNames represents the resources applied from 156 FileNames []string `json:"fileNames,omitempty"` 157 158 //Directory represents the resources applied from 159 Directory string `json:"directory,omitempty"` 160 161 // Namespace apply resources to specific namespace. 162 Namespace string `json:"namespace,omitempty"` 163 } 164 165 // ApplicationStatus defines the observed state of Application 166 type ApplicationStatus struct { 167 // INSERT ADDITIONAL STATUS FIELD - define observed state of Application 168 // Important: Run "make" to regenerate code after modifying this file 169 } 170 171 // +kubebuilder:object:root=true 172 // +kubebuilder:subresource:status 173 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 174 175 // Application is the Schema for the application API 176 type Application struct { 177 metav1.TypeMeta `json:",inline"` 178 metav1.ObjectMeta `json:"metadata,omitempty"` 179 180 Spec ApplicationSpec `json:"spec,omitempty"` 181 Status ApplicationStatus `json:"status,omitempty"` 182 } 183 184 // +kubebuilder:object:root=true 185 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 186 187 // ApplicationList contains a list of Application 188 type ApplicationList struct { 189 metav1.TypeMeta `json:",inline"` 190 metav1.ListMeta `json:"metadata,omitempty"` 191 Items []Application `json:"items"` 192 } 193 194 func init() { 195 SchemeBuilder.Register(&Application{}, &ApplicationList{}) 196 }