MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / addInitContainer

Function addInitContainer

pkg/library/home/persistentHome.go:145–186  ·  view source on GitHub ↗
(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec)

Source from the content-addressed store, hash-verified

143}
144
145func addInitContainer(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) error {
146
147 if initComponentExists(dwTemplateSpec) {
148 return fmt.Errorf("component named %s already exists in the devworkspace", constants.HomeInitComponentName)
149 }
150
151 if initCommandExists(dwTemplateSpec) {
152 return fmt.Errorf("command with id %s already exists in the devworkspace", constants.HomeInitEventId)
153 }
154
155 if initEventExists(dwTemplateSpec) {
156 return fmt.Errorf("event with id %s already exists in the devworkspace", constants.HomeInitEventId)
157 }
158
159 initContainer := inferInitContainer(dwTemplateSpec)
160 if initContainer == nil {
161 return fmt.Errorf("cannot infer initcontainer for home persistence setup")
162 }
163
164 addInitContainerComponent(dwTemplateSpec, initContainer)
165
166 if dwTemplateSpec.Commands == nil {
167 dwTemplateSpec.Commands = []v1alpha2.Command{}
168 }
169
170 if dwTemplateSpec.Events == nil {
171 dwTemplateSpec.Events = &v1alpha2.Events{}
172 }
173
174 dwTemplateSpec.Commands = append(dwTemplateSpec.Commands, v1alpha2.Command{
175 Id: constants.HomeInitEventId,
176 CommandUnion: v1alpha2.CommandUnion{
177 Apply: &v1alpha2.ApplyCommand{
178 Component: constants.HomeInitComponentName,
179 },
180 },
181 })
182
183 dwTemplateSpec.Events.PreStart = append(dwTemplateSpec.Events.PreStart, constants.HomeInitEventId)
184
185 return nil
186}
187
188func initComponentExists(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) bool {
189 if dwTemplateSpec.Components == nil {

Callers 1

AddPersistentHomeVolumeFunction · 0.85

Calls 5

initComponentExistsFunction · 0.85
initCommandExistsFunction · 0.85
initEventExistsFunction · 0.85
inferInitContainerFunction · 0.85

Tested by

no test coverage detected