kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/devops/v1alpha1/s2ibuilder_types.go (about) 1 /* 2 Copyright 2020 The 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 v1alpha1 18 19 import ( 20 "fmt" 21 22 corev1 "k8s.io/api/core/v1" 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 ) 25 26 // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 29 type RunState string 30 31 const ( 32 ResourceKindS2iBuilder = "S2iBuilder" 33 ResourceSingularS2iBuilder = "s2ibuilder" 34 ResourcePluralS2iBuilder = "s2ibuilders" 35 ) 36 37 const ( 38 NotRunning RunState = "Not Running Yet" 39 Running RunState = "Running" 40 Successful RunState = "Successful" 41 Failed RunState = "Failed" 42 Unknown RunState = "Unknown" 43 ) 44 const ( 45 AutoScaleAnnotations = "devops.kubesphere.io/autoscale" 46 S2iRunLabel = "devops.kubesphere.io/s2ir" 47 S2irCompletedScaleAnnotations = "devops.kubesphere.io/completedscale" 48 WorkLoadCompletedInitAnnotations = "devops.kubesphere.io/inithasbeencomplted" 49 S2iRunDoNotAutoScaleAnnotations = "devops.kubesphere.io/donotautoscale" 50 DescriptionAnnotations = "desc" 51 ) 52 const ( 53 KindDeployment = "Deployment" 54 KindStatefulSet = "StatefulSet" 55 ) 56 57 // EnvironmentSpec specifies a single environment variable. 58 type EnvironmentSpec struct { 59 Name string `json:"name"` 60 Value string `json:"value"` 61 } 62 63 // ProxyConfig holds proxy configuration. 64 type ProxyConfig struct { 65 HTTPProxy string `json:"httpProxy,omitempty"` 66 HTTPSProxy string `json:"httpsProxy,omitempty"` 67 } 68 69 // CGroupLimits holds limits used to constrain container resources. 70 type CGroupLimits struct { 71 MemoryLimitBytes int64 `json:"memoryLimitBytes"` 72 CPUShares int64 `json:"cpuShares"` 73 CPUPeriod int64 `json:"cpuPeriod"` 74 CPUQuota int64 `json:"cpuQuota"` 75 MemorySwap int64 `json:"memorySwap"` 76 Parent string `json:"parent"` 77 } 78 79 // VolumeSpec represents a single volume mount point. 80 type VolumeSpec struct { 81 // Source is a reference to the volume source. 82 Source string `json:"source,omitempty"` 83 // Destination is the path to mount the volume to - absolute or relative. 84 Destination string `json:"destination,omitempty"` 85 // Keep indicates if the mounted data should be kept in the final image. 86 Keep bool `json:"keep,omitempty"` 87 } 88 89 // DockerConfig contains the configuration for a Docker connection. 90 type DockerConfig struct { 91 // Endpoint is the docker network endpoint or socket 92 Endpoint string `json:"endPoint"` 93 94 // CertFile is the certificate file path for a TLS connection 95 CertFile string `json:"certFile"` 96 97 // KeyFile is the key file path for a TLS connection 98 KeyFile string `json:"keyFile"` 99 100 // CAFile is the certificate authority file path for a TLS connection 101 CAFile string `json:"caFile"` 102 103 // UseTLS indicates if TLS must be used 104 UseTLS bool `json:"useTLS"` 105 106 // TLSVerify indicates if TLS peer must be verified 107 TLSVerify bool `json:"tlsVerify"` 108 } 109 110 // AuthConfig is our abstraction of the Registry authorization information for whatever 111 // docker client we happen to be based on 112 type AuthConfig struct { 113 Username string `json:"username,omitempty"` 114 Password string `json:"password,omitempty"` 115 Email string `json:"email,omitempty"` 116 ServerAddress string `json:"serverAddress,omitempty"` 117 SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` 118 } 119 120 // ContainerConfig is the abstraction of the docker client provider (formerly go-dockerclient, now either 121 // engine-api or kube docker client) container.Config type that is leveraged by s2i or origin 122 type ContainerConfig struct { 123 Labels map[string]string 124 Env []string 125 } 126 127 type PullPolicy string 128 129 const ( 130 // PullAlways means that we always attempt to pull the latest image. 131 PullAlways PullPolicy = "always" 132 133 // PullNever means that we never pull an image, but only use a local image. 134 PullNever PullPolicy = "never" 135 136 // PullIfNotPresent means that we pull if the image isn't present on disk. 137 PullIfNotPresent PullPolicy = "if-not-present" 138 139 // DefaultBuilderPullPolicy specifies the default pull policy to use 140 DefaultBuilderPullPolicy = PullIfNotPresent 141 142 // DefaultRuntimeImagePullPolicy specifies the default pull policy to use. 143 DefaultRuntimeImagePullPolicy = PullIfNotPresent 144 145 // DefaultPreviousImagePullPolicy specifies policy for pulling the previously 146 // build Docker image when doing incremental build 147 DefaultPreviousImagePullPolicy = PullIfNotPresent 148 ) 149 150 // DockerNetworkMode specifies the network mode setting for the docker container 151 type DockerNetworkMode string 152 153 const ( 154 // DockerNetworkModeHost places the container in the default (host) network namespace. 155 DockerNetworkModeHost DockerNetworkMode = "host" 156 // DockerNetworkModeBridge instructs docker to create a network namespace for this container connected to the docker0 bridge via a veth-pair. 157 DockerNetworkModeBridge DockerNetworkMode = "bridge" 158 // DockerNetworkModeContainerPrefix is the string prefix used by NewDockerNetworkModeContainer. 159 DockerNetworkModeContainerPrefix string = "container:" 160 // DockerNetworkModeNetworkNamespacePrefix is the string prefix used when sharing a namespace from a CRI-O container. 161 DockerNetworkModeNetworkNamespacePrefix string = "netns:" 162 ) 163 164 type TriggerSource string 165 166 const ( 167 Default TriggerSource = "Manual" 168 Github TriggerSource = "Github" 169 Gitlab TriggerSource = "Gitlab" 170 SVN TriggerSource = "SVN" 171 Others TriggerSource = "Others" 172 ) 173 174 // NewDockerNetworkModeContainer creates a DockerNetworkMode value which instructs docker to place the container in the network namespace of an existing container. 175 // It can be used, for instance, to place the s2i container in the network namespace of the infrastructure container of a k8s pod. 176 func NewDockerNetworkModeContainer(id string) DockerNetworkMode { 177 return DockerNetworkMode(DockerNetworkModeContainerPrefix + id) 178 } 179 180 // String implements the String() function of pflags.Value so this can be used as 181 // command line parameter. 182 // This method is really used just to show the default value when printing help. 183 // It will not default the configuration. 184 func (p *PullPolicy) String() string { 185 if len(string(*p)) == 0 { 186 return string(DefaultBuilderPullPolicy) 187 } 188 return string(*p) 189 } 190 191 // Type implements the Type() function of pflags.Value interface 192 func (p *PullPolicy) Type() string { 193 return "string" 194 } 195 196 // Set implements the Set() function of pflags.Value interface 197 // The valid options are "always", "never" or "if-not-present" 198 func (p *PullPolicy) Set(v string) error { 199 switch v { 200 case "always": 201 *p = PullAlways 202 case "never": 203 *p = PullNever 204 case "if-not-present": 205 *p = PullIfNotPresent 206 default: 207 return fmt.Errorf("invalid value %q, valid values are: always, never or if-not-present", v) 208 } 209 return nil 210 } 211 212 type S2iConfig struct { 213 // DisplayName is a result image display-name label. This defaults to the 214 // output image name. 215 DisplayName string `json:"displayName,omitempty"` 216 217 // Description is a result image description label. The default is no 218 // description. 219 Description string `json:"description,omitempty"` 220 221 // BuilderImage describes which image is used for building the result images. 222 BuilderImage string `json:"builderImage,omitempty"` 223 224 // BuilderImageVersion provides optional version information about the builder image. 225 BuilderImageVersion string `json:"builderImageVersion,omitempty"` 226 227 // BuilderBaseImageVersion provides optional version information about the builder base image. 228 BuilderBaseImageVersion string `json:"builderBaseImageVersion,omitempty"` 229 230 // RuntimeImage specifies the image that will be a base for resulting image 231 // and will be used for running an application. By default, BuilderImage is 232 // used for building and running, but the latter may be overridden. 233 RuntimeImage string `json:"runtimeImage,omitempty"` 234 235 //OutputImageName is a result image name without tag, default is latest. tag will append to ImageName in the end 236 OutputImageName string `json:"outputImageName,omitempty"` 237 // RuntimeImagePullPolicy specifies when to pull a runtime image. 238 RuntimeImagePullPolicy PullPolicy `json:"runtimeImagePullPolicy,omitempty"` 239 240 // RuntimeAuthentication holds the authentication information for pulling the 241 // runtime Docker images from private repositories. 242 RuntimeAuthentication *AuthConfig `json:"runtimeAuthentication,omitempty"` 243 244 // RuntimeArtifacts specifies a list of source/destination pairs that will 245 // be copied from builder to a runtime image. Source can be a file or 246 // directory. Destination must be a directory. Regardless whether it 247 // is an absolute or relative path, it will be placed into image's WORKDIR. 248 // Destination also can be empty or equals to ".", in this case it just 249 // refers to a root of WORKDIR. 250 // In case it's empty, S2I will try to get this list from 251 // io.openshift.s2i.assemble-input-files label on a RuntimeImage. 252 RuntimeArtifacts []VolumeSpec `json:"runtimeArtifacts,omitempty"` 253 254 // DockerConfig describes how to access host docker daemon. 255 DockerConfig *DockerConfig `json:"dockerConfig,omitempty"` 256 257 // PullAuthentication holds the authentication information for pulling the 258 // Docker images from private repositories 259 PullAuthentication *AuthConfig `json:"pullAuthentication,omitempty"` 260 261 // PullAuthentication holds the authentication information for pulling the 262 // Docker images from private repositories 263 PushAuthentication *AuthConfig `json:"pushAuthentication,omitempty"` 264 265 // IncrementalAuthentication holds the authentication information for pulling the 266 // previous image from private repositories 267 IncrementalAuthentication *AuthConfig `json:"incrementalAuthentication,omitempty"` 268 269 // DockerNetworkMode is used to set the docker network setting to --net=container:<id> 270 // when the builder is invoked from a container. 271 DockerNetworkMode DockerNetworkMode `json:"dockerNetworkMode,omitempty"` 272 273 // PreserveWorkingDir describes if working directory should be left after processing. 274 PreserveWorkingDir bool `json:"preserveWorkingDir,omitempty"` 275 276 //ImageName Contains the registry address and reponame, tag should set by field tag alone 277 ImageName string `json:"imageName"` 278 // Tag is a result image tag name. 279 Tag string `json:"tag,omitempty"` 280 281 // BuilderPullPolicy specifies when to pull the builder image 282 BuilderPullPolicy PullPolicy `json:"builderPullPolicy,omitempty"` 283 284 // PreviousImagePullPolicy specifies when to pull the previously build image 285 // when doing incremental build 286 PreviousImagePullPolicy PullPolicy `json:"previousImagePullPolicy,omitempty"` 287 288 // Incremental describes whether to try to perform incremental build. 289 Incremental bool `json:"incremental,omitempty"` 290 291 // IncrementalFromTag sets an alternative image tag to look for existing 292 // artifacts. Tag is used by default if this is not set. 293 IncrementalFromTag string `json:"incrementalFromTag,omitempty"` 294 295 // RemovePreviousImage describes if previous image should be removed after successful build. 296 // This applies only to incremental builds. 297 RemovePreviousImage bool `json:"removePreviousImage,omitempty"` 298 299 // Environment is a map of environment variables to be passed to the image. 300 Environment []EnvironmentSpec `json:"environment,omitempty"` 301 302 // LabelNamespace provides the namespace under which the labels will be generated. 303 LabelNamespace string `json:"labelNamespace,omitempty"` 304 305 // CallbackURL is a URL which is called upon successful build to inform about that fact. 306 CallbackURL string `json:"callbackUrl,omitempty"` 307 308 // ScriptsURL is a URL describing where to fetch the S2I scripts from during build process. 309 // This url can be a reference within the builder image if the scheme is specified as image:// 310 ScriptsURL string `json:"scriptsUrl,omitempty"` 311 312 // Destination specifies a location where the untar operation will place its artifacts. 313 Destination string `json:"destination,omitempty"` 314 315 // WorkingDir describes temporary directory used for downloading sources, scripts and tar operations. 316 WorkingDir string `json:"workingDir,omitempty"` 317 318 // WorkingSourceDir describes the subdirectory off of WorkingDir set up during the repo download 319 // that is later used as the root for ignore processing 320 WorkingSourceDir string `json:"workingSourceDir,omitempty"` 321 322 // LayeredBuild describes if this is build which layered scripts and sources on top of BuilderImage. 323 LayeredBuild bool `json:"layeredBuild,omitempty"` 324 325 // Specify a relative directory inside the application repository that should 326 // be used as a root directory for the application. 327 ContextDir string `json:"contextDir,omitempty"` 328 329 // AssembleUser specifies the user to run the assemble script in container 330 AssembleUser string `json:"assembleUser,omitempty"` 331 332 // RunImage will trigger a "docker run ..." invocation of the produced image so the user 333 // can see if it operates as he would expect 334 RunImage bool `json:"runImage,omitempty"` 335 336 // Usage allows for properly shortcircuiting s2i logic when `s2i usage` is invoked 337 Usage bool `json:"usage,omitempty"` 338 339 // Injections specifies a list source/destination folders that are injected to 340 // the container that runs assemble. 341 // All files we inject will be truncated after the assemble script finishes. 342 Injections []VolumeSpec `json:"injections,omitempty"` 343 344 // CGroupLimits describes the cgroups limits that will be applied to any containers 345 // run by s2i. 346 CGroupLimits *CGroupLimits `json:"cgroupLimits,omitempty"` 347 348 // DropCapabilities contains a list of capabilities to drop when executing containers 349 DropCapabilities []string `json:"dropCapabilities,omitempty"` 350 351 // ScriptDownloadProxyConfig optionally specifies the http and https proxy 352 // to use when downloading scripts 353 ScriptDownloadProxyConfig *ProxyConfig `json:"scriptDownloadProxyConfig,omitempty"` 354 355 // ExcludeRegExp contains a string representation of the regular expression desired for 356 // deciding which files to exclude from the tar stream 357 ExcludeRegExp string `json:"excludeRegExp,omitempty"` 358 359 // BlockOnBuild prevents s2i from performing a docker build operation 360 // if one is necessary to execute ONBUILD commands, or to layer source code into 361 // the container for images that don't have a tar binary available, if the 362 // image contains ONBUILD commands that would be executed. 363 BlockOnBuild bool `json:"blockOnBuild,omitempty"` 364 365 // HasOnBuild will be set to true if the builder image contains ONBUILD instructions 366 HasOnBuild bool `json:"hasOnBuild,omitempty"` 367 368 // BuildVolumes specifies a list of volumes to mount to container running the 369 // build. 370 BuildVolumes []string `json:"buildVolumes,omitempty"` 371 372 // Labels specify labels and their values to be applied to the resulting image. Label keys 373 // must have non-zero length. The labels defined here override generated labels in case 374 // they have the same name. 375 Labels map[string]string `json:"labels,omitempty"` 376 377 // SecurityOpt are passed as options to the docker containers launched by s2i. 378 SecurityOpt []string `json:"securityOpt,omitempty"` 379 380 // KeepSymlinks indicates to copy symlinks as symlinks. Default behavior is to follow 381 // symlinks and copy files by content. 382 KeepSymlinks bool `json:"keepSymlinks,omitempty"` 383 384 // AsDockerfile indicates the path where the Dockerfile should be written instead of building 385 // a new image. 386 AsDockerfile string `json:"asDockerfile,omitempty"` 387 388 // ImageWorkDir is the default working directory for the builder image. 389 ImageWorkDir string `json:"imageWorkDir,omitempty"` 390 391 // ImageScriptsURL is the default location to find the assemble/run scripts for a builder image. 392 // This url can be a reference within the builder image if the scheme is specified as image:// 393 ImageScriptsURL string `json:"imageScriptsUrl,omitempty"` 394 395 // AddHost Add a line to /etc/hosts for test purpose or private use in LAN. Its format is host:IP,multiple hosts can be added by using multiple --add-host 396 AddHost []string `json:"addHost,omitempty"` 397 398 // Export Push the result image to specify image registry in tag 399 Export bool `json:"export,omitempty"` 400 401 // SourceURL is url of the codes such as https://github.com/a/b.git 402 SourceURL string `json:"sourceUrl"` 403 404 // IsBinaryURL explain the type of SourceURL. 405 // If it is IsBinaryURL, it will download the file directly without using git. 406 IsBinaryURL bool `json:"isBinaryURL,omitempty"` 407 408 // GitSecretRef is the BasicAuth Secret of Git Clone 409 GitSecretRef *corev1.LocalObjectReference `json:"gitSecretRef,omitempty"` 410 411 // The RevisionId is a branch name or a SHA-1 hash of every important thing about the commit 412 RevisionId string `json:"revisionId,omitempty"` 413 414 // The name of taint. 415 TaintKey string `json:"taintKey,omitempty"` 416 417 // The key of Node Affinity. 418 NodeAffinityKey string `json:"nodeAffinityKey,omitempty"` 419 420 // The values of Node Affinity. 421 NodeAffinityValues []string `json:"nodeAffinityValues,omitempty"` 422 423 // Whether output build result to status. 424 OutputBuildResult bool `json:"outputBuildResult,omitempty"` 425 426 // Regular expressions, ignoring names that do not match the provided regular expression 427 BranchExpression string `json:"branchExpression,omitempty"` 428 429 // SecretCode 430 SecretCode string `json:"secretCode,omitempty"` 431 } 432 433 type UserDefineTemplate struct { 434 //Name specify a template to use, so many fields in Config can left empty 435 Name string `json:"name,omitempty"` 436 //Parameters must use with `template`, fill some parameters which template will use 437 Parameters []Parameter `json:"parameters,omitempty"` 438 //BaseImage specify which version of this template to use 439 BuilderImage string `json:"builderImage,omitempty"` 440 } 441 442 // S2iBuilderSpec defines the desired state of S2iBuilder 443 type S2iBuilderSpec struct { 444 // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster 445 // Important: Run "make" to regenerate code after modifying this file 446 Config *S2iConfig `json:"config,omitempty"` 447 //FromTemplate define some inputs from user 448 FromTemplate *UserDefineTemplate `json:"fromTemplate,omitempty"` 449 } 450 451 // S2iBuilderStatus defines the observed state of S2iBuilder 452 type S2iBuilderStatus struct { 453 //RunCount represent the sum of s2irun of this builder 454 RunCount int `json:"runCount"` 455 //LastRunState return the state of the newest run of this builder 456 LastRunState RunState `json:"lastRunState,omitempty"` 457 //LastRunState return the name of the newest run of this builder 458 LastRunName *string `json:"lastRunName,omitempty"` 459 //LastRunStartTime return the startTime of the newest run of this builder 460 LastRunStartTime *metav1.Time `json:"lastRunStartTime,omitempty"` 461 } 462 463 // +genclient 464 // +kubebuilder:object:root=true 465 466 // S2iBuilder is the Schema for the s2ibuilders API 467 // +k8s:openapi-gen=true 468 // +kubebuilder:subresource:status 469 // +kubebuilder:printcolumn:name="RunCount",type="integer",JSONPath=".status.runCount" 470 // +kubebuilder:printcolumn:name="LastRunState",type="string",JSONPath=".status.lastRunState" 471 // +kubebuilder:printcolumn:name="LastRunName",type="string",JSONPath=".status.lastRunName" 472 // +kubebuilder:printcolumn:name="LastRunStartTime",type="date",JSONPath=".status.lastRunStartTime" 473 // +kubebuilder:resource:shortName=s2ib 474 type S2iBuilder struct { 475 metav1.TypeMeta `json:",inline"` 476 metav1.ObjectMeta `json:"metadata,omitempty"` 477 478 Spec S2iBuilderSpec `json:"spec,omitempty"` 479 Status S2iBuilderStatus `json:"status,omitempty"` 480 } 481 482 // +kubebuilder:object:root=true 483 484 // S2iBuilderList contains a list of S2iBuilder 485 type S2iBuilderList struct { 486 metav1.TypeMeta `json:",inline"` 487 metav1.ListMeta `json:"metadata,omitempty"` 488 Items []S2iBuilder `json:"items"` 489 } 490 491 type S2iAutoScale struct { 492 Kind string `json:"kind"` 493 Name string `json:"name"` 494 InitReplicas *int32 `json:"initReplicas,omitempty"` 495 Containers []string `json:"containers,omitempty"` 496 } 497 498 type DockerConfigJson struct { 499 Auths DockerConfigMap `json:"auths"` 500 } 501 502 // DockerConfig represents the config file used by the docker CLI. 503 // This config that represents the credentials that should be used 504 // when pulling images from specific image repositories. 505 type DockerConfigMap map[string]DockerConfigEntry 506 507 type DockerConfigEntry struct { 508 Username string `json:"username"` 509 Password string `json:"password"` 510 Email string `json:"email"` 511 ServerAddress string `json:"serverAddress,omitempty"` 512 } 513 514 func init() { 515 SchemeBuilder.Register(&S2iBuilder{}, &S2iBuilderList{}) 516 }