forked from kubesphere/kubesphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s2ibuildertemplate_types.go
126 lines (107 loc) · 4.3 KB
/
s2ibuildertemplate_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
ResourceKindS2iBuilderTemplate = "S2iBuilderTemplate"
ResourceSingularS2iBuilderTemplate = "s2ibuildertemplate"
ResourcePluralS2iBuilderTemplate = "s2ibuildertemplates"
)
type Parameter struct {
Description string `json:"description,omitempty"`
Key string `json:"key,omitempty"`
Type string `json:"type,omitempty"`
OptValues []string `json:"optValues,omitempty"`
Required bool `json:"required,omitempty"`
DefaultValue string `json:"defaultValue,omitempty"`
Value string `json:"value,omitempty"`
}
type CodeFramework string
const (
Ruby CodeFramework = "ruby"
Go CodeFramework = "go"
Java CodeFramework = "Java"
JavaTomcat CodeFramework = "JavaTomcat"
Nodejs CodeFramework = "Nodejs"
Python CodeFramework = "python"
)
func (p *Parameter) ToEnvonment() *EnvironmentSpec {
var v string
if p.Value == "" && p.DefaultValue != "" {
v = p.DefaultValue
} else if p.Value != "" {
v = p.Value
} else {
return nil
}
return &EnvironmentSpec{
Name: p.Key,
Value: v,
}
}
// S2iBuilderTemplateSpec defines the desired state of S2iBuilderTemplate
type S2iBuilderTemplateSpec struct {
//DefaultBaseImage is the image that will be used by default
DefaultBaseImage string `json:"defaultBaseImage,omitempty"`
//Images are the images this template will use.
ContainerInfo []ContainerInfo `json:"containerInfo,omitempty"`
//CodeFramework means which language this template is designed for and which framework is using if has framework. Like Java, NodeJS etc
CodeFramework CodeFramework `json:"codeFramework,omitempty"`
// Parameters is a set of environment variables to be passed to the image.
Parameters []Parameter `json:"environment,omitempty"`
// Version of template
Version string `json:"version,omitempty"`
// Description illustrate the purpose of this template
Description string `json:"description,omitempty"`
// IconPath is used for frontend display
IconPath string `json:"iconPath,omitempty"`
}
type ContainerInfo struct {
//BaseImage are the images this template will use.
BuilderImage string `json:"builderImage,omitempty"`
RuntimeImage string `json:"runtimeImage,omitempty"`
RuntimeArtifacts []VolumeSpec `json:"runtimeArtifacts,omitempty"`
// BuildVolumes specifies a list of volumes to mount to container running the
// build.
BuildVolumes []string `json:"buildVolumes,omitempty"`
}
// S2iBuilderTemplateStatus defines the observed state of S2iBuilderTemplate
type S2iBuilderTemplateStatus struct {
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// S2iBuilderTemplate is the Schema for the s2ibuildertemplates API
// +k8s:openapi-gen=true
// +kubebuilder:printcolumn:name="Framework",type="string",JSONPath=".spec.codeFramework"
// +kubebuilder:printcolumn:name="DefaultBaseImage",type="string",JSONPath=".spec.defaultBaseImage"
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
// +kubebuilder:resource:categories="devops",scope="Cluster",shortName="s2ibt"
type S2iBuilderTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec S2iBuilderTemplateSpec `json:"spec,omitempty"`
Status S2iBuilderTemplateStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// S2iBuilderTemplateList contains a list of S2iBuilderTemplate
type S2iBuilderTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []S2iBuilderTemplate `json:"items"`
}
func init() {
SchemeBuilder.Register(&S2iBuilderTemplate{}, &S2iBuilderTemplateList{})
}