Newer
Older
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
/*
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 container
import (
corev1 "k8s.io/api/core/v1"
parameters "k8s.libre.sh/parameters"
)
// +kubebuilder:object:generate=true
type Container struct {
*TemplateSpec `json:",inline"`
parameters.Parameters `json:"parameters,omitempty"`
}
// +kubebuilder:object:generate=true
type TemplateSpec struct {
Name string `json:"name,omitempty"`
Args []string `json:"args,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Ports []corev1.ContainerPort `json:"ports,omitempty"`
Probes `json:"inline,omitempty"`
}
// +kubebuilder:object:generate=true
type Probes struct {
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,10,opt,name=livenessProbe"`
}
func (r *TemplateSpec) GetContainerImage() string { return r.Image }
func (r *TemplateSpec) GetContainerName() string { return r.Name }
func (r *TemplateSpec) GetContainerImagePullPolicy() corev1.PullPolicy { return r.ImagePullPolicy }
func (r *TemplateSpec) GetContainerPorts() []corev1.ContainerPort { return r.Ports }
func (r *TemplateSpec) GetContainerLivenessProbe() *corev1.Probe { return r.LivenessProbe }
func (r *TemplateSpec) GetContainerReadinessProbe() *corev1.Probe { return r.ReadinessProbe }
func (r *TemplateSpec) GetContainerArgs() []string { return r.Args }
// func (r *TemplateSpec) GetParameters() parameters.Parameters { return nil }
func NewContainer(spec *TemplateSpec, p parameters.Parameters) *Container {
return &Container{
Parameters: p,
TemplateSpec: spec,
}
}
/*
func (spec *Container) GetEnv() []corev1.EnvVar {
envVars := []corev1.EnvVar{}
for _, c := range spec.Configs {
envVars = append(envVars, c.Params.GetEnv()...)
}
for _, s := range spec.Secrets {
envVars = append(envVars, s.Params.GetEnv()...)
}
return envVars
}
func (spec *Container) GetEnvFrom() []corev1.EnvFromSource {
envVars := []corev1.EnvFromSource{}
for _, c := range spec.Configs {
envVars = append(envVars, c.Params.GetEnvFrom()...)
}
for _, s := range spec.Secrets {
envVars = append(envVars, s.Params.GetEnvFrom()...)
}
return envVars
}
func (spec *Container) GetVolumeMount() []corev1.VolumeMount {
out := []corev1.VolumeMount{}
for _, c := range spec.Configs {
out = append(out, c.Params.GetVolumeMount()...)
}
for _, s := range spec.Secrets {
out = append(out, s.Params.GetVolumeMount()...)
}
return out
}
*/