kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/devops/v1alpha1/s2ibuildertemplate_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  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  )
    22  
    23  const (
    24  	ResourceKindS2iBuilderTemplate     = "S2iBuilderTemplate"
    25  	ResourceSingularS2iBuilderTemplate = "s2ibuildertemplate"
    26  	ResourcePluralS2iBuilderTemplate   = "s2ibuildertemplates"
    27  )
    28  
    29  type Parameter struct {
    30  	Description  string   `json:"description,omitempty"`
    31  	Key          string   `json:"key,omitempty"`
    32  	Type         string   `json:"type,omitempty"`
    33  	OptValues    []string `json:"optValues,omitempty"`
    34  	Required     bool     `json:"required,omitempty"`
    35  	DefaultValue string   `json:"defaultValue,omitempty"`
    36  	Value        string   `json:"value,omitempty"`
    37  }
    38  
    39  type CodeFramework string
    40  
    41  const (
    42  	Ruby       CodeFramework = "ruby"
    43  	Go         CodeFramework = "go"
    44  	Java       CodeFramework = "Java"
    45  	JavaTomcat CodeFramework = "JavaTomcat"
    46  	Nodejs     CodeFramework = "Nodejs"
    47  	Python     CodeFramework = "python"
    48  )
    49  
    50  func (p *Parameter) ToEnvonment() *EnvironmentSpec {
    51  	var v string
    52  	if p.Value == "" && p.DefaultValue != "" {
    53  		v = p.DefaultValue
    54  	} else if p.Value != "" {
    55  		v = p.Value
    56  	} else {
    57  		return nil
    58  	}
    59  	return &EnvironmentSpec{
    60  		Name:  p.Key,
    61  		Value: v,
    62  	}
    63  }
    64  
    65  // S2iBuilderTemplateSpec defines the desired state of S2iBuilderTemplate
    66  type S2iBuilderTemplateSpec struct {
    67  	//DefaultBaseImage is the image that will be used by default
    68  	DefaultBaseImage string `json:"defaultBaseImage,omitempty"`
    69  	//Images are the images this template will use.
    70  	ContainerInfo []ContainerInfo `json:"containerInfo,omitempty"`
    71  	//CodeFramework means which language this template is designed for and which framework is using if has framework. Like Java, NodeJS etc
    72  	CodeFramework CodeFramework `json:"codeFramework,omitempty"`
    73  	// Parameters is a set of environment variables to be passed to the image.
    74  	Parameters []Parameter `json:"environment,omitempty"`
    75  	// Version of template
    76  	Version string `json:"version,omitempty"`
    77  	// Description illustrate the purpose of this template
    78  	Description string `json:"description,omitempty"`
    79  	// IconPath is used for frontend display
    80  	IconPath string `json:"iconPath,omitempty"`
    81  }
    82  
    83  type ContainerInfo struct {
    84  	//BaseImage are the images this template will use.
    85  	BuilderImage     string       `json:"builderImage,omitempty"`
    86  	RuntimeImage     string       `json:"runtimeImage,omitempty"`
    87  	RuntimeArtifacts []VolumeSpec `json:"runtimeArtifacts,omitempty"`
    88  	// BuildVolumes specifies a list of volumes to mount to container running the
    89  	// build.
    90  	BuildVolumes []string `json:"buildVolumes,omitempty"`
    91  }
    92  
    93  // S2iBuilderTemplateStatus defines the observed state of S2iBuilderTemplate
    94  type S2iBuilderTemplateStatus struct {
    95  }
    96  
    97  // +genclient
    98  // +genclient:nonNamespaced
    99  // +kubebuilder:object:root=true
   100  
   101  // S2iBuilderTemplate is the Schema for the s2ibuildertemplates API
   102  // +k8s:openapi-gen=true
   103  // +kubebuilder:printcolumn:name="Framework",type="string",JSONPath=".spec.codeFramework"
   104  // +kubebuilder:printcolumn:name="DefaultBaseImage",type="string",JSONPath=".spec.defaultBaseImage"
   105  // +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
   106  // +kubebuilder:resource:categories="devops",scope="Cluster",shortName="s2ibt"
   107  type S2iBuilderTemplate struct {
   108  	metav1.TypeMeta   `json:",inline"`
   109  	metav1.ObjectMeta `json:"metadata,omitempty"`
   110  
   111  	Spec   S2iBuilderTemplateSpec   `json:"spec,omitempty"`
   112  	Status S2iBuilderTemplateStatus `json:"status,omitempty"`
   113  }
   114  
   115  // +kubebuilder:object:root=true
   116  
   117  // S2iBuilderTemplateList contains a list of S2iBuilderTemplate
   118  type S2iBuilderTemplateList struct {
   119  	metav1.TypeMeta `json:",inline"`
   120  	metav1.ListMeta `json:"metadata,omitempty"`
   121  	Items           []S2iBuilderTemplate `json:"items"`
   122  }
   123  
   124  func init() {
   125  	SchemeBuilder.Register(&S2iBuilderTemplate{}, &S2iBuilderTemplateList{})
   126  }