69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
/*
|
|
Copyright 2019 the Velero contributors.
|
|
|
|
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 builder
|
|
|
|
import (
|
|
corev1api "k8s.io/api/core/v1"
|
|
)
|
|
|
|
// ContainerBuilder builds Container objects
|
|
type ContainerBuilder struct {
|
|
object *corev1api.Container
|
|
}
|
|
|
|
// ForContainer is the constructor for ContainerBuilder.
|
|
func ForContainer(name, image string) *ContainerBuilder {
|
|
return &ContainerBuilder{
|
|
object: &corev1api.Container{
|
|
Name: name,
|
|
Image: image,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Result returns the built Container.
|
|
func (b *ContainerBuilder) Result() *corev1api.Container {
|
|
return b.object
|
|
}
|
|
|
|
// Args sets the container's Args.
|
|
func (b *ContainerBuilder) Args(args ...string) *ContainerBuilder {
|
|
b.object.Args = append(b.object.Args, args...)
|
|
return b
|
|
}
|
|
|
|
// VolumeMounts sets the container's VolumeMounts.
|
|
func (b *ContainerBuilder) VolumeMounts(volumeMounts ...*corev1api.VolumeMount) *ContainerBuilder {
|
|
for _, v := range volumeMounts {
|
|
b.object.VolumeMounts = append(b.object.VolumeMounts, *v)
|
|
}
|
|
return b
|
|
}
|
|
|
|
// Resources sets the container's Resources.
|
|
func (b *ContainerBuilder) Resources(resources *corev1api.ResourceRequirements) *ContainerBuilder {
|
|
b.object.Resources = *resources
|
|
return b
|
|
}
|
|
|
|
func (b *ContainerBuilder) Env(vars ...*corev1api.EnvVar) *ContainerBuilder {
|
|
for _, v := range vars {
|
|
b.object.Env = append(b.object.Env, *v)
|
|
}
|
|
return b
|
|
}
|